From 9ab7f50cceb34a67bec2434219c189d6b3b02d32 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 26 Nov 2026 00:52:19 +0000 Subject: [PATCH] Terminal: find field takes the keyboard; docs, capture kit right-click Co-Authored-By: Claude Opus 5.5 --- .../shell/chat_shell_terminal_find_host.dart | 5 ++ app/notes/terminal-panel.md | 63 +++++++++++++++++++ .../shell/chat_shell_terminal_find_test.dart | 6 ++ app/third_party/xterm/README.md | 9 ++- app/tool/capture/README.md | 1 + app/tool/capture/capture.mjs | 7 +++ app/tool/capture/page.mjs | 13 +++- 7 files changed, 101 insertions(+), 3 deletions(-) diff --git a/app/lib/features/chat/shell/chat_shell_terminal_find_host.dart b/app/lib/features/chat/shell/chat_shell_terminal_find_host.dart index 474ac7cc..7198bd61 100644 --- a/app/lib/features/chat/shell/chat_shell_terminal_find_host.dart +++ b/app/lib/features/chat/shell/chat_shell_terminal_find_host.dart @@ -38,6 +38,11 @@ mixin ChatShellTerminalFindHost on State { current: scheme.tertiary.withValues(alpha: 0.6), ); }); + // The field's autofocus would not take the keyboard from the terminal, + // which holds it in the same scope. + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted && _find != null) _findFocus.requestFocus(); + }); } void _closeFind() { diff --git a/app/notes/terminal-panel.md b/app/notes/terminal-panel.md index 47f4ca9b..fa15b4c5 100644 --- a/app/notes/terminal-panel.md +++ b/app/notes/terminal-panel.md @@ -109,6 +109,69 @@ tmux inside it for work that must survive that). terminal is opened): each connection sends one request at a time, so the first screen's read is never queued behind `terminal_list`. +## View features (round 2, 2026-11-26) + +Shared by the permanent terminal and chat terminal cards +(`ChatShellTerminalView`); client-side only, no server change. The view's +own keys are answered before the key→byte mapping +(`chatShellLocalKey`, `chat_shell_terminal_shortcuts.dart`): + +- **Find in scrollback:** Cmd+F (Apple) / Ctrl+Shift+F (elsewhere; Ctrl+F + stays the shell's forward-char) opens a find bar over the terminal's top + end, or focuses it. Typing searches the whole buffer, wrapped rows joined + (`chat_shell_terminal_search.dart`, at most 1000 matches, "1000+"); every + match is highlighted (controller highlights, the emulator's existing + hook) and the current one more strongly, scrolled into view. It starts + at the newest match; Enter / the down arrow is next, Shift+Enter / up is + previous, wrapping; **Aa** toggles Match case; Esc or × closes it and + gives the terminal the keyboard back. Output arriving meanwhile marks + the result stale; the next step searches again. +- **Text size:** Cmd (Apple) / Ctrl with `=`/`+` and `-` zoom one point, + with `0` back to the default; Settings → Appearance → Terminal → Text size + too. Saved with the layout (`font_size`, 8–32). The view relays out at + the new cell size, so the PTY is resized through the normal resize path. + Note Ctrl+- is readline's undo (`^_`) in xterm; here it zooms. +- **Scrollback:** Settings → Scrollback (1k, 5k, 10k default, 25k, 50k, + 100k lines; saved as `scrollback`). It applies at once to open terminals + (`Terminal.maxLines` is settable; shrinking drops the oldest lines). +- **Scrolling keys:** on the main screen Shift+PgUp / Shift+PgDn scroll one + screen (keeping a line), Shift+Home / Shift+End to the top / bottom, + locally. On the alternate screen (less, vim) they reach the program. +- **Context menu:** a right-click offers Copy (with a selection), Paste + (live terminals), Select all (scrollback included), Clear scrollback + (this view's copy; the server keeps the output) and Find…. A program + that tracks the mouse gets the right button instead, unless Shift is + held. On the web the browser's own menu is suppressed while the pointer + is over the terminal (`ChatShellNoBrowserMenu`, the chat links' + `suppressBrowserMenuOverLink`). +- **Bell:** BEL flashes the terminal's border in the accent colour + (300 ms fade; held then gone under reduced motion). A bell while no view + shows the terminal (another tab selected, or the terminal hidden) dots + its tab until it is shown. Settings → Visual bell turns both off. +- **Links:** hovering an OSC 8 hyperlink (by its target, `hyperlinkAt`) or + a printed http(s) address shows a pointer cursor and underlines the + link's cells; a click opens it as before. +- **OSC 52:** a program setting the clipboard copies to the system + clipboard and shows "Copied from terminal" (reads are never answered). + **OSC 7:** the reported folder names an untitled tab and its tooltip. + A replay (reload, reconnect) of old output neither copies nor rings. +- **Cursor blink:** a blinking DECSCUSR shape (odd Ps) blinks (530 ms + phases) on a ticker that runs only while the terminal is focused and + motion is not reduced; output or typing shows it again at once. +- **Stale selection:** a selection clears when its rows on screen are + rewritten or erased, the screen is cleared, its lines drop out of the + scrollback, or the program switches screens. + +Evidence: tests `test/features/chat/shell/chat_shell_terminal_{find, +local_keys,menu,events,feedback}_test.dart`, `test/features/terminal/ +terminal_tab_events_test.dart`, `test/features/settings/ +settings_terminal_controls_test.dart`, `test/third_party_xterm/ +scrollback_blink_test.dart`. Chrome captures (capture kit, `?terminals=1 +&terminal=panel`, 1200x800): find bar with "2 of 2" PASS highlights, +context menu, Ctrl+= zoom, OSC 8 link hover underline; a synthetic +`contextmenu` event over the terminal is default-prevented, elsewhere not. +The capture kit gained `rightclick=`. + ## Protocol (server) `internal/protocol/terminal.go`; documented in `docs/cli.md` ("Machine diff --git a/app/test/features/chat/shell/chat_shell_terminal_find_test.dart b/app/test/features/chat/shell/chat_shell_terminal_find_test.dart index f04eb205..d3282745 100644 --- a/app/test/features/chat/shell/chat_shell_terminal_find_test.dart +++ b/app/test/features/chat/shell/chat_shell_terminal_find_test.dart @@ -68,6 +68,12 @@ void main() { await harness.focus(tester); await _openFind(tester); expect(find.byKey(_field), findsOneWidget); + await tester.pump(); + // The field has the keyboard, which the terminal held. + expect( + tester.widget(find.byKey(_field)).focusNode!.hasFocus, + isTrue, + ); // The keys went to the find bar, not the shell. expect(harness.typed, isEmpty); await tester.enterText(find.byKey(_field), 'needle'); diff --git a/app/third_party/xterm/README.md b/app/third_party/xterm/README.md index fa2ffc63..83e2e235 100644 --- a/app/third_party/xterm/README.md +++ b/app/third_party/xterm/README.md @@ -21,7 +21,7 @@ Local patches (keep this list current): - DCS/APC/PM/SOS strings consumed rather than printed; DECRQSS (`m`, `r`, ` q`) answered - RIS (`ESC c`) full reset and DECSTR (`CSI ! p`) -- DECSCUSR cursor shapes (blinking is stored, not animated); SCOSC/SCORC, +- DECSCUSR cursor shapes (blinking is stored; the host animates it); SCOSC/SCORC, CHT, CBT, HPA, HPR, VPR; HTS sets tab stops; DSR 6 one-based - OSC 10/11/12 colour queries from the view's theme; OSC 8 links on cells (`Terminal.hyperlinkAt`); OSC 52 set (`onClipboardSet`, no reads); OSC 7 @@ -33,3 +33,10 @@ Local patches (keep this list current): - rendering: block cursor shows the character inverted, underline/bar cursor position, strikethrough, conceal, overline, underline styles - focus reporting (`?1004`, `Terminal.focusInput`, called by `TerminalView`) +- `Terminal.maxLines` is settable (`Buffer.setMaxLines`): a smaller value + drops the oldest scrollback at once; `IndexAwareCircularBuffer.trimStart` + detaches the dropped lines and keeps the others' indexes (it left them + attached and off by the trimmed count, so `clearScrollback` broke anchors) +- `TerminalView.cursorBlinkVisible`: the host animates a blinking cursor; + while false the render object skips the cursor (the painter is unchanged) +- `RenderTerminal` is exported from `ui.dart` (cell geometry for hosts) diff --git a/app/tool/capture/README.md b/app/tool/capture/README.md index 7a9609de..19b648cf 100644 --- a/app/tool/capture/README.md +++ b/app/tool/capture/README.md @@ -55,6 +55,7 @@ In JSON, a step can also set `wait` (ms), `timeout`, `name`, `ms` and `frames`. | `type=text` | type into the focused field (or the first visible one) | | `press=Enter` | press a key: Enter, Escape, Tab, Backspace, ArrowUp, ArrowDown, a letter or a digit, optionally after `Control+`, `Shift+`, `Alt+` or `Meta+` (`press=Control+2`) | | `scroll=600` | scroll with the mouse wheel at the centre (JSON `at` sets a target, `dx` a horizontal delta, `repeat` and `gap` a run of ticks) | +| `rightclick=` | click the secondary mouse button on the target (context menus), then wait | | `hover=` | move the mouse onto the target without pressing (hover states) | | `drag=>dx,dy` | press on the target, move by dx,dy in `steps` (12) moves `gap` (16) ms apart, release (JSON `dx`, `dy`, `steps`, `gap`; `hold: true` keeps the button down to capture mid-drag) | | `size=WxH` | resize without reloading | diff --git a/app/tool/capture/capture.mjs b/app/tool/capture/capture.mjs index 4624e305..29ebcaf4 100644 --- a/app/tool/capture/capture.mjs +++ b/app/tool/capture/capture.mjs @@ -25,6 +25,7 @@ steps: open=[@WxH] wait= shot= click= waitfor= press= scroll= size=WxH files=[,] (answers the next file chooser) film= labels= tabs= eval= expect= hover= + rightclick= (secondary button: context menus) drag=>, (JSON: drag, dx, dy, steps, gap, hold) swipe=>, pinch=> (with --touch true) target: