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(); }


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(); }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to