From c794f853e943ba0f70c0e927c50ada1bf5136117 Mon Sep 17 00:00:00 2001 From: avanspector Date: Tue, 17 Sep 2024 16:57:02 +0200 Subject: [PATCH] init ansi on a standalone testing exe --- core/testing/runner.odin | 4 ++++ core/testing/runner_windows.odin | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 core/testing/runner_windows.odin diff --git a/core/testing/runner.odin b/core/testing/runner.odin index 386ba8cb5..10d5dca5c 100644 --- a/core/testing/runner.odin +++ b/core/testing/runner.odin @@ -204,6 +204,10 @@ runner :: proc(internal_tests: []Internal_Test) -> bool { } } + when ODIN_OS == .Windows { + console_ansi_init() + } + stdout := io.to_writer(os.stream_from_handle(os.stdout)) stderr := io.to_writer(os.stream_from_handle(os.stderr)) diff --git a/core/testing/runner_windows.odin b/core/testing/runner_windows.odin new file mode 100644 index 000000000..fa233ff84 --- /dev/null +++ b/core/testing/runner_windows.odin @@ -0,0 +1,22 @@ +//+private +package testing + +import win32 "core:sys/windows" + +console_ansi_init :: proc() { + stdout := win32.GetStdHandle(win32.STD_OUTPUT_HANDLE) + if stdout != win32.INVALID_HANDLE && stdout != nil { + old_console_mode: u32 + if win32.GetConsoleMode(stdout, &old_console_mode) { + win32.SetConsoleMode(stdout, old_console_mode | win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING) + } + } + + stderr := win32.GetStdHandle(win32.STD_ERROR_HANDLE) + if stderr != win32.INVALID_HANDLE && stderr != nil { + old_console_mode: u32 + if win32.GetConsoleMode(stderr, &old_console_mode) { + win32.SetConsoleMode(stderr, old_console_mode | win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING) + } + } +}