Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
15790643
Commit
15790643
authored
Aug 10, 2017
by
Gennadiy Civil
Committed by
GitHub
Aug 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1127 from zulkarnine/patch-1
Fix background color in ColoredPrintf
parents
cfab28d5
2960aa54
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
3 deletions
+31
-3
gtest.cc
googletest/src/gtest.cc
+31
-3
No files found.
googletest/src/gtest.cc
View file @
15790643
...
@@ -2895,6 +2895,33 @@ WORD GetColorAttribute(GTestColor color) {
...
@@ -2895,6 +2895,33 @@ WORD GetColorAttribute(GTestColor color) {
}
}
}
}
int
GetBitOffset
(
WORD
color_mask
)
{
if
(
color_mask
==
0
)
return
0
;
int
bitOffset
=
0
;
while
((
color_mask
&
1
)
==
0
)
{
color_mask
>>=
1
;
++
bitOffset
;
}
return
bitOffset
;
}
WORD
GetNewColor
(
GTestColor
color
,
WORD
old_color_attrs
)
{
// Let's reuse the BG
static
const
WORD
background_mask
=
BACKGROUND_BLUE
|
BACKGROUND_GREEN
|
BACKGROUND_RED
|
BACKGROUND_INTENSITY
;
static
const
WORD
foreground_mask
=
FOREGROUND_BLUE
|
FOREGROUND_GREEN
|
FOREGROUND_RED
|
FOREGROUND_INTENSITY
;
const
WORD
existing_bg
=
old_color_attrs
&
background_mask
;
WORD
new_color
=
GetColorAttribute
(
color
)
|
existing_bg
|
FOREGROUND_INTENSITY
;
static
const
int
bg_bitOffset
=
GetBitOffset
(
background_mask
);
static
const
int
fg_bitOffset
=
GetBitOffset
(
foreground_mask
);
if
(((
new_color
&
background_mask
)
>>
bg_bitOffset
)
==
((
new_color
&
foreground_mask
)
>>
fg_bitOffset
))
{
new_color
^=
FOREGROUND_INTENSITY
;
//invert intensity
}
return
new_color
;
}
#else
#else
// Returns the ANSI color code for the given color. COLOR_DEFAULT is
// Returns the ANSI color code for the given color. COLOR_DEFAULT is
...
@@ -2980,13 +3007,14 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
...
@@ -2980,13 +3007,14 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
CONSOLE_SCREEN_BUFFER_INFO
buffer_info
;
CONSOLE_SCREEN_BUFFER_INFO
buffer_info
;
GetConsoleScreenBufferInfo
(
stdout_handle
,
&
buffer_info
);
GetConsoleScreenBufferInfo
(
stdout_handle
,
&
buffer_info
);
const
WORD
old_color_attrs
=
buffer_info
.
wAttributes
;
const
WORD
old_color_attrs
=
buffer_info
.
wAttributes
;
const
WORD
new_color
=
GetNewColor
(
color
,
old_color_attrs
);
// We need to flush the stream buffers into the console before each
// We need to flush the stream buffers into the console before each
// SetConsoleTextAttribute call lest it affect the text that is already
// SetConsoleTextAttribute call lest it affect the text that is already
// printed but has not yet reached the console.
// printed but has not yet reached the console.
fflush
(
stdout
);
fflush
(
stdout
);
SetConsoleTextAttribute
(
stdout_handle
,
SetConsoleTextAttribute
(
stdout_handle
,
new_color
);
GetColorAttribute
(
color
)
|
FOREGROUND_INTENSITY
);
vprintf
(
fmt
,
args
);
vprintf
(
fmt
,
args
);
fflush
(
stdout
);
fflush
(
stdout
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment