From 72a384bc1f1ed5ba9a6c361f17a642d2e10be00c Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 23 Jun 2025 19:12:50 -0600 Subject: [PATCH] AK: Set the console output code page to UTF-8 This fixes the broken emoji output from test-js. --- AK/Format.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/AK/Format.cpp b/AK/Format.cpp index 444b8e19fcf..90c5b37467a 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -1272,7 +1272,7 @@ void set_rich_debug_enabled(bool value) static int main_thread_id = GetCurrentThreadId(); -static int enable_escape_sequences() +static int initialize_console_settings() { HANDLE console_handle = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (console_handle == INVALID_HANDLE_VALUE) { @@ -1288,16 +1288,20 @@ static int enable_escape_sequences() return 0; } + // Enable Virtual Terminal Processing to allow ANSI escape codes mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; if (!SetConsoleMode(console_handle, mode)) { dbgln("Unable to set console mode"); return 0; } + // Set the output code page to UTF-8 to support Emoji and other Unicode characters + (void)SetConsoleOutputCP(CP_UTF8); + return 0; } -static int dummy = enable_escape_sequences(); +static int dummy = initialize_console_settings(); #endif