authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-06-04 17:39:13-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-05 18:06:29-04:00
logb32aa99b8704efd892567c8a716fb6c9f4e48a36
tree3f76d5a4327ed33592c078b433d1c18962819b82
parent9fe0c1dc50e739ae1ab5d8dc8887c7960a1ef9bd

File.getOrEnableAnsiEscapeSupport: Do not attempt to set DISABLE_NEWLINE_AUTO_RETURN

Follow up to #20172. Fixes #20188

1 files changed, 10 insertions(+), 9 deletions(-)

lib/std/fs/File.zig+10-9
......@@ -264,16 +264,17 @@ pub fn getOrEnableAnsiEscapeSupport(self: File) bool {
264264
265265 // For Windows Console, VT Sequences processing support was added in Windows 10 build 14361, but disabled by default.
266266 // https://devblogs.microsoft.com/commandline/tmux-support-arrives-for-bash-on-ubuntu-on-windows/
267 // Use Microsoft's recommended way to enable virtual terminal processing.
267 //
268 // Note: In Microsoft's example for enabling virtual terminal processing, it
269 // shows attempting to enable `DISABLE_NEWLINE_AUTO_RETURN` as well:
268270 // https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example-of-enabling-virtual-terminal-processing
269 var requested_console_modes: windows.DWORD = windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | windows.DISABLE_NEWLINE_AUTO_RETURN;
270 var console_mode = original_console_mode | requested_console_modes;
271 if (windows.kernel32.SetConsoleMode(self.handle, console_mode) != 0) return true;
272
273 // An application receiving ERROR_INVALID_PARAMETER with one of the newer console mode
274 // flags in the bit field should gracefully degrade behavior and try again.
275 requested_console_modes = windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING;
276 console_mode = original_console_mode | requested_console_modes;
271 // This is avoided because in the old Windows Console, that flag causes \n (as opposed to \r\n)
272 // to behave unexpectedly (the cursor moves down 1 row but remains on the same column).
273 // Additionally, the default console mode in Windows Terminal does not have
274 // `DISABLE_NEWLINE_AUTO_RETURN` set, so by only enabling `ENABLE_VIRTUAL_TERMINAL_PROCESSING`
275 // we end up matching the mode of Windows Terminal.
276 const requested_console_modes = windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING;
277 const console_mode = original_console_mode | requested_console_modes;
277278 if (windows.kernel32.SetConsoleMode(self.handle, console_mode) != 0) return true;
278279 }
279280