[clang-tools-extra] d915d40 - Use ANSI escape codes for --use-color on Windows
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 31 07:37:36 PDT 2020
Author: David Sanders
Date: 2020-10-31T10:36:42-04:00
New Revision: d915d403d7410b17e8ac52f1f435859713a7b354
URL: https://github.com/llvm/llvm-project/commit/d915d403d7410b17e8ac52f1f435859713a7b354
DIFF: https://github.com/llvm/llvm-project/commit/d915d403d7410b17e8ac52f1f435859713a7b354.diff
LOG: Use ANSI escape codes for --use-color on Windows
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).
Added:
Modified:
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 1f94ab4977c2..b5f2a1c0fbdb 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -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; }
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp
index 5f0e3509d008..ace70a4a051e 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp
@@ -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
More information about the cfe-commits
mailing list