From a79c54be66fb9704c8bbd55ae3b23c74be8d47f4 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 12 Jan 2026 08:25:39 +0100 Subject: [PATCH] shell_modes: clear the FLUSHO flag On macOS, pressing ctrl-o (VDISCARD) before starting fish will discard all terminal output, from shell or its child processes. This breaks querying and seems like something we don't want to support, so maybe disable it? Not sure if term_fix_external_modes needs it too, add it I guess. Fixes #12304 --- src/reader/reader.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/reader/reader.rs b/src/reader/reader.rs index b2997efcb..91b4e7683 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -20,9 +20,9 @@ use crate::portable_atomic::AtomicU64; use fish_common::{UTF8_BOM_WCHAR, help_section}; use libc::{ - _POSIX_VDISABLE, ECHO, EINTR, EIO, EISDIR, ENOTTY, EPERM, ESRCH, ICANON, ICRNL, IEXTEN, INLCR, - IXOFF, IXON, O_NONBLOCK, O_RDONLY, ONLCR, OPOST, SIGINT, SIGTTIN, STDERR_FILENO, STDIN_FILENO, - STDOUT_FILENO, TCSANOW, VMIN, VQUIT, VSUSP, VTIME, c_char, + _POSIX_VDISABLE, ECHO, EINTR, EIO, EISDIR, ENOTTY, EPERM, ESRCH, FLUSHO, ICANON, ICRNL, IEXTEN, + INLCR, IXOFF, IXON, O_NONBLOCK, O_RDONLY, ONLCR, OPOST, SIGINT, SIGTTIN, STDERR_FILENO, + STDIN_FILENO, STDOUT_FILENO, TCSANOW, VMIN, VQUIT, VSUSP, VTIME, c_char, }; use nix::fcntl::OFlag; use nix::sys::stat::Mode; @@ -1018,7 +1018,7 @@ pub fn reader_init(will_restore_foreground_pgroup: bool) { { let mut shell_modes = shell_modes(); *shell_modes = *tty_modes_for_external_cmds; - term_fix_modes(&mut shell_modes); + term_fix_shell_modes(&mut shell_modes); } drop(tty_modes_for_external_cmds); @@ -4683,7 +4683,7 @@ fn term_fix_oflag(modes: &mut libc::termios) { } /// Restore terminal settings we care about, to prevent a broken shell. -fn term_fix_modes(modes: &mut libc::termios) { +fn term_fix_shell_modes(modes: &mut libc::termios) { modes.c_iflag &= { // disable mapping CR (\cM) to NL (\cJ) !ICRNL @@ -4691,12 +4691,10 @@ fn term_fix_modes(modes: &mut libc::termios) { & !INLCR }; modes.c_lflag &= { - // turn off echo mode !ECHO - // turn off canonical mode & !ICANON - // turn off handling of discard and lnext characters - & !IEXTEN + & !IEXTEN // turn off handling of discard and lnext characters + & !FLUSHO }; term_fix_oflag(modes); @@ -4717,9 +4715,8 @@ fn term_fix_modes(modes: &mut libc::termios) { fn term_fix_external_modes(modes: &mut libc::termios) { term_fix_oflag(modes); // These cause other ridiculous behaviors like input not being shown. - modes.c_lflag |= ECHO | ICANON | IEXTEN; - modes.c_iflag |= ICRNL; - modes.c_iflag &= !INLCR; + modes.c_lflag = (modes.c_lflag | ECHO | ICANON | IEXTEN) & !FLUSHO; + modes.c_iflag = (modes.c_iflag | ICRNL) & !INLCR; } /// Give up control of terminal.