summaryrefslogtreecommitdiffstats
path: root/googletest
diff options
context:
space:
mode:
authorZulkarnine Mahmud <zulkarnine2076@gmail.com>2017-06-22 02:06:17 (GMT)
committerGitHub <noreply@github.com>2017-06-22 02:06:17 (GMT)
commit271fb8ff5ed869d7cf38051c4cb0f54998eea6ac (patch)
tree893a6462ebd106cd124fbbed4cf1bead8448200e /googletest
parent365df11427eb40e6458adee2b5ace7191b883efa (diff)
downloadgoogletest-271fb8ff5ed869d7cf38051c4cb0f54998eea6ac.zip
googletest-271fb8ff5ed869d7cf38051c4cb0f54998eea6ac.tar.gz
googletest-271fb8ff5ed869d7cf38051c4cb0f54998eea6ac.tar.bz2
Fix a problem when bg_color == fg_color
Invert the intensity bit if the background_color == foreground_color
Diffstat (limited to 'googletest')
-rw-r--r--googletest/src/gtest.cc27
1 files changed, 24 insertions, 3 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 1ac2d6a..5f41a11 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -2979,16 +2979,37 @@ 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 background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
+ const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
+ 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;
+
+#if 1 // do we really need to waste these cpu cycles every time?
+ int bg_bitOffset = 0;
+ WORD bg_mask = background_mask;
+ while((bg_mask & 0x01) == 0x00) {
+ bg_mask >>= 1;
+ ++bg_bitOffset;
+ }
+#else
+ const int bg_bitOffset = 4;
+#endif
+ if (((new_color & background_mask) >> bg_bitOffset) == (new_color & foreground_mask)) {
+ //revert intensity
+ new_color ^= FOREGROUND_INTENSITY;
+ }
+
// 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) | existing_bg | FOREGROUND_INTENSITY);
+ SetConsoleTextAttribute(stdout_handle, new_color);
+
vprintf(fmt, args);
fflush(stdout);