Skip to content

Add mouse click support to the TUI: click-to-select rows and picker options - #115

Open
MJohnson459 wants to merge 1 commit into
mainfrom
tui-mouse-clicks
Open

Add mouse click support to the TUI: click-to-select rows and picker options#115
MJohnson459 wants to merge 1 commit into
mainfrom
tui-mouse-clicks

Conversation

@MJohnson459

Copy link
Copy Markdown
Contributor

Add mouse click support to the TUI: click-to-select rows and picker options.

What changed

  • ui::draw now returns a HitMap — a list of (Rect, Hit) built during the
    draw, where Hit is CockpitRow/TaskRow/ProjectRow/ViewerRow/
    PickerOption and 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_STEP requires.
  • App::on_mouse(col, row, &hitmap) clears status like on_key does and
    moves the same selection fields j/k move. A click never fires the row's
    action. In a picker, a click moves the cursor and a second click on the
    option already under it sends Enter through the existing key handler, so
    confirmation runs the unchanged transition path.
  • A modal clears the map the screen behind it contributed, so only the popup's
    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.rs gains init_terminal/restore_terminal helpers that pair
    crossterm 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.
  • DESIGN.md §9 gains a sentence naming the mouse as a secondary input.

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) and
    cargo clippy --workspace --all-targets -- -D warnings are clean.
  • Six new tests in ui.rs render into a TestBackend, 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.
  • Drove the real binary under tmux against a scratch DB: a click moved the
    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.
  • Captured the raw pty stream: mouse reporting is enabled once at startup and
    disabled before leaving the alternate screen on quit.

Branch tui-mouse-clicks, committed locally, not pushed.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant