From aa0768b734d95a1f54df1719290d977df796068d Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Fri, 3 Jul 2026 02:49:27 +0300 Subject: fix: stop sgr mouse sequences leaking into panes refs #939 --- src/terminal_modes.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/terminal_modes.rs (limited to 'src/terminal_modes.rs') diff --git a/src/terminal_modes.rs b/src/terminal_modes.rs new file mode 100644 index 00000000..953a5812 --- /dev/null +++ b/src/terminal_modes.rs @@ -0,0 +1,32 @@ +use std::io::{self, Write}; + +const DISABLE_HOST_MOUSE_REPORTING_SEQUENCE: &[u8] = + b"\x1b[?1006l\x1b[?1016l\x1b[?1015l\x1b[?1005l\x1b[?1003l\x1b[?1002l\x1b[?1000l"; + +#[cfg(not(windows))] +pub(crate) fn clear_host_mouse_reporting(writer: &mut W) -> io::Result<()> { + writer.write_all(DISABLE_HOST_MOUSE_REPORTING_SEQUENCE)?; + writer.flush() +} + +#[cfg(windows)] +pub(crate) fn clear_host_mouse_reporting(_writer: &mut W) -> io::Result<()> { + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn clears_all_known_host_mouse_modes() { + let sequence = std::str::from_utf8(DISABLE_HOST_MOUSE_REPORTING_SEQUENCE).unwrap(); + + for mode in ["1000", "1002", "1003", "1005", "1006", "1015", "1016"] { + assert!( + sequence.contains(&format!("\x1b[?{mode}l")), + "missing mouse mode {mode}" + ); + } + } +} -- cgit v1.2.3