diff options
author | James Ross-Gowan <rossymiles@gmail.com> | 2014-08-24 20:59:35 +1000 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-08-24 13:23:11 +0200 |
commit | ef1c6e9295f40a4633685eeae3c12706f8290bb0 (patch) | |
tree | a51b8a22a782f7d46bd14512807cfd1d388bb245 | |
parent | 67c6335efcf27186d60c17d34824d3320af878f3 (diff) | |
download | mpv-ef1c6e9295f40a4633685eeae3c12706f8290bb0.tar.bz2 mpv-ef1c6e9295f40a4633685eeae3c12706f8290bb0.tar.xz |
win32: correct SGR sequence handling
This should get colour working again on the Windows console.
Fixes #1032.
-rw-r--r-- | osdep/terminal-win.c | 18 |
1 files changed, 13 insertions, 5 deletions
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; |