From 1b8ab152eab6f2c910010a6d7cd847caf9ac1ff6 Mon Sep 17 00:00:00 2001 From: GoaLitiuM Date: Mon, 27 Aug 2018 04:43:33 +0300 Subject: Enable ANSI escape sequences on Windows 10 terminals --- src/line_printer.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/line_printer.cc b/src/line_printer.cc index 6effca6..953982a 100644 --- a/src/line_printer.cc +++ b/src/line_printer.cc @@ -18,6 +18,9 @@ #include #ifdef _WIN32 #include +#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4 +#endif #else #include #include @@ -46,6 +49,15 @@ LinePrinter::LinePrinter() : have_blank_line_(true), console_locked_(false) { const char* clicolor_force = getenv("CLICOLOR_FORCE"); supports_color_ = clicolor_force && string(clicolor_force) != "0"; } +#ifdef _WIN32 + // Try enabling ANSI escape sequence support on Windows 10 terminals. + if (supports_color_) { + DWORD mode; + if (GetConsoleMode(console_, &mode)) { + SetConsoleMode(console_, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); + } + } +#endif } void LinePrinter::Print(string to_print, LineType type) { -- cgit v0.12