summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Hood <jadoxa@yahoo.com.au>2019-02-12 18:34:37 +1000
committerNico Williams <nico@cryptonector.com>2019-02-16 20:40:41 -0600
commitdef42a31caef46dbc122cb41f213784d915d318e (patch)
tree3899500185e8fd90d34e304ceb7fa1be9f38eaa4
parent605bfb35772833db0bd69927181c934d79b96d2e (diff)
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.
-rw-r--r--src/main.c11
1 files changed, 11 insertions, 0 deletions
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