This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Do not use Console API if output isn't a console device
Needs ReviewPublic

Authored by kasper93 on Feb 2 2023, 10:08 AM.

Details

Reviewers
Bigcheese
Summary

This fixes -fcolor-diagnostics to properly enable color output when
not outputting to console devices. Example would be ninja.

This affects only Windows.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>

Diff Detail

Event Timeline

kasper93 created this revision.Feb 2 2023, 10:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 10:08 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
kasper93 requested review of this revision.Feb 2 2023, 10:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 10:08 AM

Ok, so I recognize that this is global state and it is not very good to flip it like that.

Frankly this Console API usage in llvm is little bit messy it only sets color on STD_OUTPUT_HANDLE, what about STD_ERROR_HANDLE? Anyhow Microsoft documentation strongly suggests to use virtual terminal sequences. And I believe they are supported on all Windows versions that are still not EOL.

So how about removing this static bool UseANSI = false; and related code? I can do that, but since I already this review, I might as well ask you for opinion.

see https://learn.microsoft.com/en-us/windows/console/setconsoletextattribute