[PATCH] D90109: [clang-tidy] Use ANSI escape codes for --use-color on Windows
David Sanders via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 24 17:18:07 PDT 2020
dsanders11 created this revision.
dsanders11 added reviewers: aaron.ballman, njames93.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, xazax.hun.
Herald added projects: clang, LLVM.
dsanders11 requested review of this revision.
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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D90109
Files:
clang-tools-extra/clang-tidy/ClangTidy.cpp
llvm/lib/Support/Windows/Process.inc
Index: llvm/lib/Support/Windows/Process.inc
===================================================================
--- llvm/lib/Support/Windows/Process.inc
+++ 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;
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ 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; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90109.300515.patch
Type: text/x-patch
Size: 1243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201025/7ffe1aeb/attachment.bin>
More information about the llvm-commits
mailing list