diff --git a/crates/pullpen-ui/src/app/command/mod.rs b/crates/pullpen-ui/src/app/command/mod.rs index 51c2f61..38f657e 100644 --- a/crates/pullpen-ui/src/app/command/mod.rs +++ b/crates/pullpen-ui/src/app/command/mod.rs @@ -30,6 +30,7 @@ pub enum Cmd { Title, New, Messages, + Mouse, Clear, Quit, QuitAll, @@ -57,6 +58,7 @@ pub const COMMANDS: &[CmdInfo] = &[ c("diff", Cmd::Diff, "open the diff"), c("merge", Cmd::Merge, "merge now"), c("messages", Cmd::Messages, "recent results and errors"), + c("mouse", Cmd::Mouse, "turn the mouse off, or back on"), c("open", Cmd::Open, "open in the browser"), c("q", Cmd::Quit, "back, or quit from the list"), c("qa", Cmd::QuitAll, "quit from anywhere"), diff --git a/crates/pullpen-ui/src/app/input/mod.rs b/crates/pullpen-ui/src/app/input/mod.rs index fe52ea1..eec47d2 100644 --- a/crates/pullpen-ui/src/app/input/mod.rs +++ b/crates/pullpen-ui/src/app/input/mod.rs @@ -467,6 +467,12 @@ impl App { self.input = Input::Messages; vec![] } + Cmd::Mouse => { + self.ui.mouse = !self.ui.mouse; + let now = if self.ui.mouse { "on" } else { "off: the terminal selects text again" }; + self.say(markup(&format!("{{d|mouse {now}}}")), Mode::Normal); + vec![] + } Cmd::Clear if self.view_is(self.active, pullpen_core::View::Merged) => self.clear_landed(), Cmd::Clear => { self.refused(":clear drops finished rows in Merged"); diff --git a/crates/pullpen-ui/src/app/input/tests.rs b/crates/pullpen-ui/src/app/input/tests.rs index 7685c4b..31682a9 100644 --- a/crates/pullpen-ui/src/app/input/tests.rs +++ b/crates/pullpen-ui/src/app/input/tests.rs @@ -603,3 +603,13 @@ fn a_refused_new_pr_names_the_repo_not_a_number() { } assert!(said(&a).contains(":new acme/api: No commits between main and feat/retry"), "{}", said(&a)); } + +#[test] +fn mouse_turns_the_mouse_off_and_the_next_one_turns_it_back_on() { + let mut a = app(); + assert!(a.ui.mouse, "on unless asked"); + command(&mut a, "mouse"); + assert_eq!((a.ui.mouse, said(&a).as_str()), (false, "mouse off: the terminal selects text again")); + command(&mut a, "mouse"); + assert_eq!((a.ui.mouse, said(&a).as_str()), (true, "mouse on")); +} diff --git a/crates/pullpen-ui/src/app/mod.rs b/crates/pullpen-ui/src/app/mod.rs index dc3a344..37a2526 100644 --- a/crates/pullpen-ui/src/app/mod.rs +++ b/crates/pullpen-ui/src/app/mod.rs @@ -108,6 +108,9 @@ pub struct UiConfig { pub delete_branch: bool, /// How often a watched pipeline is asked for while it runs. pub watch: std::time::Duration, + /// Whether the terminal is asked to report the mouse. While it is, the + /// terminal's own text selection needs Shift held. + pub mouse: bool, } impl Default for UiConfig { @@ -118,6 +121,7 @@ impl Default for UiConfig { default_method: DefaultMethod::Repo, delete_branch: true, watch: pipeline::WATCH, + mouse: true, } } } diff --git a/crates/pullpen/src/term.rs b/crates/pullpen/src/term.rs index 55fd2ac..d70a013 100644 --- a/crates/pullpen/src/term.rs +++ b/crates/pullpen/src/term.rs @@ -35,6 +35,8 @@ const HISTORY_MAX: usize = 500; struct Term { kitty: bool, + /// Whether mouse reporting is on, to follow `:mouse`. + mouse: bool, /// The window title last sent, so it is sent again only when it changes. title: String, } @@ -54,14 +56,14 @@ impl Term { // escape sequence for every move of the pointer. let hook = std::panic::take_hook(); std::panic::set_hook(Box::new(move |info| { - Term { kitty, title: String::new() }.modes_off(); + Term { kitty, mouse: true, title: String::new() }.modes_off(); hook(info); })); // Save the window title on the terminal's own stack (XTWINOPS 22), // so leaving can put back whatever the shell had; a terminal without // the stack ignores it, and the shell's next prompt retitles anyway. execute!(stdout(), Print("\x1b[22;0t"), SetTitle("pullpen"))?; - Ok((terminal, Term { kitty, title: "pullpen".into() })) + Ok((terminal, Term { kitty, mouse: true, title: "pullpen".into() })) } /// Best effort: the terminal may already be gone, and an error here @@ -138,6 +140,10 @@ fn event_loop(terminal: &mut DefaultTerminal, term: &mut Term, l: &mut Loop) -> execute!(stdout(), SetTitle(&title))?; term.title = title; } + if l.app.ui.mouse != term.mouse { + term.mouse = l.app.ui.mouse; + if term.mouse { execute!(stdout(), EnableMouseCapture)? } else { execute!(stdout(), DisableMouseCapture)? } + } draw(terminal, l.app)?; let mut effects = Vec::new(); if event::poll(TICK)? { diff --git a/wiki/Commands.md b/wiki/Commands.md index b8e7912..345d4ec 100644 --- a/wiki/Commands.md +++ b/wiki/Commands.md @@ -35,6 +35,7 @@ names; `↑` `↓` walk history, filtered by what you have typed. | `:refresh [all]` | fetch this section, or all | | `:section ` | switch section | | `:messages` | the last 200 results and errors | +| `:mouse` | turn the mouse off, and again to turn it back on, until you quit | | `:clear` | in the Merged section, drop every finished row that is not failing | | `:dismiss [#n]` | in Deploys, resolve a failing branch by hand | | `:watch [#n]` | the PR's pipeline and its jobs' logs, live | diff --git a/wiki/Keys.md b/wiki/Keys.md index 3f8a7ec..ccb8b21 100644 --- a/wiki/Keys.md +++ b/wiki/Keys.md @@ -44,3 +44,8 @@ Optional: everything below is also a key. Each line is a test in A confirm prompt, the command line, a filter and `?` take keys only (`a_click_at_a_confirm_prompt_changes_nothing`). + +While pullpen has the mouse, most terminals select text only with `Shift` +held. `:mouse` hands the mouse back to the terminal, and again takes it +(`mouse_turns_the_mouse_off_and_the_next_one_turns_it_back_on` in +`crates/pullpen-ui/src/app/input/tests.rs`). diff --git a/wiki/Troubleshooting.md b/wiki/Troubleshooting.md index aff087f..4a5cc09 100644 --- a/wiki/Troubleshooting.md +++ b/wiki/Troubleshooting.md @@ -28,6 +28,10 @@ check, a conflict or a draft, and the key that helps. **A merge or an approval fails.** The message is the forge's own reason. `:messages` keeps the last 200. +**Dragging does not select text, or clicks do odd things.** pullpen asks the +terminal for the mouse. Hold `Shift` while dragging to select, or type +`:mouse` to turn the mouse off until you quit. + **Something else.** The log is `~/.local/state/pullpen/pullpen.log` (`%LOCALAPPDATA%\pullpen\state\pullpen.log` on Windows); it never contains a token. Attach `pullpen config check` and `pullpen --version` to an diff --git a/wiki/Your-first-session.md b/wiki/Your-first-session.md index 83f3065..535d6ec 100644 --- a/wiki/Your-first-session.md +++ b/wiki/Your-first-session.md @@ -32,7 +32,9 @@ how many PRs are armed and failing, when it last synced, and each forge with | `?` | every key | | `q` | back, or quit | -[All the keys](Keys). +[All the keys](Keys). The mouse works too: click a tab or a row, +double-click to open, click the top row of a PR to go back, and scroll with +the wheel ([Mouse](Keys#mouse)). ## Walking away