From 257305c58d7b349aabd4c3679b013a63c16bfe43 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 21 Sep 2022 16:14:10 +0200 Subject: [PATCH] Enable ANSI escape code processing on Windows 10 and later This lets the engine and projects use the same color codes in the terminal on all platforms. --- platform/windows/os_windows.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index c1e51b8ebdf..900755a0d1c 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -3998,6 +3998,21 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) { AudioDriverManager::add_driver(&driver_xaudio2); #endif + // Enable ANSI escape code support on Windows 10 v1607 (Anniversary Update) and later. + // This lets the engine and projects use ANSI escape codes to color text just like on macOS and Linux. + // + // NOTE: The engine does not use ANSI escape codes to color error/warning messages; it uses Windows API calls instead. + // Therefore, error/warning messages are still colored on Windows versions older than 10. + HANDLE stdoutHandle; + stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD outMode = 0; + outMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + + if (!SetConsoleMode(stdoutHandle, outMode)) { + // Windows 8.1 or below, or Windows 10 prior to Anniversary Update. + print_verbose("Can't set the ENABLE_VIRTUAL_TERMINAL_PROCESSING Windows console mode."); + } + Vector loggers; loggers.push_back(memnew(WindowsTerminalLogger)); _set_logger(memnew(CompositeLogger(loggers)));