From ef1c6e9295f40a4633685eeae3c12706f8290bb0 Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Sun, 24 Aug 2014 20:59:35 +1000 Subject: win32: correct SGR sequence handling This should get colour working again on the Windows console. Fixes #1032. --- osdep/terminal-win.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'osdep') diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c index 03730ae736..def8cd6569 100644 --- a/osdep/terminal-win.c +++ b/osdep/terminal-win.c @@ -41,6 +41,9 @@ #define hSTDOUT GetStdHandle(STD_OUTPUT_HANDLE) #define hSTDERR GetStdHandle(STD_ERROR_HANDLE) + +#define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) + static short stdoutAttrs = 0; static const unsigned char ansi2win32[8] = { 0, @@ -230,11 +233,16 @@ void mp_write_console_ansi(HANDLE wstream, char *buf) case 'm': { // "SGR" for (int n = 0; n < num_params; n++) { int p = params[n]; - if (p <= 0) { - SetConsoleTextAttribute(wstream, stdoutAttrs); - } else if (p >= 0 && p < 8) { - SetConsoleTextAttribute(wstream, - ansi2win32[p] | FOREGROUND_INTENSITY); + if (p == 0) { + info.wAttributes = stdoutAttrs; + SetConsoleTextAttribute(wstream, info.wAttributes); + } else if (p == 1) { + info.wAttributes |= FOREGROUND_INTENSITY; + SetConsoleTextAttribute(wstream, info.wAttributes); + } else if (p >= 30 && p < 38) { + info.wAttributes &= ~FOREGROUND_ALL; + info.wAttributes |= ansi2win32[p - 30]; + SetConsoleTextAttribute(wstream, info.wAttributes); } } break; -- cgit v1.2.3