aboutsummaryrefslogtreecommitdiff
path: root/src/terminal_modes.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-07-03 02:49:27 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-07-03 02:49:27 +0300
commitaa0768b734d95a1f54df1719290d977df796068d (patch)
treef173bf0e14b4c951e9ad2dc02dc7e66f102b89b4 /src/terminal_modes.rs
parente1bbc252e2b40da6e0c6d7b0f8d7babb17cc8814 (diff)
fix: stop sgr mouse sequences leaking into panes
refs #939
Diffstat (limited to 'src/terminal_modes.rs')
-rw-r--r--src/terminal_modes.rs32
1 files changed, 32 insertions, 0 deletions
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<W: Write>(writer: &mut W) -> io::Result<()> {
+ writer.write_all(DISABLE_HOST_MOUSE_REPORTING_SEQUENCE)?;
+ writer.flush()
+}
+
+#[cfg(windows)]
+pub(crate) fn clear_host_mouse_reporting<W: Write>(_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}"
+ );
+ }
+ }
+}