summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2024-10-25 23:05:43 -0500
committerDanny Holman <dholman@gymli.org>2024-10-25 23:05:43 -0500
commit5b3a0a5b07a3e2e252ec61e0591fd53e416a9d3f (patch)
tree9895a0f9253f61977f84b7540dedd742b0f50803
parent42bbbe9185019df04c6aaa05ba4e815bb2a1ab67 (diff)
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 <dholman@gymli.org>
-rw-r--r--core/logging.c16
1 files changed, 15 insertions, 1 deletions
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 <windows.h>
+
+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;
}