From ac86be2d7a837c9f3ba26ad0a3bcc4c751d81df2 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 20 Oct 2020 20:43:14 +0200 Subject: [PATCH] Fix bug in Windows where specifying a style while using a terminal that supports color does not enable the color support, so colors do not show correctly --- src/printer.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/printer.c b/src/printer.c index 783bee8..dca6805 100644 --- a/src/printer.c +++ b/src/printer.c @@ -166,16 +166,21 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style, struct colors* cs) { } art->ascii_chars[1] = '#'; + #ifdef _WIN32 + HANDLE std_handle = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD console_mode; + + // Attempt to enable the VT100-processing flag + GetConsoleMode(std_handle, &console_mode); + SetConsoleMode(std_handle, console_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); + // Get the console mode flag again, to see if it successfully enabled it + GetConsoleMode(std_handle, &console_mode); + #endif + if(style == STYLE_EMPTY) { #ifdef _WIN32 - HANDLE std_handle = GetStdHandle(STD_OUTPUT_HANDLE); - DWORD console_mode; - // Attempt to enable the VT100-processing flag - GetConsoleMode(std_handle, &console_mode); - SetConsoleMode(std_handle, console_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); - // Get the console mode flag again, to see if it successfully enabled it - GetConsoleMode(std_handle, &console_mode); - // Enable fancy mode if VT100-processing is enabled + // Use fancy style if VT100-processing is enabled, + // or legacy style in other case art->style = (console_mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) ? STYLE_FANCY : STYLE_LEGACY; #else art->style = STYLE_FANCY;