summaryrefslogtreecommitdiffstats
path: root/googletest
diff options
context:
space:
mode:
authorZulkarnine Mahmud <zulkarnine2076@gmail.com>2017-06-20 06:40:53 (GMT)
committerGitHub <noreply@github.com>2017-06-20 06:40:53 (GMT)
commit649aa295523885723ea4c9d56148ebe2b9b8a239 (patch)
tree546e1c4ec5e3a44cc6c9db251fb812c74ffc908e /googletest
parentc2d90bddc6a2a562ee7750c14351e9ca16a6a37a (diff)
downloadgoogletest-649aa295523885723ea4c9d56148ebe2b9b8a239.zip
googletest-649aa295523885723ea4c9d56148ebe2b9b8a239.tar.gz
googletest-649aa295523885723ea4c9d56148ebe2b9b8a239.tar.bz2
Fix background color in ColoredPrintf
Re-use existing background color for Widows' console window. This fixes a problem where the background color for ColoredPrintf would be BLACK even if the user's console is using a different BG color.
Diffstat (limited to 'googletest')
-rw-r--r--googletest/src/gtest.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 3a18f25..1e6afb2 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -2979,13 +2979,15 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
CONSOLE_SCREEN_BUFFER_INFO buffer_info;
GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
const WORD old_color_attrs = buffer_info.wAttributes;
-
+ // Let's reuse the BG
+ const WORD existing_bg = old_color_attrs & 0x00F0;
+
// We need to flush the stream buffers into the console before each
// SetConsoleTextAttribute call lest it affect the text that is already
// printed but has not yet reached the console.
fflush(stdout);
SetConsoleTextAttribute(stdout_handle,
- GetColorAttribute(color) | FOREGROUND_INTENSITY);
+ GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY);
vprintf(fmt, args);
fflush(stdout);