From 98d1a38d7f07b854eee4234d883e76b1f68ca440 Mon Sep 17 00:00:00 2001 From: Dav999 Date: Wed, 25 Oct 2023 16:55:15 +0200 Subject: [PATCH] Allow UTF-8 console output on Windows (for -console) Right now, Windows assumes all our console output is code page ????. That means our UTF-8 output appears mangled. (I ran into this while testing IME text input by outputting strings to the console) For a moment I was scared we'd need to do UTF-16 conversions and call Windows-specific print functions like WriteConsoleW() in our vlog functions, but fortunately SetConsoleOutputCP(CP_UTF8) works just fine. --- desktop_version/src/Vlogging.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/desktop_version/src/Vlogging.c b/desktop_version/src/Vlogging.c index ae046c87..0b10506d 100644 --- a/desktop_version/src/Vlogging.c +++ b/desktop_version/src/Vlogging.c @@ -220,6 +220,11 @@ void vlog_open_console(void) } check_color_support(); + + if (!SetConsoleOutputCP(CP_UTF8)) + { + vlog_warn("Could not set code page for console output to UTF-8."); + } } #endif /* _WIN32 */