-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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] Fix for background colours besides black #1488
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -136,13 +136,16 @@ void ColorPrintf(std::ostream& out, LogColor color, const char* fmt, | |||||||||
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. | ||||||||||
Comment on lines
+145
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gvanem To clarify/reiterate, what happens if you literally apply the following change:
Suggested change
Does it not compile? |
||||||||||
SetConsoleTextAttribute(stdout_handle, | ||||||||||
GetPlatformColorCode(color) | FOREGROUND_INTENSITY); | ||||||||||
new_attr | GetPlatformColorCode(color) | FOREGROUND_INTENSITY); | ||||||||||
vprintf(fmt, args); | ||||||||||
|
||||||||||
fflush(stdout); | ||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are 7 and 8 here? Can we avoid magic numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simply mask off the foreground bits (~7) and the hi-intensity background colour bit (~8).
Should be clear. And there's no WinCon values for these AFAIK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is https://docs.microsoft.com/en-us/windows/console/console-screen-buffers#character-attributes lying and there are no macros for these magic numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I give up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment suggests there's a bug here.
BACKGROUND_INTENSITY
is 0x0080 i think.FOREGROUND_INTENSITY
is 0x0008.same with the masking of ~7 if you're trying to mask off the backgrounds.. not sure how this works (i am not a windows dev though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me rephraze: can you not just replace
8
withBACKGROUND_INTENSITY
and7
withFOREGROUND_INTENSITY
?