Terminal: find field takes the keyboard; docs, capture kit right-click

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 00:52:19 +00:00
parent e65354496a
commit 9ab7f50cce
7 changed files with 101 additions and 3 deletions
@@ -38,6 +38,11 @@ mixin ChatShellTerminalFindHost<T extends StatefulWidget> on State<T> {
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() {
+63
View File
@@ -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=<target>`.
## Protocol (server)
`internal/protocol/terminal.go`; documented in `docs/cli.md` ("Machine
@@ -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<TextField>(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');
+8 -1
View File
@@ -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)
+1
View File
@@ -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=<target>` | click the secondary mouse button on the target (context menus), then wait |
| `hover=<target>` | move the mouse onto the target without pressing (hover states) |
| `drag=<target>>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 |
+7
View File
@@ -25,6 +25,7 @@ steps: open=<route>[@WxH] wait=<ms> shot=<name> click=<target> waitfor=<target
type=<text> press=<Enter|Escape|Tab|...> scroll=<dy> size=WxH
files=<path>[,<path>] (answers the next file chooser)
film=<target> labels=<name> tabs=<name> eval=<js> expect=<js> hover=<target>
rightclick=<target> (secondary button: context menus)
drag=<target>><dx>,<dy> (JSON: drag, dx, dy, steps, gap, hold)
swipe=<target>><dx>,<dy> pinch=<target>><scale> (with --touch true)
target: <label> | label:<label> | key:<semantics identifier> | x,y`;
@@ -113,6 +114,12 @@ try {
await delay(step.wait ?? settle);
break;
}
case 'rightclick': {
const hit = await page.rightClick(value, step.timeout);
log(` right-clicked ${describe(parseTarget(value))} at ${Math.round(hit.x)},${Math.round(hit.y)}`);
await delay(step.wait ?? settle);
break;
}
case 'waitfor': await page.waitFor(value, step.timeout ?? 10000); break;
case 'files': await page.armFiles(String(value).split(',').map((p) => resolve(p))); break;
case 'type': await page.type(String(value)); await delay(step.wait ?? settle); break;
+11 -2
View File
@@ -121,6 +121,14 @@ export function flutterPage(browser, log, { touch = false } = {}) {
await tap(point);
return point;
},
/** Clicks the secondary (right) mouse button on [target] (context menus). */
async rightClick(target, timeout) {
const { x, y } = await locate(target, timeout);
await send('Input.dispatchMouseEvent', { type: 'mouseMoved', x, y });
await send('Input.dispatchMouseEvent', { type: 'mousePressed', x, y, button: 'right', buttons: 2, clickCount: 1 });
await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x, y, button: 'right', buttons: 0, clickCount: 1 });
return { x, y };
},
waitFor: (target, timeout) => locate(target, timeout),
/** Answers the next file chooser the page opens with [paths] (absolute). */
async armFiles(paths) {
@@ -148,9 +156,10 @@ export function flutterPage(browser, log, { touch = false } = {}) {
const key = parts.pop();
const bits = { Alt: 1, Control: 2, Meta: 4, Shift: 8 };
const modifiers = parts.reduce((m, p) => m | (bits[p] ?? 0), 0);
const codes = { Enter: 13, Escape: 27, Tab: 9, Backspace: 8, ArrowDown: 40, ArrowUp: 38, ArrowLeft: 37, ArrowRight: 39, "/": 191 };
const codes = { Enter: 13, Escape: 27, Tab: 9, Backspace: 8, ArrowDown: 40, ArrowUp: 38, ArrowLeft: 37, ArrowRight: 39, "/": 191, '=': 187, '-': 189 };
const digit = /^\d$/.test(key);
const code = key === '/' ? 'Slash' : digit ? `Digit${key}` : /^[a-z]$/i.test(key) ? `Key${key.toUpperCase()}` : key;
const named = { '/': 'Slash', '=': 'Equal', '-': 'Minus' };
const code = named[key] ? named[key] : digit ? `Digit${key}` : /^[a-z]$/i.test(key) ? `Key${key.toUpperCase()}` : key;
const vk = codes[key] ?? (key.length === 1 ? key.toUpperCase().charCodeAt(0) : 0);
const text = key === 'Enter' ? '\r' : key.length === 1 && !modifiers ? key : undefined;
const base = { key, code, windowsVirtualKeyCode: vk, modifiers, text };