getOrEnableAnsiEscapeSupport
Returns whether or not ANSI escape codes will be treated as such, and attempts to enable support for ANSI escape codes if necessary (on Windows).
Returns true if ANSI escape codes are supported or support was
successfully enabled. Returns false if ANSI escape codes are not
supported or support was unable to be enabled.
See also supportsAnsiEscapeCodes.
Function parameters
Parameters
Type definitions in this namespace
Types
- Permissions
- Cross-platform representation of permissions on a file.
- Reader
- Memoizes key information about a file handle such as:
Functions in this namespace
Functions
- close
- Upon success, the stream is in an uninitialized state.
- sync
- Blocks until all pending file contents and metadata modifications
- isTty
- Test whether the file refers to a terminal.
- getOrEnableAnsiEscapeSupport
- Returns whether or not ANSI escape codes will be treated as such,
- supportsAnsiEscapeCodes
- Test whether ANSI escape codes will be treated as such without
- setEndPos
- Shrinks or expands the file.
- seekBy
- Repositions read/write file offset relative to the current offset.
- seekFromEnd
- Repositions read/write file offset relative to the end.
- seekTo
- Repositions read/write file offset relative to the beginning.
- getPos
- TODO: integrate with async I/O
- getEndPos
- TODO: integrate with async I/O
- mode
- TODO: integrate with async I/O
- stat
- Returns `Stat` containing basic information about the `File`.
- chmod
- Changes the mode of the file.
- chown
- Changes the owner and group of the file.
- setPermissions
- Sets permissions according to the provided `Permissions` struct.
- updateTimes
- The underlying file system may have a different granularity than nanoseconds,
- readToEndAlloc
- Deprecated in favor of `Reader`.
- readToEndAllocOptions
- Deprecated in favor of `Reader`.
- readAll
- Deprecated in favor of `Reader`.
- pread
- On Windows, this function currently does alter the file pointer.
- preadAll
- Deprecated in favor of `Reader`.
- readv
- See https://github.com/ziglang/zig/issues/7699
- readvAll
- Deprecated in favor of `Reader`.
- preadv
- See https://github.com/ziglang/zig/issues/7699
- preadvAll
- Deprecated in favor of `Reader`.
- writeAll
- Deprecated in favor of `Writer`.
- pwrite
- On Windows, this function currently does alter the file pointer.
- pwriteAll
- Deprecated in favor of `Writer`.
- writev
- See https://github.com/ziglang/zig/issues/7699
- writevAll
- Deprecated in favor of `Writer`.
- pwritev
- See https://github.com/ziglang/zig/issues/7699
- pwritevAll
- Deprecated in favor of `Writer`.
- copyRange
- Deprecated in favor of `Writer`.
- copyRangeAll
- Deprecated in favor of `Writer`.
- deprecatedReader
- Deprecated in favor of `Reader`.
- deprecatedWriter
- Deprecated in favor of `Writer`.
- reader
- Defaults to positional reading; falls back to streaming.
- readerStreaming
- Positional is more threadsafe, since the global seek position is not
- writer
- Defaults to positional reading; falls back to streaming.
- writerStreaming
- Positional is more threadsafe, since the global seek position is not
- lock
- Blocks when an incompatible lock is held by another process.
- unlock
- Assumes the file is locked.
- tryLock
- Attempts to obtain a lock, returning `true` if the lock is
- downgradeLock
- Assumes the file is already locked in exclusive mode.
Error sets in this namespace
Error Sets
= posix.fd_t
Values
Source
Implementation
pub fn getOrEnableAnsiEscapeSupport(self: File) bool {
if (builtin.os.tag == .windows) {
var original_console_mode: windows.DWORD = 0;
// For Windows Terminal, VT Sequences processing is enabled by default.
if (windows.kernel32.GetConsoleMode(self.handle, &original_console_mode) != 0) {
if (original_console_mode & windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0) return true;
// For Windows Console, VT Sequences processing support was added in Windows 10 build 14361, but disabled by default.
// https://devblogs.microsoft.com/commandline/tmux-support-arrives-for-bash-on-ubuntu-on-windows/
//
// Note: In Microsoft's example for enabling virtual terminal processing, it
// shows attempting to enable `DISABLE_NEWLINE_AUTO_RETURN` as well:
// https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example-of-enabling-virtual-terminal-processing
// This is avoided because in the old Windows Console, that flag causes \n (as opposed to \r\n)
// to behave unexpectedly (the cursor moves down 1 row but remains on the same column).
// Additionally, the default console mode in Windows Terminal does not have
// `DISABLE_NEWLINE_AUTO_RETURN` set, so by only enabling `ENABLE_VIRTUAL_TERMINAL_PROCESSING`
// we end up matching the mode of Windows Terminal.
const requested_console_modes = windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING;
const console_mode = original_console_mode | requested_console_modes;
if (windows.kernel32.SetConsoleMode(self.handle, console_mode) != 0) return true;
}
return self.isCygwinPty();
}
return self.supportsAnsiEscapeCodes();
}