zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 28862dd30c7152e6033abdb5daee3230ac39500a (tree)
parent 3ef91233caf2c637797d84527a4e78f870e4b4b9
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun, 18 Jun 2023 13:36:59 -0700

Merge pull request #16080 from squeek502/windows-vt

windows: detect ANSI support in more terminals
Diffstat:
Mlib/std/fs/file.zig | 5+++++
Mlib/std/os/windows.zig | 2++
2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig @@ -230,6 +230,11 @@ pub const File = struct { /// Test whether ANSI escape codes will be treated as such. pub fn supportsAnsiEscapeCodes(self: File) bool { if (builtin.os.tag == .windows) { + var console_mode: os.windows.DWORD = 0; + if (os.windows.kernel32.GetConsoleMode(self.handle, &console_mode) != 0) { + if (console_mode & os.windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0) return true; + } + return os.isCygwinPty(self.handle); } if (builtin.os.tag == .wasi) { diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig @@ -3387,6 +3387,8 @@ pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct { dwMaximumWindowSize: COORD, }; +pub const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4; + pub const FOREGROUND_BLUE = 1; pub const FOREGROUND_GREEN = 2; pub const FOREGROUND_RED = 4;