diff options
author | GoaLitiuM <goalitium@kapsi.fi> | 2018-08-27 04:43:33 +0300 |
---|---|---|
committer | GoaLitiuM <goalitium@kapsi.fi> | 2018-11-14 11:00:45 +0200 |
commit | 1b8ab152eab6f2c910010a6d7cd847caf9ac1ff6 (patch) | |
tree | 8a955e95d2c87e81fed92d617919f80329cf9f80 | |
parent | a65f0d42dc8820cc4d80561ddcd4b693c0adc892 (diff) | |
download | ninja-1b8ab152eab6f2c910010a6d7cd847caf9ac1ff6.tar.gz |
Enable ANSI escape sequences on Windows 10 terminals
-rw-r--r-- | src/line_printer.cc | 12 |
1 files changed, 12 insertions, 0 deletions
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 <stdlib.h> #ifdef _WIN32 #include <windows.h> +#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4 +#endif #else #include <unistd.h> #include <sys/ioctl.h> @@ -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) { |