authorgravatar for christofer.nolander@gmail.comChristofer Nolander <christofer.nolander@gmail.com> 2023-04-14 16:07:51+02:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-06-17 23:30:17-07:00
log59a12cd293a6d84090071b0ebb4828cd6626e079
treeffd9c8ead24d8577ace22fc3a91c1832b90e39e4
parent729a051e9e38674233190aea23c0ac8c134f2d67

windows: detect ANSI support in more terminals


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

lib/std/fs/file.zig+7
...@@ -230,6 +230,13 @@ pub const File = struct {...@@ -230,6 +230,13 @@ 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 if (!os.isatty(self.handle)) return false;
234
235 var console_mode: os.windows.DWORD = 0;
236 if (os.windows.kernel32.GetConsoleMode(self.handle, &console_mode) != 0) {
237 if (console_mode & os.windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0) return true;
238 }
239
233 return os.isCygwinPty(self.handle);240 return os.isCygwinPty(self.handle);
234 }241 }
235 if (builtin.os.tag == .wasi) {242 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;