summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2018-11-16 09:58:11 (GMT)
committerGitHub <noreply@github.com>2018-11-16 09:58:11 (GMT)
commit516f637504da31ddecba3cb29d3e3d7e7ba61227 (patch)
treec6c372c2caba781c36aa7daad578ce70461af501
parentd5091ee97468b248038ad2acb4501aee8b1e499b (diff)
parent1b8ab152eab6f2c910010a6d7cd847caf9ac1ff6 (diff)
downloadNinja-516f637504da31ddecba3cb29d3e3d7e7ba61227.zip
Ninja-516f637504da31ddecba3cb29d3e3d7e7ba61227.tar.gz
Ninja-516f637504da31ddecba3cb29d3e3d7e7ba61227.tar.bz2
Merge pull request #1462 from GoaLitiuM/win10color
Enable ANSI escape sequences on Windows 10 terminals
-rw-r--r--src/line_printer.cc12
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) {