[Lldb-commits] [PATCH] D51615: Set Windows console mode to enable support for ansi escape codes

Dávid Bolvanský via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 4 02:17:12 PDT 2018


xbolva00 created this revision.
xbolva00 added reviewers: JDevlieghere, teemperor.
Herald added subscribers: lldb-commits, abidh.

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

https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences.

Syntax hightlighting now works fine on Windows:
https://i.imgur.com/P0i04A7.png


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D51615

Files:
  source/Core/Debugger.cpp


Index: source/Core/Debugger.cpp
===================================================================
--- source/Core/Debugger.cpp
+++ source/Core/Debugger.cpp
@@ -50,6 +50,12 @@
 
 #if defined(_WIN32)
 #include "lldb/Host/windows/PosixApi.h" // for PATH_MAX
+#include "windows.h"
+
+#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
+#endif
+
 #endif
 
 #include "llvm/ADT/None.h"      // for None
@@ -804,6 +810,14 @@
   // Turn off use-color if we don't write to a terminal with color support.
   if (!m_output_file_sp->GetFile().GetIsTerminalWithColors())
     SetUseColor(false);
+
+#if defined(_WIN32)
+  HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+  DWORD consoleMode;
+  GetConsoleMode(hConsole, &consoleMode);
+  consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+  SetUseColor(SetConsoleMode(hConsole, consoleMode));
+#endif
 }
 
 Debugger::~Debugger() { Clear(); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51615.163766.patch
Type: text/x-patch
Size: 927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180904/e8321b2d/attachment-0001.bin>


More information about the lldb-commits mailing list