Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[windows] Terminal background colour #1487

Open
gvanem opened this issue Sep 10, 2022 · 2 comments
Open

[windows] Terminal background colour #1487

gvanem opened this issue Sep 10, 2022 · 2 comments

Comments

@gvanem
Copy link

gvanem commented Sep 10, 2022

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:

STL-1

Not very nice IMHO.

With my blue terminal background I'd like it to look like:
STL-2

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
@LebedevRI LebedevRI changed the title Terminal background colour [windows] Terminal background colour Sep 10, 2022
@dmah42
Copy link
Member

dmah42 commented Sep 12, 2022

could you create a pull request for this?

@gvanem
Copy link
Author

gvanem commented Sep 12, 2022

I'm not very familiar with git pull request. But my attempt: #1488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants