From 5b3a0a5b07a3e2e252ec61e0591fd53e416a9d3f Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Fri, 25 Oct 2024 23:05:43 -0500 Subject: core: ANSI colors need additional setup on Windows The ANSI color codes require additional setup when running under Win32. The logging API should reflect that. Signed-off-by: Danny Holman --- core/logging.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/logging.c b/core/logging.c index 06fd95d..3f6404b 100644 --- a/core/logging.c +++ b/core/logging.c @@ -17,7 +17,7 @@ #define LSTR_DEBUG "[DEBUG]" static int debug_enabled = 0; -static int color_enabled = 1; +static int color_enabled = 0; void log_output(int level, const char *fmt, ...) { char out[4096]; @@ -72,10 +72,24 @@ void disable_log_debug(void) { debug_enabled = 0; } +#ifdef _WIN32 + +#include + +void enable_log_color(void) { + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleMode(handle, ENABLE_VIRTUAL_TERMINAL_PROCESSING); + color_enabled = 1; +} + +#else + void enable_log_color(void) { color_enabled = 1; } +#endif + void disable_log_color(void) { color_enabled = 0; } -- cgit v1.2.3