authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-18 13:36:59-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-06-18 13:36:59-07:00
log28862dd30c7152e6033abdb5daee3230ac39500a
treeb23c538fc3af1bb8a4b88416ce775ec89748fa96
parent3ef91233caf2c637797d84527a4e78f870e4b4b9
parent5439f36c976ac31f7faa27cc1536a0ecd3c4469f
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16080 from squeek502/windows-vt

windows: detect ANSI support in more terminals

2 files changed, 7 insertions(+), 0 deletions(-)

lib/std/fs/file.zig+5
...@@ -230,6 +230,11 @@ pub const File = struct {...@@ -230,6 +230,11 @@ pub const File = struct {
230 /// Test whether ANSI escape codes will be treated as such.230 /// Test whether ANSI escape codes will be treated as such.
231 pub fn supportsAnsiEscapeCodes(self: File) bool {231 pub fn supportsAnsiEscapeCodes(self: File) bool {
232 if (builtin.os.tag == .windows) {232 if (builtin.os.tag == .windows) {
233 var console_mode: os.windows.DWORD = 0;
234 if (os.windows.kernel32.GetConsoleMode(self.handle, &console_mode) != 0) {
235 if (console_mode & os.windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0) return true;
236 }
237
233 return os.isCygwinPty(self.handle);238 return os.isCygwinPty(self.handle);
234 }239 }
235 if (builtin.os.tag == .wasi) {240 if (builtin.os.tag == .wasi) {
lib/std/os/windows.zig+2
...@@ -3387,6 +3387,8 @@ pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct {...@@ -3387,6 +3387,8 @@ pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct {
3387 dwMaximumWindowSize: COORD,3387 dwMaximumWindowSize: COORD,
3388};3388};
33893389
3390pub const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4;
3391
3390pub const FOREGROUND_BLUE = 1;3392pub const FOREGROUND_BLUE = 1;
3391pub const FOREGROUND_GREEN = 2;3393pub const FOREGROUND_GREEN = 2;
3392pub const FOREGROUND_RED = 4;3394pub const FOREGROUND_RED = 4;