From 483530f053fc720b746cbc5f9243c7afbb3af552 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 16 Nov 2018 10:40:04 +0100 Subject: [PATCH] enable rendering of ANSI term colors on Windows console --- src/StreamError.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/StreamError.cc b/src/StreamError.cc index 27cd9ce..cc8d833 100644 --- a/src/StreamError.cc +++ b/src/StreamError.cc @@ -18,6 +18,9 @@ ***************************************************************/ #include "StreamError.h" +#ifdef _WIN32 +#include +#endif #include #include #include @@ -39,6 +42,18 @@ FILE *StreamDebugFile = NULL; #ifdef _WIN32 #define localtime_r(timet,tm) localtime_s(tm,timet) + +/* Enable ANSI colors in Windows console */ +static int win_console_init() { + DWORD dwMode = 0; + HANDLE hCons = GetStdHandle(STD_ERROR_HANDLE); + GetConsoleMode(hCons, &dwMode); + dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + SetConsoleMode(hCons, dwMode); + return 0; +} +static int s = win_console_init(); + #endif /* You can globally change the printTimestamp function @@ -115,4 +130,3 @@ print(const char* fmt, ...) va_end(args); return 1; } -