[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 02:03:04 PDT 2018


xbolva00 created this revision.
xbolva00 added reviewers: zturner, chandlerc.
Herald added a subscriber: llvm-commits.

Windows console now supports supports ANSI escape codes, but we need to enable it using SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING flag.

Fixes https://bugs.llvm.org/show_bug.cgi?id=38817

Tested on Windows 10, screenshot:
https://i.imgur.com/bqYq0Uy.png


Repository:
  rL LLVM

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,7 +328,15 @@
 
 static bool UseANSI = false;
 void Process::UseANSIEscapeCodes(bool enable) {
-  UseANSI = enable;
+  if (enable) {
+    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+    DWORD consoleMode;
+    GetConsoleMode(hConsole, &consoleMode);
+    consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+    UseANSI = SetConsoleMode(hConsole, consoleMode);
+  } else {
+    UseANSI = false;
+  }
 }
 
 namespace {


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


More information about the llvm-commits mailing list