benchmark
benchmark copied to clipboard
[windows] Terminal background colour
Hello folks, my first issue.
The function ColorPrintf()
ass-u-mes that all users of this library have terminals with a black background colour.
I.e. using it in Microsoft's STL library and the benchmark-std_copy.exe
program, the output like like this:
Not very nice IMHO.
With my blue terminal background I'd like it to look like:
which I fixed with:
--- a/src/colorprint.cc 2022-09-10 14:58:12
+++ b/src/colorprint.cc 2022-09-10 14:54:32
@@ -136,13 +136,16 @@
CONSOLE_SCREEN_BUFFER_INFO buffer_info;
GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
const WORD old_color_attrs = buffer_info.wAttributes;
+ WORD new_attr;
// 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);
+ new_attr = (buffer_info.wAttributes & ~7);
+ new_attr &= ~8; // Since 'wAttributes' could have been hi-intensity at startup.
SetConsoleTextAttribute(stdout_handle,
- GetPlatformColorCode(color) | FOREGROUND_INTENSITY);
+ new_attr | GetPlatformColorCode(color) | FOREGROUND_INTENSITY);
vprintf(fmt, args);
fflush(stdout);
PS. I use JPsoft's 4NT as the shell.
System
- Win-10
- Compiler and version: MSVC ver. 19.34.31721 for x64
could you create a pull request for this?
I'm not very familiar with git pull request. But my attempt: https://github.com/google/benchmark/pull/1488