-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows: add support for native virtual terminal #15206
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3199,8 +3199,16 @@ pub fn isatty(handle: fd_t) bool { | |
if (isCygwinPty(handle)) | ||
return true; | ||
|
||
var out: windows.DWORD = undefined; | ||
return windows.kernel32.GetConsoleMode(handle, &out) != 0; | ||
// Support for ANSI escapes sequences was added to Windows 10 1511 | ||
// on 2016. | ||
// See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences. | ||
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004; | ||
|
||
var mode: windows.DWORD = undefined; | ||
if (windows.kernel32.GetConsoleMode(handle, &mode) == 0) return false; | ||
|
||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | ||
return windows.kernel32.SetConsoleMode(handle, mode) != 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not aware of any
AFAIK, Windows Terminal enables this the feature by default. The problem, that I did not consider, is how to detect Windows Terminal. Is anyone using Zig on a Windows Terminal? Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Note that the first call is to get the current state and the second it to set it. It is the same as with Unix termios. Also, about the Console API and Windows Terminal: calling |
||
} | ||
if (builtin.link_libc) { | ||
return system.isatty(handle) != 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads like either 1. a version check should be used here or 2. an assertion should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to advertise this feature, but probably it is not necessary.
A version check is not necessary, since if
SetConsoleMode
returns0
, then the feature is not supported.