From 2f3c9fc0121363232c95a92d05d5cd48932d625a Mon Sep 17 00:00:00 2001 From: graykode Date: Sun, 5 Jul 2026 16:34:18 +0900 Subject: [PATCH] fix: allow terminal drag selection --- README.md | 2 ++ src/lib.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c40a2f8..68116b7 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,11 @@ abtop --once # Print snapshot and exit abtop --json # Print one JSON snapshot and exit (for scripts/tools) abtop --setup # Install rate limit collection hook abtop --theme dracula # Launch with a specific theme +abtop --mouse # Enable mouse click/scroll navigation ``` Recommended terminal size: **120x40** or larger. Minimum 80x24 — panels hide gracefully when small. +Mouse capture is off by default so terminal drag selection and copy keep working. Launch with `--mouse` if you prefer click targets and wheel navigation. ### Terminal Jump diff --git a/src/lib.rs b/src/lib.rs index da2dbe1..6a5d31d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -142,6 +142,7 @@ pub fn run() -> io::Result<()> { let demo_mode = std::env::args().any(|a| a == "--demo"); let exit_on_jump = std::env::args().any(|a| a == "--exit-on-jump"); + let mouse_capture = should_enable_mouse_capture(std::env::args()); // --json flag: print a machine-readable JSON snapshot and exit. // Single tick, no summary subprocesses. Useful for scripting and as a @@ -190,7 +191,9 @@ pub fn run() -> io::Result<()> { // Setup terminal enable_raw_mode()?; stdout().execute(EnterAlternateScreen)?; - stdout().execute(EnableMouseCapture)?; + if mouse_capture { + stdout().execute(EnableMouseCapture)?; + } let mut terminal = Terminal::new(CrosstermBackend::new(stdout()))?; let app_result = run_app( @@ -204,7 +207,11 @@ pub fn run() -> io::Result<()> { ); // Always attempt both cleanup steps regardless of app result - let r1 = stdout().execute(DisableMouseCapture).map(|_| ()); + let r1 = if mouse_capture { + stdout().execute(DisableMouseCapture).map(|_| ()) + } else { + Ok(()) + }; let r2 = disable_raw_mode(); let r3 = stdout().execute(LeaveAlternateScreen).map(|_| ()); @@ -212,6 +219,14 @@ pub fn run() -> io::Result<()> { app_result.and(r1).and(r2).and(r3) } +fn should_enable_mouse_capture(args: I) -> bool +where + I: IntoIterator, + S: AsRef, +{ + args.into_iter().any(|a| a.as_ref() == "--mouse") +} + fn run_app( terminal: &mut Terminal>, demo_mode: bool, @@ -550,3 +565,14 @@ fn fmt_tok(n: u64) -> String { format!("{}", n) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn mouse_capture_is_opt_in() { + assert!(!should_enable_mouse_capture(["abtop"])); + assert!(should_enable_mouse_capture(["abtop", "--mouse"])); + } +}