From 09f939d3a0140478f2e547f45b4becd05247d360 Mon Sep 17 00:00:00 2001 From: "U.Nakamura" Date: Mon, 21 Dec 2020 17:29:09 +0900 Subject: [PATCH] Enable escape sequence on Windows10 console * win32/win32.c (init_stdhandle): enable escape sequence on Windows10 console to show `ruby --help` colors correctly. --- win32/win32.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/win32/win32.c b/win32/win32.c index 5934d7de28..5985875fe2 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2687,6 +2687,17 @@ init_stdhandle(void) } if (nullfd >= 0 && !keep) close(nullfd); setvbuf(stderr, NULL, _IONBF, 0); + + { + HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD m; + if (GetConsoleMode(h, &m)) { +#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x200 +#endif + SetConsoleMode(h, m | ENABLE_VIRTUAL_TERMINAL_PROCESSING); + } + } } #undef getsockopt