From def42a31caef46dbc122cb41f213784d915d318e Mon Sep 17 00:00:00 2001 From: Jason Hood Date: Tue, 12 Feb 2019 18:34:37 +1000 Subject: [PATCH] Possibly enable color output on Windows (#1494) Windows 10 supports color output, but it must be explicitly enabled; ANSICON provides support for other versions. Enable color if either of those are available. Resolves #1494. --- src/main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.c b/src/main.c index ebfddf9a..233d130b 100644 --- a/src/main.c +++ b/src/main.c @@ -538,6 +538,17 @@ int main(int argc, char* argv[]) { /* Disable color by default on Windows builds as Windows terminals tend not to display it correctly */ dumpopts |= JV_PRINT_COLOR; +#else + // Unless ANSICON is installed, or it's Windows 10 + if (getenv("ANSICON") != NULL) + dumpopts |= JV_PRINT_COLOR; + else { + DWORD mode; + HANDLE con = GetStdHandle(STD_OUTPUT_HANDLE); + if (GetConsoleMode(con, &mode) && + SetConsoleMode(con, mode | 4/*ENABLE_VIRTUAL_TERMINAL_PROCESSING*/)) + dumpopts |= JV_PRINT_COLOR; + } #endif } #endif