Add mouse click support to the TUI: click-to-select rows and picker options - #115
Open
MJohnson459 wants to merge 1 commit into
Open
Add mouse click support to the TUI: click-to-select rows and picker options#115MJohnson459 wants to merge 1 commit into
MJohnson459 wants to merge 1 commit into
Conversation
The TUI was keyboard-only: the event loop matched only key events and mouse capture was never enabled, so clicking a task did nothing. A click is a selection move and nothing more — the same field j/k set — except inside a picker, where a second click on the option already under the cursor sends the ⏎ its key handler answers. Key handlers deliberately run without geometry, so the layout is resolved where it is already known: draw() now returns a hit-map of (rect, intent) built from the scroll offset ratatui itself computed while rendering each list, and the main loop routes left-button-down through it. A modal clears the map the screen behind it contributed, so a popup owns the pointer and clicks beside it are ignored rather than dismissing it. Mouse reporting is enabled with the terminal and disabled with it — including on the panic path and around the $EDITOR, attach and plan round-trips that tear the TUI down — so no session leaves the terminal reporting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add mouse click support to the TUI: click-to-select rows and picker options.
What changed
ui::drawnow returns aHitMap— a list of (Rect, Hit) built during thedraw, where
HitisCockpitRow/TaskRow/ProjectRow/ViewerRow/PickerOptionand the index is the one the key handlers already count in.Each list's rects come from the scroll offset ratatui computed while
rendering it, so a scrolled list maps a visible line to the item on it.
Key handlers stay geometry-free, as
DETAIL_PAGE_STEPrequires.App::on_mouse(col, row, &hitmap)clearsstatuslikeon_keydoes andmoves the same selection fields
j/kmove. A click never fires the row'saction. In a picker, a click moves the cursor and a second click on the
option already under it sends
Enterthrough the existing key handler, soconfirmation runs the unchanged transition path.
options are targets: clicks outside are ignored, not a dismiss, and
text-entry modes (Prompt, LinkPr, AddProject, ViewerForm, ConfirmPr) and the
Detail popup offer no targets at all.
main.rsgainsinit_terminal/restore_terminalhelpers that paircrossterm mouse capture with ratatui's init/restore at all four sites
(startup/shutdown plus the $EDITOR, attach and plan round-trips), and a
panic hook that disables reporting on the way out of a panic.
Scope note: the document picker (Mode::DocPicker, added after this task was
written) is included with the other pickers — a click selects, a second click
link/unlinks, exactly as ⏎ does there.
Verification
cargo test --workspace(559 tests) andcargo clippy --workspace --all-targets -- -D warningsare clean.ui.rsrender into aTestBackend, capture the hit-map,and locate rows by the text drawn on them rather than by hard-coded
coordinates: cockpit queue + running strip, dead zones (header, detail pane,
status line), the tasks browser scrolled past its first page, the projects
and Config viewer lists, picker select-then-confirm (ready -> park -> parked),
and clicks outside a popup / in a text prompt. Mutation-checked the scrolled
case by ignoring the offset — it fails, as it should.
cockpit selection and the detail pane followed; two clicks on "park ->
parked" in the transition picker parked the task; a click on the detail pane
did nothing; a click selected the right row in the task browser (which
orders by score, not id); clicks still worked after an $EDITOR round-trip.
disabled before leaving the alternate screen on quit.
Branch tui-mouse-clicks, committed locally, not pushed.