diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -110,6 +110,11 @@ DiagOpts->ShowColors = Context.getOptions().UseColor.getValueOr( llvm::sys::Process::StandardOutHasColors()); DiagPrinter->BeginSourceFile(LangOpts); +#if defined(_WIN32) + if (DiagOpts->ShowColors && !llvm::sys::Process::StandardOutIsDisplayed()) { + llvm::sys::Process::UseANSIEscapeCodes(true); + } +#endif } SourceManager &getSourceManager() { return SourceMgr; } diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc --- a/llvm/lib/Support/Windows/Process.inc +++ b/llvm/lib/Support/Windows/Process.inc @@ -327,9 +327,10 @@ if (enable) { HANDLE Console = GetStdHandle(STD_OUTPUT_HANDLE); DWORD Mode; - GetConsoleMode(Console, &Mode); - Mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; - SetConsoleMode(Console, Mode); + if (GetConsoleMode(Console, &Mode) != 0) { + Mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + SetConsoleMode(Console, Mode); + } } #endif UseANSI = enable;