Function getOrEnableAnsiEscapeSupport [src]
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.
Prototype
pub fn getOrEnableAnsiEscapeSupport(self: File) bool
Parameters
self: File
Source
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();
}