[PATCH] D143202: [llvm] Do not use Console API if output isn't a console device
Kacper Michajłow via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 2 10:08:50 PST 2023
kasper93 created this revision.
kasper93 added a reviewer: Bigcheese.
Herald added a subscriber: hiraditya.
Herald added a project: All.
kasper93 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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 at gmail.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D143202
Files:
llvm/lib/Support/raw_ostream.cpp
Index: llvm/lib/Support/raw_ostream.cpp
===================================================================
--- llvm/lib/Support/raw_ostream.cpp
+++ llvm/lib/Support/raw_ostream.cpp
@@ -636,6 +636,11 @@
// Check if this is a console device. This is not equivalent to isatty.
IsWindowsConsole =
::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
+
+ // If this isn't a Windows console device, don't try to use API to set color.
+ // Switch to ANSI escape codes instead.
+ if (!IsWindowsConsole)
+ llvm::sys::Process::UseANSIEscapeCodes(true);
#endif
// Get the starting position.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143202.494350.patch
Type: text/x-patch
Size: 616 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230202/0a930670/attachment.bin>
More information about the llvm-commits
mailing list