[PATCH] D51611: Set console mode when -fansi-escape-codes is enabled

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 03:47:23 PDT 2018


xbolva00 updated this revision to Diff 163778.
xbolva00 added a comment.

- Addressed comments from PR38817


https://reviews.llvm.org/D51611

Files:
  lib/Support/Windows/Process.inc
  lib/Support/Windows/WindowsSupport.h


Index: lib/Support/Windows/WindowsSupport.h
===================================================================
--- lib/Support/Windows/WindowsSupport.h
+++ lib/Support/Windows/WindowsSupport.h
@@ -34,6 +34,10 @@
 #define NOMINMAX
 #endif
 
+#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
+#endif
+
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
Index: lib/Support/Windows/Process.inc
===================================================================
--- lib/Support/Windows/Process.inc
+++ lib/Support/Windows/Process.inc
@@ -328,6 +328,13 @@
 
 static bool UseANSI = false;
 void Process::UseANSIEscapeCodes(bool enable) {
+  if (enable) {
+    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+    DWORD consoleMode;
+    GetConsoleMode(hConsole, &consoleMode);
+    consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+    SetConsoleMode(hConsole, consoleMode);
+  }
   UseANSI = enable;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51611.163778.patch
Type: text/x-patch
Size: 1004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180904/3b428889/attachment.bin>


More information about the llvm-commits mailing list