authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-14 20:31:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-14 20:31:47-04:00
logba405ed59b18871b41aa2fd5288849f725d39531
tree89f4ebbc5bbf1f79a81df895ee8c1d985fa364bf
parentfd7654e4e80f59e18bfaf7ba4872fefcd74feeb5

try harder to emit console colors


1 files changed, 21 insertions(+), 0 deletions(-)

src/os.cpp+21
...@@ -948,6 +948,12 @@ static void set_color_posix(TermColor color) {...@@ -948,6 +948,12 @@ static void set_color_posix(TermColor color) {
948 }948 }
949}949}
950950
951
952#if defined(ZIG_OS_WINDOWS)
953bool got_orig_console_attrs = false;
954WORD original_console_attributes = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE;
955#endif
956
951void os_stderr_set_color(TermColor color) {957void os_stderr_set_color(TermColor color) {
952#if defined(ZIG_OS_WINDOWS)958#if defined(ZIG_OS_WINDOWS)
953 if (is_stderr_cyg_pty()) {959 if (is_stderr_cyg_pty()) {
...@@ -965,22 +971,37 @@ void os_stderr_set_color(TermColor color) {...@@ -965,22 +971,37 @@ void os_stderr_set_color(TermColor color) {
965 mode_flags |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;971 mode_flags |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
966 SetConsoleMode(stderr_handle, mode_flags);972 SetConsoleMode(stderr_handle, mode_flags);
967 }973 }
974
975 if (!got_orig_console_attrs) {
976 got_orig_console_attrs = true;
977 CONSOLE_SCREEN_BUFFER_INFO info;
978 if (GetConsoleScreenBufferInfo(stderr_handle, &info)) {
979 original_console_attributes = info.wAttributes;
980 }
981 }
982
968 DWORD chars_written;983 DWORD chars_written;
969 switch (color) {984 switch (color) {
970 case TermColorRed:985 case TermColorRed:
986 SetConsoleTextAttribute(stderr_handle, FOREGROUND_RED|FOREGROUND_INTENSITY);
971 WriteConsole(stderr_handle, VT_RED, strlen(VT_RED), &chars_written, NULL);987 WriteConsole(stderr_handle, VT_RED, strlen(VT_RED), &chars_written, NULL);
972 break;988 break;
973 case TermColorGreen:989 case TermColorGreen:
990 SetConsoleTextAttribute(stderr_handle, FOREGROUND_GREEN|FOREGROUND_INTENSITY);
974 WriteConsole(stderr_handle, VT_GREEN, strlen(VT_GREEN), &chars_written, NULL);991 WriteConsole(stderr_handle, VT_GREEN, strlen(VT_GREEN), &chars_written, NULL);
975 break;992 break;
976 case TermColorCyan:993 case TermColorCyan:
994 SetConsoleTextAttribute(stderr_handle, FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
977 WriteConsole(stderr_handle, VT_CYAN, strlen(VT_CYAN), &chars_written, NULL);995 WriteConsole(stderr_handle, VT_CYAN, strlen(VT_CYAN), &chars_written, NULL);
978 break;996 break;
979 case TermColorWhite:997 case TermColorWhite:
998 SetConsoleTextAttribute(stderr_handle,
999 FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
980 WriteConsole(stderr_handle, VT_WHITE, strlen(VT_WHITE), &chars_written, NULL);1000 WriteConsole(stderr_handle, VT_WHITE, strlen(VT_WHITE), &chars_written, NULL);
981 break;1001 break;
982 case TermColorReset:1002 case TermColorReset:
983 {1003 {
1004 SetConsoleTextAttribute(stderr_handle, original_console_attributes);
984 WriteConsole(stderr_handle, VT_RESET, strlen(VT_RESET), &chars_written, NULL);1005 WriteConsole(stderr_handle, VT_RESET, strlen(VT_RESET), &chars_written, NULL);
9851006
986 DWORD mode_flags = 0;1007 DWORD mode_flags = 0;