Add File.getOrEnableAnsiEscapeSupport
and use it
#20172
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Windows, the console mode flag
ENABLE_VIRTUAL_TERMINAL_PROCESSING
determines whether or not ANSI escape codes are parsed/acted on. On the newer Windows Terminal, this flag is set by default, but on the older Windows Console, it is not set by default, but can be enabled (since Windows 10 RS1 from June 2016).The new
File.getOrEnableAnsiEscapeSupport
function will get the current status of ANSI escape code support, but will also attempt to enableENABLE_VIRTUAL_TERMINAL_PROCESSING
on Windows if necessary which will provide better/more consistent results for things likestd.Progress
andstd.io.tty
.This type of change was not done previously due to a mistaken assumption (on my part) that the console mode would persist after the run of a program. However, it turns out that the console mode is always reset to the default for each program run in a console session.
EDIT: A caveat here is that child processes can affect the console mode of parent processes, see #16526 (comment) for an example of how this can cause problems. So this may not actually be fully safe to do, as spawning Zig as a child process can end up messing with the console mode of other processes unexpectedly.
This is a revivial of #18692 / #15206 (the first commit is cherry-picked from #18692).
Notes:
ENABLE_VIRTUAL_TERMINAL_PROCESSING
ENABLE_VIRTUAL_TERMINAL_PROCESSING
for one will set it for bothstd.Progress
/std.io.tty
, but that is not done in this PR (see rework std.Progress #20059 (comment)). Doing so would mean that color support/progress support would require Windows 10 >= RS1 (from June 2016)