Skip to content

Commit

Permalink
Merge pull request #44118 from Calinou/windows-enable-ansi-escape-codes
Browse files Browse the repository at this point in the history
Enable ANSI escape code processing on Windows 10 and later
  • Loading branch information
YuriSizov authored Sep 8, 2022
2 parents 141fdac + debfc7c commit d2a6a18
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,21 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) {

DisplayServerWindows::register_windows_driver();

// 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. `print_rich()` will not work as expected.");
}

Vector<Logger *> loggers;
loggers.push_back(memnew(WindowsTerminalLogger));
_set_logger(memnew(CompositeLogger(loggers)));
Expand Down

0 comments on commit d2a6a18

Please sign in to comment.