A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
input: ignore zero-distance wheel events before terminal forwarding
RoversXd35e146d3723
diff --git a/term/src/terminalstate/mouse.rs b/term/src/terminalstate/mouse.rsindex 6dafd470..98708088 100644--- a/term/src/terminalstate/mouse.rs+++ b/term/src/terminalstate/mouse.rs@@ -74,6 +74,18 @@ impl TerminalState {}fn mouse_wheel(&mut self, event: MouseEvent) -> anyhow::Result<()> {+ // A fractional GUI scroll is not a whole terminal wheel event.+ // Also guard other callers (including mux input) against producing+ // a mouse report or alternate-screen cursor keys for zero travel.+ if matches!(+ event.button,+ MouseButton::WheelUp(0)+ | MouseButton::WheelDown(0)+ | MouseButton::WheelLeft(0)+ | MouseButton::WheelRight(0)+ ) {+ return Ok(());+ }let (button, _button) = self.mouse_report_button_number(&event);if self.mouse_encoding == MouseEncoding::SGRdiff --git a/term/src/test/mod.rs b/term/src/test/mod.rsindex adb840f8..c39c9fbf 100644--- a/term/src/test/mod.rs+++ b/term/src/test/mod.rs@@ -7,6 +7,7 @@ use bitflags::bitflags;mod c1;mod csi;mod graphics;+mod mouse;#[cfg(feature = "use_serde")]mod snapshot;// mod selection; FIXME: port to render layerdiff --git a/term/src/test/mouse.rs b/term/src/test/mouse.rsnew file mode 100644index 00000000..c48f269a--- /dev/null+++ b/term/src/test/mouse.rs@@ -0,0 +1,119 @@+use crate::{+ color::ColorPalette, KeyModifiers, MouseButton, MouseEvent, MouseEventKind, Terminal,+ TerminalConfiguration, TerminalSize,+};+use std::io::Write;+use std::sync::{mpsc, Arc};+use std::time::{Duration, Instant};++#[derive(Debug)]+struct Config;++impl TerminalConfiguration for Config {+ fn scrollback_size(&self) -> usize {+ 24+ }++ fn color_palette(&self) -> ColorPalette {+ ColorPalette::default()+ }+}++struct Output(mpsc::Sender<Vec<u8>>);++impl Write for Output {+ fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {+ self.0.send(bytes.to_vec()).unwrap();+ Ok(bytes.len())+ }++ fn flush(&mut self) -> std::io::Result<()> {+ Ok(())+ }+}++fn terminal() -> (Terminal, mpsc::Receiver<Vec<u8>>) {+ let (tx, rx) = mpsc::channel();+ let term = Terminal::new(+ TerminalSize {+ rows: 24,+ cols: 80,+ pixel_width: 800,+ pixel_height: 480,+ dpi: 96,+ },+ Arc::new(Config),+ "ThinkTerm",+ "test",+ Box::new(Output(tx)),+ );+ (term, rx)+}++fn wheel(term: &mut Terminal, button: MouseButton) {+ term.mouse_event(MouseEvent {+ kind: MouseEventKind::Press,+ button,+ x: 0,+ y: 0,+ x_pixel_offset: 0,+ y_pixel_offset: 0,+ modifiers: KeyModifiers::NONE,+ })+ .unwrap();+}++fn drain(term: &mut Terminal, output: &mpsc::Receiver<Vec<u8>>) -> Vec<u8> {+ // An ordered DSR reply proves that all prior output has crossed the+ // threaded writer, including when there should be no wheel output.+ term.advance_bytes(b"\x1b[5n");+ let deadline = Instant::now() + Duration::from_secs(5);+ let mut bytes = Vec::new();+ while !bytes.ends_with(b"\x1b[0n") {+ bytes.extend(+ output+ .recv_timeout(deadline.saturating_duration_since(Instant::now()))+ .expect("terminal output barrier"),+ );+ }+ bytes.truncate(bytes.len() - 4);+ bytes+}++#[test]+fn zero_wheel_events_emit_neither_cursor_keys_nor_mouse_reports() {+ for mode in ["", "\x1b[?1000h", "\x1b[?1000h\x1b[?1006h"] {+ let (mut term, output) = terminal();+ term.advance_bytes(format!("\x1b[?1049h\x1b[?1h{}", mode));+ for _ in 0..4 {+ for button in [+ MouseButton::WheelUp(0),+ MouseButton::WheelDown(0),+ MouseButton::WheelLeft(0),+ MouseButton::WheelRight(0),+ ] {+ wheel(&mut term, button);+ }+ }+ assert_eq!(drain(&mut term, &output), b"", "mode {:?}", mode);+ }+}++#[test]+fn whole_wheel_events_keep_their_direction_and_scroll_speed() {+ let (mut term, output) = terminal();+ term.advance_bytes(b"\x1b[?1049h\x1b[?1h");+ wheel(&mut term, MouseButton::WheelUp(1));+ // The touchpad's fractional tail must not reverse an upward scroll.+ for _ in 0..4 {+ wheel(&mut term, MouseButton::WheelDown(0));+ }+ assert_eq!(drain(&mut term, &output), b"\x1bOA".repeat(3));+ wheel(&mut term, MouseButton::WheelDown(1));+ assert_eq!(drain(&mut term, &output), b"\x1bOB".repeat(3));++ term.advance_bytes(b"\x1b[?1000h\x1b[?1006h");+ wheel(&mut term, MouseButton::WheelUp(1));+ wheel(&mut term, MouseButton::WheelDown(1));+ assert_eq!(drain(&mut term, &output), b"\x1b[<64;1;1M\x1b[<65;1;1M");+}diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rsindex 88221371..15cede80 100644--- a/wezterm-gui/src/termwindow/mouseevent.rs+++ b/wezterm-gui/src/termwindow/mouseevent.rs@@ -8655,6 +8655,11 @@ impl super::TermWindow {TMB::None}}+ // Sub-line motion may have been consumed by a pixel-scroll+ // binding above. If it wasn't, it must not become terminal+ // input: zero otherwise falls through to WheelDown/Right(0),+ // which alternate-screen applications interpret as cursor keys.+ WMEK::VertWheel(0) | WMEK::HorzWheel(0) => return,WMEK::VertWheel(amount) => {if amount > 0 {TMB::WheelUp(amount as usize)