Skip to content

Commit

Permalink
Use ANSI escape codes for --use-color on Windows
Browse files Browse the repository at this point in the history
On Windows the --use-color option cannot be used for its originally
intended purpose of forcing color when piping stdout, since Windows
does not use ANSI escape codes by default. This change turns on ANSI
escape codes on Windows when forcing color to a non-displayed stdout
(e.g. piped).
  • Loading branch information
dsanders11 authored and AaronBallman committed Oct 31, 2020
1 parent 30ad742 commit d915d40
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang-tools-extra/clang-tidy/ClangTidy.cpp
Expand Up @@ -110,6 +110,9 @@ class ErrorReporter {
DiagOpts->ShowColors = Context.getOptions().UseColor.getValueOr(
llvm::sys::Process::StandardOutHasColors());
DiagPrinter->BeginSourceFile(LangOpts);
if (DiagOpts->ShowColors && !llvm::sys::Process::StandardOutIsDisplayed()) {
llvm::sys::Process::UseANSIEscapeCodes(true);
}
}

SourceManager &getSourceManager() { return SourceMgr; }
Expand Down
Expand Up @@ -5,7 +5,6 @@
// RUN: clang-tidy -config='UseColor: false' -dump-config | FileCheck -check-prefix=CHECK-CONFIG-NO-COLOR %s
// RUN: clang-tidy -help | FileCheck -check-prefix=CHECK-OPT-PRESENT %s

// REQUIRES: ansi-escape-sequences
// RUN: clang-tidy -checks='-*, modernize-use-override' -extra-arg=-std=c++11 -use-color=false %s | FileCheck -check-prefix=CHECK-NO-COLOR %s
// RUN: clang-tidy -checks='-*, modernize-use-override' -extra-arg=-std=c++11 %s | FileCheck -check-prefix=CHECK-NO-COLOR %s
// RUN: clang-tidy -checks='-*, modernize-use-override' -extra-arg=-std=c++11 -use-color %s | FileCheck -check-prefix=CHECK-COLOR %s
Expand Down

0 comments on commit d915d40

Please sign in to comment.