From c6e017698f46827bded10182958bbfce3a5d6744 Mon Sep 17 00:00:00 2001 From: Bryan Speelman Date: Thu, 26 Nov 2026 12:45:51 -0500 Subject: [PATCH 1/2] feat: the mouse works on every screen, not only the list A click selects the row under it and a second opens it in the grouped views, the pipeline, a job's steps and the file list; a click on a pane focuses it; the top row of a PR, pipeline or job goes back; the wheel scrolls the pane under the pointer and stops where the keys stop. Each frame records which item its rows show, so a click is resolved against what was drawn. Before, the pipeline and job screens passed clicks to the list beneath them, Deploys and Merged selected the wrong row, and a click in the preview pane selected a row. Every click presses the key that already does the thing; prompts and typed lines still take keys only. Co-Authored-By: Claude Fable 5.2 --- crates/pullpen-ui/src/app/armed/mod.rs | 10 +- crates/pullpen-ui/src/app/mod.rs | 15 +- crates/pullpen-ui/src/app/mouse/mod.rs | 148 +++++++++--- crates/pullpen-ui/src/app/mouse/tests.rs | 247 +++++++++++++++++++- crates/pullpen-ui/src/app/pipeline/mod.rs | 4 +- crates/pullpen-ui/src/views/detail.rs | 19 +- crates/pullpen-ui/src/views/pipeline/mod.rs | 29 ++- crates/pullpen/src/term.rs | 2 +- docs/PLAN.md | 2 +- wiki/Keys.md | 17 ++ 10 files changed, 430 insertions(+), 63 deletions(-) diff --git a/crates/pullpen-ui/src/app/armed/mod.rs b/crates/pullpen-ui/src/app/armed/mod.rs index 113edf6..d99ac78 100644 --- a/crates/pullpen-ui/src/app/armed/mod.rs +++ b/crates/pullpen-ui/src/app/armed/mod.rs @@ -208,18 +208,20 @@ impl App { let mut out = vec![tabs(&tab, self.active, w, self.narrow(w), right), vec![]]; let (mut body, mut sel_line) = (Vec::new(), 0); for (title, members) in groups.into_iter().filter(|(_, m)| !m.is_empty()) { - body.push(heading(&title, members.len())); + body.push((None, heading(&title, members.len()))); for (i, line) in members { if i == sec.sel { sel_line = body.len(); } - body.push(line); + body.push((Some(i), line)); } - body.push(vec![]); + body.push((None, vec![])); } let room = h.saturating_sub(4); let start = sel_line.saturating_sub(room.saturating_sub(1)); - out.extend(body.into_iter().skip(start).take(room)); + let (hits, shown): (Vec<_>, Vec) = body.into_iter().skip(start).take(room).unzip(); + self.set_hits(out.len(), hits); + out.extend(shown); while out.len() < h.saturating_sub(2) { out.push(vec![]); } diff --git a/crates/pullpen-ui/src/app/mod.rs b/crates/pullpen-ui/src/app/mod.rs index 46cf6a8..dc3a344 100644 --- a/crates/pullpen-ui/src/app/mod.rs +++ b/crates/pullpen-ui/src/app/mod.rs @@ -217,6 +217,9 @@ pub struct App { /// Seconds east of UTC, for showing clock times. pub tz_offset: i64, pub last_click: Option<(usize, Instant)>, + /// The item each screen row of the last frame showed, so a click lands + /// on what was drawn and not on a second copy of the layout. + pub(crate) hits: std::cell::RefCell>>, pub caps: HashMap, pub forges: Vec, pub theme: Theme, @@ -265,6 +268,7 @@ impl App { last_visit: None, tz_offset: 0, last_click: None, + hits: Default::default(), caps: HashMap::new(), forges: vec![Forge::GitHub, Forge::GitLab], theme, @@ -560,6 +564,7 @@ impl App { status: self.status(w), cmd: self.cmd_line(w), }; + self.hits.borrow_mut().clear(); let mut lines = match self .pipe_lines(w, h) .or_else(|| self.detail_lines(w, h)) @@ -568,7 +573,11 @@ impl App { .or_else(|| self.merged_lines(w, h)) { Some(l) => l, - None => list_screen(&screen, &ctx), + None => { + // Rows start under the tabs, a blank and the header. + self.set_hits(3, (sec.offset..rows.len()).take(body_rows(h)).map(Some)); + list_screen(&screen, &ctx) + } }; if let Some((menu, mw)) = self.menu() { let bottom = lines.len().saturating_sub(2); @@ -613,7 +622,9 @@ impl App { let mut lines = crate::views::detail::detail_screen(&screen, &self.ctx()); if let (Some((filter, sel)), Some(files)) = (&d.picker, self.diffs.get(&d.id)) { help::fade(&mut lines, h.saturating_sub(2)); - help::place(&mut lines, &crate::views::detail::picker(files, filter, *sel, d.file, h), w); + let (panel, hits) = crate::views::detail::picker(files, filter, *sel, d.file, h); + help::place(&mut lines, &panel, w); + self.set_hits(help::TOP, hits); } Some(lines) } diff --git a/crates/pullpen-ui/src/app/mouse/mod.rs b/crates/pullpen-ui/src/app/mouse/mod.rs index a5c1cd9..ed0cea2 100644 --- a/crates/pullpen-ui/src/app/mouse/mod.rs +++ b/crates/pullpen-ui/src/app/mouse/mod.rs @@ -1,10 +1,15 @@ //! The mouse, additive only (design §13): nothing here that a key cannot do. +//! A click finds what the last frame drew under it, then presses that key. use std::time::{Duration, Instant}; -use super::{App, Input}; -use crate::views::detail::Pane; -use crate::views::list::body_rows; +use pullpen_core::View; + +use super::{App, Effect, Input}; +use crate::keymap::Key; +use crate::views::detail::{self, Pane}; +use crate::views::list::PREVIEW_W; +use crate::views::pipeline::{self, JOB_TOP, steps}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Mouse { @@ -14,52 +19,123 @@ pub enum Mouse { /// Two clicks on one row this close together open it. const DOUBLE: Duration = Duration::from_millis(400); -/// Rows above the list body: tabs, a blank, the header. -const LIST_TOP: u16 = 3; +/// Rows one notch of the wheel moves. +const WHEEL: usize = 3; impl App { - pub fn mouse(&mut self, m: Mouse, now: Instant) { + /// Records which item each screen row from `top` down shows. + pub(super) fn set_hits(&self, top: usize, rows: impl IntoIterator>) { + let mut h = self.hits.borrow_mut(); + *h = vec![None; top]; + h.extend(rows); + } + + pub fn mouse(&mut self, m: Mouse, now: Instant) -> Vec { + // A prompt or a line being typed is answered by keys alone, so a + // stray click can neither confirm nor cancel it. if !matches!(self.input, Input::Normal) { - return; - } - if let Some(d) = &mut self.detail { - if let Mouse::Scroll { x, down } = m { - let p = if usize::from(x) < 2 + 56 + 2 && !d.zoom { Pane::Overview } else { Pane::Diff }; - let s = &mut d.scroll[p as usize]; - *s = if down { *s + 3 } else { s.saturating_sub(3) }; - } - return; + return vec![]; } + self.pending = None; match m { - Mouse::Click { x, y: 0 } => { - if let Some(i) = self.tab_at(usize::from(x)) { - self.active = i; - } - } - Mouse::Click { y, .. } if y >= LIST_TOP && usize::from(y - LIST_TOP) < body_rows(self.height) => { - if self.sections[self.active].section.view == pullpen_core::View::Armed { - return; + Mouse::Click { x, y } => self.click(usize::from(x), usize::from(y), now), + Mouse::Scroll { x, down } => self.wheel(usize::from(x), down, now), + } + } + + fn click(&mut self, x: usize, y: usize, now: Instant) -> Vec { + let hit = self.hits.borrow().get(y).copied().flatten(); + let h = self.height; + // Inside the two panes or on their headings, which sit a row above. + let panes = |top: usize| (top - 1..h.saturating_sub(2)).contains(&y); + let n_steps = self.open_job().map_or(0, |(_, j, _)| steps(j, self.current_log(), self.now).len()); + // The key the click stands for, and the item it is on when the key + // waits for a second click. + let (key, item) = if let Some(p) = &mut self.pipe { + match (&mut p.job, hit) { + _ if y == 0 => (Key::Char('q'), None), + (Some(v), _) if panes(JOB_TOP) && x < 2 + pipeline::LW => { + v.steps = true; + let Some(i) = y.checked_sub(JOB_TOP).filter(|i| *i < n_steps) else { return vec![] }; + v.step = i; + (Key::Enter, Some(i)) } - let i = self.section().offset + usize::from(y - LIST_TOP); - if i >= self.section().visible().len() { - return; + (Some(_), _) if panes(JOB_TOP) => (Key::Char('l'), None), + (None, Some(k)) => { + p.sel = k; + (Key::Enter, hit) } - let double = self.last_click.is_some_and(|(j, at)| j == i && now.duration_since(at) < DOUBLE); - self.section_mut().sel = i; - self.last_click = Some((i, now)); - if double { - self.open_detail(false); + _ => return vec![], + } + } else if let Some(d) = &mut self.detail { + match (&mut d.picker, hit) { + (Some((_, sel)), Some(r)) => { + *sel = r; + (Key::Enter, hit) } + (Some(_), None) => return vec![], + _ if y == 0 => (Key::Char('q'), None), + _ if panes(detail::TOP) => (Key::Char(if x < 2 + detail::LW && !d.zoom { 'h' } else { 'l' }), None), + _ => return vec![], } - Mouse::Scroll { down, .. } => { - let n = self.section().visible().len(); - let s = self.section_mut(); - s.sel = if down { (s.sel + 3).min(n.saturating_sub(1)) } else { s.sel.saturating_sub(3) }; + } else if y == 0 { + if let Some(i) = self.tab_at(x) { + self.active = i; } - Mouse::Click { .. } => {} + return vec![]; + } else { + let Some(i) = hit.filter(|_| x < self.list_width()) else { return vec![] }; + self.section_mut().sel = i; + (Key::Enter, hit) + }; + match item { + Some(i) if !self.twice(i, now) => vec![], + _ => self.key(key, now), } } + /// Whether this is the second click on item `i` in quick succession. + fn twice(&mut self, i: usize, now: Instant) -> bool { + let double = self.last_click.is_some_and(|(j, at)| j == i && now.duration_since(at) < DOUBLE); + // Forgotten once used: the screen a double click opens has rows of + // its own, and a third click must not open one of those. + self.last_click = (!double).then_some((i, now)); + double + } + + /// The wheel scrolls the pane under the pointer, as the arrow keys + /// would if it had the focus, and leaves the focus where it was. + fn wheel(&mut self, x: usize, down: bool, now: Instant) -> Vec { + let key = if down { Key::Down } else { Key::Up }; + let roll = |a: &mut App| (0..WHEEL).flat_map(|_| a.key(key, now)).collect(); + if let Some(v) = self.pipe.as_mut().and_then(|p| p.job.as_mut()) { + let was = std::mem::replace(&mut v.steps, x < 2 + pipeline::LW); + let out = roll(self); + if let Some(v) = self.pipe.as_mut().and_then(|p| p.job.as_mut()) { + v.steps = was; + } + return out; + } + if self.pipe.is_none() + && let Some(d) = self.detail.as_mut().filter(|d| d.picker.is_none()) + { + let over = if x < 2 + detail::LW && !d.zoom { Pane::Overview } else { Pane::Diff }; + let was = std::mem::replace(&mut d.focus, over); + let out = roll(self); + if let Some(d) = &mut self.detail { + d.focus = was; + } + return out; + } + roll(self) + } + + /// Where the list's rows end: the preview beside them is not a row. + fn list_width(&self) -> usize { + let w = self.last_width; + if self.view_is(self.active, View::List) && self.preview_shown(w) { w.saturating_sub(PREVIEW_W + 4) } else { w } + } + /// Which tab covers column `x`, laid out as `views::chrome::tabs` lays /// them out. fn tab_at(&self, x: usize) -> Option { diff --git a/crates/pullpen-ui/src/app/mouse/tests.rs b/crates/pullpen-ui/src/app/mouse/tests.rs index b1e369d..8f8edf5 100644 --- a/crates/pullpen-ui/src/app/mouse/tests.rs +++ b/crates/pullpen-ui/src/app/mouse/tests.rs @@ -1,8 +1,11 @@ use std::time::Instant; use pullpen_fixtures as fx; +use ratatui::buffer::Buffer; +use ratatui::layout::Rect; use super::*; +use crate::app::Input; use crate::app::SectionState; use crate::glyphs::Glyphs; use crate::paint::Theme; @@ -17,18 +20,86 @@ fn app() -> App { .collect(); let mut a = App::new(sections, Theme { palette: Palette::new(Tier::True), glyphs: Glyphs::Unicode }, fx::NOW); a.active = 6; - a.height = 40; a } +fn draw(a: &mut App, w: u16) -> Vec { + let area = Rect::new(0, 0, w, 40); + let mut buf = Buffer::empty(area); + a.render(area, &mut buf); + (0..40).map(|y| (0..w).map(|x| buf[(x, y)].symbol()).collect()).collect() +} + +/// The screen row showing `text`. +fn y_of(rows: &[String], text: &str) -> u16 { + rows.iter().position(|r| r.contains(text)).unwrap_or_else(|| panic!("{text:?} is not on screen")) as u16 +} + +fn click(a: &mut App, x: u16, y: u16) { + a.mouse(Mouse::Click { x, y }, Instant::now()); +} + +/// Two clicks 100ms apart, a second after any click before them. +fn twice(a: &mut App, x: u16, y: u16) { + let t = Instant::now() + Duration::from_secs(1); + a.mouse(Mouse::Click { x, y }, t); + a.mouse(Mouse::Click { x, y }, t + Duration::from_millis(100)); +} + +fn wheel(a: &mut App, x: u16, down: bool) { + a.mouse(Mouse::Scroll { x, down }, Instant::now()); +} + +fn selected(a: &App) -> u64 { + a.section().selected().unwrap().id.number +} + +/// #812 in the Open section, `Enter` then `w`: its pipeline over its detail +/// view, the runs answered. +fn in_pipeline() -> App { + let mut a = app(); + a.active = 5; + a.sections[5].sel = a.sections[5].prs.iter().position(|p| p.id.number == 812).unwrap(); + let id = a.section().prs[a.section().sel].id.clone(); + a.key(Key::Enter, Instant::now()); + a.key(Key::Char('w'), Instant::now()); + a.runs_loaded(id, fx::runs(812)); + a +} + +/// `in_pipeline`, then Enter on `build`, its log answered. +fn in_job() -> App { + let mut a = in_pipeline(); + let id = a.pipe.as_ref().unwrap().id.clone(); + a.key(Key::Enter, Instant::now()); + a.log_loaded(id, "79".into(), fx::LOG); + a +} + +/// #4821's detail view, its diff of fourteen files loaded. +fn in_detail() -> App { + let mut a = app(); + let id = a.section().prs[0].id.clone(); + a.details.insert(id.clone(), fx::detail(4821)); + a.diffs.insert(id, fx::diff(4821)); + a.key(Key::Enter, Instant::now()); + a +} + +fn job(a: &App) -> &crate::views::pipeline::JobView { + a.pipe.as_ref().unwrap().job.as_ref().unwrap() +} + #[test] fn clicking_a_tab_switches_and_a_row_selects_and_twice_opens() { let mut a = app(); + draw(&mut a, 120); let t = Instant::now(); // " Mine 6 Needs my review 4 …": column 12 is inside the second tab. a.mouse(Mouse::Click { x: 12, y: 0 }, t); assert_eq!(a.active, 1); a.active = 6; + draw(&mut a, 120); a.mouse(Mouse::Click { x: 30, y: 5 }, t); assert_eq!((a.section().sel, a.detail.is_none()), (2, true)); a.mouse(Mouse::Click { x: 30, y: 5 }, t + Duration::from_millis(100)); @@ -38,6 +109,180 @@ fn clicking_a_tab_switches_and_a_row_selects_and_twice_opens() { #[test] fn the_wheel_moves_the_selection() { let mut a = app(); + draw(&mut a, 120); a.mouse(Mouse::Scroll { x: 0, down: true }, Instant::now()); assert_eq!(a.section().sel, 3); } + +#[test] +fn a_click_in_a_grouped_view_selects_the_row_under_it_not_a_heading() { + let mut a = app(); + // Armed, Deploys, Merged. + for view in [2, 3, 4] { + a.active = view; + let want = a.section().visible().last().unwrap().id.number; + let rows = draw(&mut a, 120); + click(&mut a, 30, y_of(&rows[1..], &format!("#{want} ")) + 1); + assert_eq!(selected(&a), want, "section {view}"); + // Row 2 is the first group's heading. + click(&mut a, 30, 2); + assert_eq!(selected(&a), want, "a heading is not a row, section {view}"); + } +} + +#[test] +fn a_double_click_in_deploys_opens_the_pipeline() { + let mut a = app(); + a.active = 3; + let rows = draw(&mut a, 120); + twice(&mut a, 30, y_of(&rows, "#812 ")); + assert_eq!(a.pipe.as_ref().map(|p| p.id.number), Some(812)); + assert!(a.detail.is_none(), "as Enter does there, not the detail view"); +} + +#[test] +fn a_click_in_the_preview_pane_selects_nothing() { + let mut a = app(); + let rows = draw(&mut a, 120); + let pane = rows[5].chars().position(|c| c == '│').unwrap() as u16; + click(&mut a, pane + 5, 5); + assert_eq!(a.section().sel, 0); + click(&mut a, pane - 5, 5); + assert_eq!(a.section().sel, 2, "the same row, left of the preview"); +} + +#[test] +fn the_pipeline_screen_takes_the_click_not_the_list_beneath_it() { + let mut a = in_pipeline(); + a.key(Key::Char('q'), Instant::now()); + a.key(Key::Char('q'), Instant::now()); + a.key(Key::Char('w'), Instant::now()); + assert!(a.pipe.is_some() && a.detail.is_none(), "the pipeline, straight over the list"); + let rows = draw(&mut a, 120); + click(&mut a, 30, y_of(&rows, "lint")); + assert_eq!((selected(&a), a.pipe.as_ref().unwrap().sel), (812, 0)); + wheel(&mut a, 30, true); + assert_eq!((selected(&a), a.pipe.as_ref().unwrap().sel), (812, 3), "and the wheel"); +} + +#[test] +fn a_job_row_selects_and_twice_opens_the_job() { + let mut a = in_pipeline(); + let rows = draw(&mut a, 120); + for not_a_job in ["after merge", "zo to show"] { + twice(&mut a, 30, y_of(&rows, not_a_job)); + assert_eq!(a.pipe.as_ref().unwrap().sel, 2, "{not_a_job}"); + } + click(&mut a, 30, y_of(&rows, "go mod verify")); + assert_eq!(a.pipe.as_ref().unwrap().sel, 1); + assert!(a.pipe.as_ref().unwrap().job.is_none()); + twice(&mut a, 30, y_of(&rows, "lint")); + assert_eq!(job(&a).name, "lint"); +} + +#[test] +fn the_click_that_opens_a_screen_does_not_count_towards_opening_a_row_of_it() { + let mut a = app(); + a.active = 3; + let rows = draw(&mut a, 120); + let y = y_of(&rows, "#812 "); + let t = Instant::now(); + for ms in [0, 100, 200] { + a.mouse(Mouse::Click { x: 30, y }, t + Duration::from_millis(ms)); + draw(&mut a, 120); + } + let p = a.pipe.as_ref().unwrap(); + assert!(p.job.is_none(), "three quick clicks open the pipeline and stop there"); +} + +#[test] +fn clicking_a_pane_focuses_it() { + let mut a = in_detail(); + draw(&mut a, 120); + click(&mut a, 80, 20); + assert_eq!(a.detail.as_ref().unwrap().focus, Pane::Diff); + click(&mut a, 10, 20); + assert_eq!(a.detail.as_ref().unwrap().focus, Pane::Overview); + click(&mut a, 10, 3); + assert!(a.detail.is_some(), "the rows above the panes do nothing"); + + let mut a = in_job(); + let rows = draw(&mut a, 120); + click(&mut a, 10, y_of(&rows, "Getting source from Git")); + assert_eq!((job(&a).steps, job(&a).step), (true, 2)); + click(&mut a, 80, 20); + assert!(!job(&a).steps, "the log has the focus"); + twice(&mut a, 10, y_of(&rows, "Getting source from Git")); + assert_eq!((job(&a).steps, job(&a).follow), (false, false), "twice on a step jumps to it, as Enter does"); +} + +#[test] +fn the_wheel_scrolls_the_pane_under_it_and_the_log_stops_following() { + let mut a = in_job(); + draw(&mut a, 120); + assert!(job(&a).follow && !job(&a).steps); + wheel(&mut a, 10, true); + assert_eq!((job(&a).step, job(&a).steps, job(&a).follow), (3, false, true), "over the steps: the step moves"); + wheel(&mut a, 80, false); + assert_eq!((job(&a).steps, job(&a).follow), (false, false), "over the log: it scrolls up and lets go"); +} + +#[test] +fn the_wheel_stops_at_the_end_of_a_pane() { + let mut a = in_detail(); + draw(&mut a, 120); + for _ in 0..100 { + wheel(&mut a, 80, true); + } + let d = a.detail.clone().unwrap(); + assert_eq!(d.focus, Pane::Overview, "the wheel leaves the focus alone"); + assert_eq!(d.scroll[0], 0); + a.key(Key::Char('l'), Instant::now()); + a.key(Key::Char('G'), Instant::now()); + assert_eq!(d.scroll[1], a.detail.as_ref().unwrap().scroll[1], "where G stops"); + assert!(d.scroll[1] > 0); +} + +#[test] +fn the_breadcrumb_goes_back_one_level() { + let mut a = in_job(); + draw(&mut a, 120); + click(&mut a, 5, 0); + assert!(a.pipe.as_ref().is_some_and(|p| p.job.is_none()), "job to pipeline"); + click(&mut a, 5, 0); + assert!(a.pipe.is_none() && a.detail.is_some(), "pipeline to the detail view it was opened from"); + click(&mut a, 5, 0); + assert!(a.detail.is_none(), "detail view to the list"); + assert_eq!(a.active, 5, "and there row 0 is the tabs again; column 5 is the first"); + draw(&mut a, 120); + click(&mut a, 12, 0); + assert_eq!(a.active, 1); +} + +#[test] +fn a_picker_row_selects_and_twice_opens_the_file() { + let mut a = in_detail(); + a.key(Key::Char('F'), Instant::now()); + let rows = draw(&mut a, 120); + let y = y_of(&rows, "part5.ts"); + click(&mut a, 40, y); + assert_eq!(a.detail.as_ref().unwrap().picker.as_ref().map(|p| p.1), Some(4)); + click(&mut a, 5, 0); + assert!(a.detail.as_ref().is_some_and(|d| d.picker.is_some()), "a click off the rows leaves the list open"); + twice(&mut a, 40, y); + let d = a.detail.as_ref().unwrap(); + assert_eq!((d.file, d.picker.is_none(), d.focus), (4, true, Pane::Diff)); +} + +#[test] +fn a_click_at_a_confirm_prompt_changes_nothing() { + let mut a = app(); + a.key(Key::Char('x'), Instant::now()); + assert!(matches!(a.input, Input::Confirm(_)), "x asks before closing"); + draw(&mut a, 120); + twice(&mut a, 30, 5); + click(&mut a, 12, 0); + wheel(&mut a, 30, true); + assert!(matches!(a.input, Input::Confirm(_)), "still asking"); + assert_eq!((a.active, a.section().sel, a.detail.is_none()), (6, 0, true)); +} diff --git a/crates/pullpen-ui/src/app/pipeline/mod.rs b/crates/pullpen-ui/src/app/pipeline/mod.rs index 8acb0df..5928295 100644 --- a/crates/pullpen-ui/src/app/pipeline/mod.rs +++ b/crates/pullpen-ui/src/app/pipeline/mod.rs @@ -198,7 +198,9 @@ impl App { status: self.status(w), cmd: self.cmd_line(w), }; - Some(pipeline_screen(&screen, &ctx)) + let (lines, hits) = pipeline_screen(&screen, &ctx); + self.set_hits(0, hits); + Some(lines) } /// The status line's position: the job among the jobs, or the log row diff --git a/crates/pullpen-ui/src/views/detail.rs b/crates/pullpen-ui/src/views/detail.rs index 6c20405..baac369 100644 --- a/crates/pullpen-ui/src/views/detail.rs +++ b/crates/pullpen-ui/src/views/detail.rs @@ -12,12 +12,12 @@ use super::words::verdict_long; use crate::palette::Tok; use crate::span::{Line, Span, fit, lr, markup, s, sp}; -const LW: usize = 56; +pub const LW: usize = 56; const FACT_W: usize = 59; /// Checks shown before the rest fold behind `zo`. const FOLDED: usize = 5; /// Rows above the panes: breadcrumb, title, meta, verdict, facts, heading. -const TOP: usize = 11; +pub const TOP: usize = 11; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Pane { @@ -249,8 +249,15 @@ pub fn matching(files: &[FileDiff], filter: &str) -> Vec { } /// The `F` file list: every changed file with its size, filtered by what -/// has been typed, in the same surface panel as the `?` overlay. -pub fn picker(files: &[FileDiff], filter: &str, sel: usize, current: usize, h: usize) -> Vec { +/// has been typed, in the same surface panel as the `?` overlay. With it, +/// the row of the filtered list each panel row shows. +pub fn picker( + files: &[FileDiff], + filter: &str, + sel: usize, + current: usize, + h: usize, +) -> (Vec, Vec>) { use super::help::PANEL_W; let pad = |l: &[Span]| { let mut v = vec![sp(3)]; @@ -261,6 +268,7 @@ pub fn picker(files: &[FileDiff], filter: &str, sel: usize, current: usize, h: u if filter.is_empty() { markup("{B|files}") } else { markup(&format!("{{B|files}}{{a| {}}}", esc(filter))) }; let hint = markup("{d|type to filter · ↑↓ move · Enter open · Esc close}"); let mut out = vec![pad(&[]), pad(&lr(&title, &hint, PANEL_W - 6)), pad(&[])]; + let mut hits = vec![None; out.len()]; let shown = matching(files, filter); let room = h.saturating_sub(12).max(3); let start = sel.saturating_sub(room - 1); @@ -274,6 +282,7 @@ pub fn picker(files: &[FileDiff], filter: &str, sel: usize, current: usize, h: u l.push(sp(2)); l.push(s(&f.path, Tok::Fg)); let line = pad(&l); + hits.push(Some(row)); out.push(if row == sel { crate::span::with_bg( line.into_iter() @@ -293,7 +302,7 @@ pub fn picker(files: &[FileDiff], filter: &str, sel: usize, current: usize, h: u } out.push(pad(&markup(&format!("{{d|{} of {} files}}", shown.len(), files.len())))); out.push(pad(&[])); - out + (out, hits) } /// Rows where each hunk's header sits, for `]c` and `[c`. diff --git a/crates/pullpen-ui/src/views/pipeline/mod.rs b/crates/pullpen-ui/src/views/pipeline/mod.rs index d6f5288..8013273 100644 --- a/crates/pullpen-ui/src/views/pipeline/mod.rs +++ b/crates/pullpen-ui/src/views/pipeline/mod.rs @@ -12,9 +12,9 @@ use crate::palette::Tok; use crate::span::{Line, fit, lr, markup, s, sp, with_bg}; /// The steps pane's width in the job screen. -const LW: usize = 40; +pub const LW: usize = 40; /// Rows above the body: the PR's four, a gap, the job, a gap, the headings. -const JOB_TOP: usize = 8; +pub const JOB_TOP: usize = 8; /// The pipeline screen's state; `job` is set while a job is open over it. #[derive(Clone, Debug)] @@ -197,31 +197,32 @@ fn job_row(j: &JobRun, sel: bool, w: usize, ctx: &Ctx) -> Line { if sel { with_bg(l, Tok::Sel) } else { l } } -pub fn pipeline_screen(o: &PipelineScreen, ctx: &Ctx) -> Vec { +/// The screen, and the job each of its rows shows. +pub fn pipeline_screen(o: &PipelineScreen, ctx: &Ctx) -> (Vec, Vec>) { let (w, pr) = (o.w, o.pr); let mut out = head(pr, o.section, "pipeline", &o.refreshed, w, ctx); - let mut body: Vec = Vec::new(); + let mut body: Vec<(Option, Line)> = Vec::new(); // The body row of the selected job, to keep it on screen. let mut at = 0; match o.runs { - None => body.push(markup(" {d|asking for the pipeline…}")), - Some([]) => body.push(markup(" {d|no pipeline has run for this PR}")), + None => body.push((None, markup(" {d|asking for the pipeline…}"))), + Some([]) => body.push((None, markup(" {d|no pipeline has run for this PR}"))), Some(runs) => { let mut k = 0; for (i, r) in runs.iter().enumerate() { if i > 0 { - body.push(vec![]); + body.push((None, vec![])); } - body.push(run_head(r, pr, w, ctx)); + body.push((None, run_head(r, pr, w, ctx))); if !o.pipe.shown(i, r) { - body.push(markup(&format!(" {{d|zo to show its {} jobs}}", r.jobs.len()))); + body.push((None, markup(&format!(" {{d|zo to show its {} jobs}}", r.jobs.len())))); continue; } for j in &r.jobs { if k == o.pipe.sel { at = body.len(); } - body.push(job_row(j, k == o.pipe.sel, w, ctx)); + body.push((Some(k), job_row(j, k == o.pipe.sel, w, ctx))); k += 1; } } @@ -229,13 +230,17 @@ pub fn pipeline_screen(o: &PipelineScreen, ctx: &Ctx) -> Vec { } let room = o.h.saturating_sub(out.len() + 2); let skip = (at + 1).saturating_sub(room); - out.extend(body.into_iter().skip(skip).take(room)); + let mut hits = vec![None; out.len()]; + for (hit, line) in body.into_iter().skip(skip).take(room) { + hits.push(hit); + out.push(line); + } while out.len() < o.h.saturating_sub(2) { out.push(vec![]); } out.push(status(w, &o.status)); out.push(o.cmd.clone()); - out.into_iter().map(|l| fit(&l, w, false)).collect() + (out.into_iter().map(|l| fit(&l, w, false)).collect(), hits) } /// A step as the job screen lists it, from GitHub's steps or, on GitLab, diff --git a/crates/pullpen/src/term.rs b/crates/pullpen/src/term.rs index 462e6b4..97a1159 100644 --- a/crates/pullpen/src/term.rs +++ b/crates/pullpen/src/term.rs @@ -151,7 +151,7 @@ fn event_loop(terminal: &mut DefaultTerminal, term: &mut Term, l: &mut Loop) -> _ => None, }; if let Some(ev) = ev { - l.app.mouse(ev, Instant::now()); + effects.extend(l.app.mouse(ev, Instant::now())); } } // A resize needs nothing beyond the redraw at the top of the diff --git a/docs/PLAN.md b/docs/PLAN.md index bfc5dbd..79d57cd 100644 --- a/docs/PLAN.md +++ b/docs/PLAN.md @@ -47,7 +47,7 @@ Each row is settled. The ones with a record are answered by its number: ADR-001 | Clipboard / browser | `open` crate for `o`; no clipboard in v1 | | | Row treatment | **1a columns** (`rowA`) | Chosen in design review. | | Vocabulary | "PR" everywhere; GitLab `!812` displayed `#812`; both spellings accepted in commands | Design §01, §07. | -| Mouse | Optional, additive: click row selects, click tab switches, wheel scrolls panes | Everything reachable by keyboard first. | +| Mouse | Optional, additive, on every screen: a click selects the row under it and twice opens it, click tab switches, click a pane focuses it, the top row of a subscreen goes back, wheel scrolls the pane under it. Prompts and typed lines ignore it | Everything reachable by keyboard first. | | License | MIT | | Crates (pin latest stable at implementation time). This list is the dependency ceiling; adding a crate takes a record first (ADR-005): `ratatui`, `crossterm`, `tokio`, `reqwest` (rustls, json), `serde`, `serde_json`, `toml`, `clap`, `directories`, `thiserror`, `anyhow`, `tracing` + `tracing-subscriber` (file log only, never stdout), `unicode-width`, `open`, `strsim` (did-you-mean), `async-trait` (object-safe `Forge`), `insta` (snapshots, dev), `wiremock` (forge tests, dev). diff --git a/wiki/Keys.md b/wiki/Keys.md index b0a47a5..3f8a7ec 100644 --- a/wiki/Keys.md +++ b/wiki/Keys.md @@ -27,3 +27,20 @@ fold the checks, and `d` widens the diff. Single keys can be rebound by name in `config.toml`, under `[keys]`: `merge = "m"` adds `m` for merging, and `M` keeps working. + +## Mouse + +Optional: everything below is also a key. Each line is a test in +`crates/pullpen-ui/src/app/mouse/tests.rs`. + +| mouse | does | test | +|---|---|---| +| click a tab | that section | `clicking_a_tab_switches_and_a_row_selects_and_twice_opens` | +| click a row | selects it: a PR, a job, a step, a file in `F` | `a_click_in_a_grouped_view_selects_the_row_under_it_not_a_heading`, `a_job_row_selects_and_twice_opens_the_job`, `a_picker_row_selects_and_twice_opens_the_file` | +| double-click a row | `Enter` on it | `a_double_click_in_deploys_opens_the_pipeline` | +| click a pane | `h` or `l` | `clicking_a_pane_focuses_it` | +| click the top row of a PR, pipeline or job | `q` | `the_breadcrumb_goes_back_one_level` | +| wheel | scrolls what is under the pointer | `the_wheel_scrolls_the_pane_under_it_and_the_log_stops_following`, `the_wheel_stops_at_the_end_of_a_pane` | + +A confirm prompt, the command line, a filter and `?` take keys only +(`a_click_at_a_confirm_prompt_changes_nothing`). From 8a7a4f05d4d8507a1e21e0a3ff5bd04627580b67 Mon Sep 17 00:00:00 2001 From: Bryan Speelman Date: Thu, 26 Nov 2026 12:48:18 -0500 Subject: [PATCH 2/2] fix: a panic turns mouse reporting off before the shell gets the terminal back ratatui's panic hook leaves raw mode and the alternate screen only, so a crash left focus and mouse reporting and the keyboard flags on, and the shell printed an escape sequence for every move of the pointer. Co-Authored-By: Claude Fable 5.2 --- crates/pullpen/src/term.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/pullpen/src/term.rs b/crates/pullpen/src/term.rs index 97a1159..55fd2ac 100644 --- a/crates/pullpen/src/term.rs +++ b/crates/pullpen/src/term.rs @@ -49,6 +49,14 @@ impl Term { execute!(stdout(), PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES))?; } execute!(stdout(), EnableFocusChange, EnableMouseCapture)?; + // ratatui's panic hook leaves raw mode and the alternate screen and + // nothing else: a shell left with mouse reporting on prints an + // 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(); + 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. @@ -59,11 +67,17 @@ impl Term { /// Best effort: the terminal may already be gone, and an error here /// would only hide the one the caller is about to return. fn leave(&self) { + self.modes_off(); + ratatui::restore(); + } + + /// Turns off what `enter` turned on beyond ratatui's own setup. Best + /// effort, for the reason `leave` gives. + fn modes_off(&self) { let _ = execute!(stdout(), DisableFocusChange, DisableMouseCapture, Print("\x1b[23;0t")); if self.kitty { let _ = execute!(stdout(), PopKeyboardEnhancementFlags); } - ratatui::restore(); } }