Skip to content

feat(tui,screenshots): one picker overlay; the terminal UI captured as a real screenshot - #1348

Merged
huichen merged 3 commits into
mainfrom
pr/huichen
Oct 25, 2026
Merged

huichen merged 3 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

What and why

The workbench gains a single picker: /model, /theme and /sessions now open the same overlay instead of three separate menus, so the three lists share one layout, one key map and one place to fix. The frame renderer stops relying on a line feed to advance between rows and addresses every row absolutely, which is what makes the layout survive a row that grows or is skipped. Alongside it, the terminal UI becomes screenshot-able from the real binary: a small harness drives the workbench through a demo agent and renders each pane to a PNG, and three of those captures (model, theme, session pickers) are checked in under docs/tui/assets and referenced from the guides.

Commits

  • fix(tui): address every frame row absolutely instead of advancing with a line feed
  • feat(screenshots): capture the terminal UI as a real screenshot
  • feat(tui): one picker overlay behind /model, /theme and /sessions

Verification

Run on the frozen tip (be092e8f8) with rustc 1.97.0 / clippy 0.1.97 (the CI toolchain):

  • cargo fmt --all -- --check — clean
  • cargo clippy -p future-tui --all-targets -- -D warnings — clean (includes the new tui/examples demo binaries)
  • cargo test -p future-tui --lib — 1013 passed, 0 failed

Screenshot captures were produced by the new scripts/screenshots/tui_capture.py against the real TUI; only the three referenced PNGs are committed.

Notes

  • The new picker lives in tui/src/workbench/picker.rs and is driven through workbench/mod.rs; the old per-command menus are gone, so /model, /theme and /sessions share their behaviour by construction.
  • Change is confined to future-tui, scripts/screenshots and docs/; no other crate's public API moves.

…h a line feed

A frame written with `\r\n` between rows is only safe while the program's idea
of the height equals the terminal's. It need not: the pty reports its size
through SIGWINCH, so between a resize and the next frame a taller frame runs
past the last row and the alternate screen scrolls. The frame is then not
clipped but *shifted* — the header leaves the screen, every band sits above the
row the layout assigned it, and an SGR mouse report (a fixed cell) lands on the
wrong thing.

Measured while building the screenshot harness: in a ttyd-rendered terminal at
1000x700, two frames after start only the last seven rows were still visible.

Every row is now placed with `CSI row;1H`, so a size mismatch is harmless —
rows past the end draw nothing and no write ever scrolls.
The TUI had no capture path in the repository: `capture.py terminal` wraps a
command's stdout in a terminal frame without parsing ANSI, and the old
gitignored `.future/tools/tui-shot/` died with the inline TUI it drove.

`capture.py tui` runs the shipped binary the way the desktop and mobile
scenarios run the real app: `demo_agent` (a scripted gRPC server, one fixed
session) answers, `future tui --offline` runs in a pty of a fixed size, and
`tui_capture.py` keeps the bytes it wrote there. `tui_terminal.py` replays
that stream through a terminal cell model — absolute positioning, SGR colours,
double-width CJK, the 256-colour palette, the caret the app left — and has
headless Chrome rasterize the glyphs.

Two runs produce byte-identical PNGs, which is what lets a diff mean "the UI
changed".

Bugs this found and fixed, each with a test:

- the demo agent dropped its event-stream sender on return, so the stream ended
  after its first frame; the client then spent a connect wait on every call and
  the surface never painted at all.
- the renderer only consumed the CSI sequences it understood, so `ESC[?25h`
  was printed as the literal text `[?25h` into the prompt row. Only OCR of the
  finished PNG caught it; the parser now consumes every CSI and OSC form.
- `tui_capture` sizes the pty before exec. `pty.fork()` execs first, and a
  program that reads 0x0 draws nothing (measured: 0 bytes, looked like a hang).
`/model` and `/theme` cycled a value at a time (twenty models, six themes),
`/sessions` refreshed a list nobody could see, and `/new` quietly swapped the
session instead of showing the launchpad. There is now one list component —
`workbench/picker.rs` — that all three menus open:

- incremental search, `↑↓` / `pageUp` / `pageDown`, group headings the highlight
  steps over, `✓` on the row in force, and a window that follows the highlight;
- mouse: a click on a row moves the highlight *and* applies it (a pointer has no
  second `enter`), the wheel walks the list, a click outside closes it;
- `/model` groups the agent's models by provider under a reasoning slider
  (`←`/`→`, the crate's six levels) and commits model + level together;
- `/theme` lists the six palettes and previews them as the highlight moves,
  `esc` restores the one the box opened on, only `enter` persists `themeId`;
- `/sessions` switches conversations; `/new` returns to the launchpad with the
  header's own state (connection dot, version) intact.

The theme ids are now the inline catalogue's (`crate::themes::THEME_SPECS`), so
`settings.json` → `themeId` means the same thing in both surfaces; ids older
workbench builds wrote (`future-dark`/`future-light`) still resolve. A typed
`/model` in the draft is a command again, not a prompt sent to the agent, and a
verb with an argument (`/model <id>`) keeps going to the app.

Rows are painted and registered as hit regions from one list and one geometry
(`screen::box_geometry`), which is what makes a click land on the row under the
pointer instead of one beside it.

Behaviour measured against the live agent in tmux at 120×38: 20 models in four
provider groups, a click on `glm-5.3` moved the header and the status bar to
`future/glm-5.3`, `esc` during a theme preview left `themeId` untouched, and
`/new` painted the launchpad with `● future-tui v0.0.2` still in the corner.
The two-providers-one-id case (`future/deepseek-flash` vs
`westlakehpc/deepseek-flash`) ticked two rows until the exact match won over the
id-tail fallback.

Screenshots (`docs/tui/assets/workbench-picker-{model,theme,sessions}.png`) come
from that session, the row chosen with a real SGR mouse click.

Tests: `cargo test -p future-tui workbench` (118), `--lib` (1012), and
`workbench_demo --self-test` (which now also clicks a picker row).
@huichen
huichen enabled auto-merge (squash) October 25, 2026 11:04
@huichen
huichen merged commit 390b02b into main Oct 25, 2026
10 checks passed
@huichen
huichen deleted the pr/huichen branch October 25, 2026 11:17
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