diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2017-03-16 13:55:09 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2017-03-16 19:51:42 +0000 |
commit | ae4b02fb21772effd6836599a7e1792b26ff95e0 (patch) | |
tree | c86b39ed076dec6e97679f2c85156a39c3f0555e | |
parent | 3d97f4997039beb5cbc5e0b668c1cb2ffa69a76f (diff) |
Bazel client, Windows: support colorful output
See https://github.com/bazelbuild/bazel/issues/2107
--
PiperOrigin-RevId: 150314355
MOS_MIGRATED_REVID=150314355
-rw-r--r-- | src/main/cpp/blaze_util_windows.cc | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index 15d39a5364..0aa0954573 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -1122,6 +1122,19 @@ void SetupStdStreams() { // with bizarre things like stdout going to the lock file, etc. _open("NUL", (i == 0) ? _O_RDONLY : _O_WRONLY); } + DWORD mode = 0; + if (i > 0 && handle != INVALID_HANDLE_VALUE && handle != NULL && + ::GetConsoleMode(handle, &mode)) { + DWORD newmode = mode | ENABLE_PROCESSED_OUTPUT | + ENABLE_WRAP_AT_EOL_OUTPUT | + ENABLE_VIRTUAL_TERMINAL_PROCESSING; + if (mode != newmode) { + // We don't care about the success of this. Worst that can happen if + // this method fails is that the console won't understand control + // characters like color change or carriage return. + ::SetConsoleMode(handle, newmode); + } + } } #else // not COMPILER_MSVC // Set non-buffered output mode for stderr/stdout. The server already @@ -1313,9 +1326,18 @@ bool IsEmacsTerminal() { // environment variables). bool IsStandardTerminal() { #ifdef COMPILER_MSVC - // TODO(bazel-team): Implement this method properly. We may return true if - // stdout and stderr are not redirected. - return false; + for (DWORD i : {STD_OUTPUT_HANDLE, STD_ERROR_HANDLE}) { + DWORD mode = 0; + HANDLE handle = ::GetStdHandle(i); + // handle may be invalid when std{out,err} is redirected + if (handle == INVALID_HANDLE_VALUE || !::GetConsoleMode(handle, &mode) || + !(mode & ENABLE_PROCESSED_OUTPUT) || + !(mode & ENABLE_WRAP_AT_EOL_OUTPUT) || + !(mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)) { + return false; + } + } + return true; #else // not COMPILER_MSVC string term = GetEnv("TERM"); if (term.empty() || term == "dumb" || term == "emacs" || |