This is an archive of the discontinued LLVM Phabricator instance.

[raw_ostream] When printing color on Windows, use the existing foreground / background color.
ClosedPublic

Authored by zturner on Feb 27 2015, 6:40 PM.

Details

Summary

According to MSDN [https://msdn.microsoft.com/en-us/library/windows/desktop/ms682088(v=vs.85).aspx#_win32_character_attributes], when setting the console attribute, whichever property you don't set has a default value chosen.

Quote: "If no background constant is specified, the background is black, and if no foreground constant is specified, the text is black"

This is annoying if you have changed the default background color of your console and then use raw_ostrema to change the foreground color (or vice versa), because setting only the foreground attribute will also choose a default value for the background which will be different than your current console's setting.

This patch gets the current value of both attributes, and when you set one attribute, it sets the opposite attribute to its existing value before committing the color update.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner updated this revision to Diff 20923.Feb 27 2015, 6:40 PM
zturner retitled this revision from to [raw_ostream] When printing color on Windows, use the existing foreground / background color..
zturner updated this object.
zturner edited the test plan for this revision. (Show Details)
zturner added reviewers: bkramer, aaron.ballman.
zturner added a subscriber: Unknown Object (MLST).
zturner updated this revision to Diff 20924.Feb 27 2015, 6:44 PM

Fixed a variable shadowing and removed unnecessary locals.

aaron.ballman edited edge metadata.Feb 28 2015, 9:31 AM

LGTM, thank you for doing this!

~Aaron

This revision was automatically updated to reflect the committed changes.