Skip to content

Commit 85e1aa6

Browse files
committed
[llvm] Do not use Console API if the output isn't a console device
This fixes the `-fcolor-diagnostics` to properly enable color output when not outputting to console devices, such as when using Ninja. This affects only Windows. Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
1 parent bf67610 commit 85e1aa6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

llvm/lib/Support/raw_ostream.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
645645
// Check if this is a console device. This is not equivalent to isatty.
646646
IsWindowsConsole =
647647
::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
648+
649+
// If this isn't a console device, don't try to use the API to set the color.
650+
// Switch to ANSI escape codes instead.
651+
if (!IsWindowsConsole)
652+
llvm::sys::Process::UseANSIEscapeCodes(true);
648653
#endif
649654

650655
// Get the starting position.

0 commit comments

Comments
 (0)