Terminal: xterm key encoding, no live reflow on resize, Alt+T/Ctrl+T reach the shell

- Live terminals no longer reflow (xterm.dart 4.0.0 left the cursor on the
  wrong row); narrowing cuts and erases cells past the width, rows scroll
  into scrollback keeping the cursor row; finished output still reflows.
- App-side key encoding before xterm.dart's defaults: Alt as Meta (ESC +
  the typed character), Ctrl symbol table, xterm modifier parameter for
  arrows/Home/End/PgUp/PgDn/Ins/Del/F-keys, DECCKM and DECKPAM, Alt+BS.
- Settings > Appearance > Terminal: Use Option as Meta key (Macs, on).
- Inside a focused terminal only Cmd+T and Ctrl+` toggle it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 23:32:29 +00:00
parent 5ab1ec9e00
commit 7d1ffe8ad3
22 changed files with 1408 additions and 61 deletions
+35 -4
View File
@@ -28,7 +28,30 @@ emulator. Auth flows that print a link, wait for a pasted token and continue
Android/iOS the toolbar also has a text field ("Type input, then Enter")
for the soft keyboard, with a Hide typing toggle; it is emptied when sent.
- The terminal is resized to its layout (debounced 150 ms); the process gets
SIGWINCH. New runs start at the last laid-out size.
SIGWINCH. New runs start at the last laid-out size. A live terminal does
not reflow (xterm.dart's reflow left the cursor on another line's row, so
prompts landed on old output and rows merged): narrowing cuts rows at the
new width (the cut cells are erased, so widening never brings stale text
back), fewer rows drop blank rows below the cursor and then scroll the top
into scrollback with the cursor's row at the bottom, more rows bring
scrollback back above it. Finished output still reflows to its card.
- **Keys** (`chat_shell_terminal_{input,key_input,keymap}.dart`): the view
encodes hardware keys before xterm.dart does, with the event's real
character, and a `TerminalInputHandler` chained before the package's
defaults encodes `keyInput` calls (key toolbar, soft keyboard) the same
way. Alt is Meta (ESC + the character, Shift and layout included; Macs:
the Option as Meta setting, the key's own character instead of Option's
symbol). Ctrl maps letters and `@ 2 Space`→NUL, `[ 3`→ESC, `\ 4`→0x1c,
`] 5`→0x1d, `^ 6`→0x1e, `_ / - 7`→0x1f, `? 8`→DEL. Arrows, Home/End,
Insert/Delete, PgUp/PgDn and F1–F12 carry xterm's modifier parameter
(1 + Shift 1 + Alt 2 + Ctrl 4: Shift+Up `CSI 1;2A`, Alt+Left `CSI 1;3D`,
Ctrl+Shift+Right `CSI 1;6C`, Ctrl+PgDn `CSI 6;5~`, Shift+F1 `CSI 1;2P`);
unmodified arrows and Home/End are SS3 under DECCKM. With DECKPAM the
keypad's Enter and operators send SS3 (`ESC O M`, `k`, `m`, `j`, `o`);
keypad digits keep typing (NumLock on). Alt+Backspace is `ESC DEL`,
Ctrl+Backspace `^H`, Shift+Tab `CSI Z`, Alt+Enter `ESC CR`. Ctrl+Alt
typing a composed symbol outside Apple platforms (AltGr) types it.
Cmd (Meta key) chords and plain typing are left to the emulator.
- Printed `http(s)` links open in the browser on tap (wrapped links are
joined). Other schemes are ignored.
- Finished runs are drawn read-only, shrunk to the rows their output takes
@@ -92,8 +115,16 @@ emulator. Auth flows that print a link, wait for a pasted token and continue
position) for a live run, so two open clients send two answers.
xterm.dart 4.0.0 answers DSR 6 zero-based; the app overrides it to the
correct one-based answer.
- xterm.dart 4.0.0 keeps blank rows when it rewraps; the app drops blank rows
below the cursor after a resize so the top of the output stays in view.
- xterm.dart 4.0.0 keeps blank rows when it rewraps; for finished output
(the only output that reflows) the app drops blank rows below the cursor
after a resize so the top of the output stays in view.
- A live terminal's long lines are cut, not rewrapped, when it narrows, and
stay cut when it widens again (as xterm without reflow).
- Key encoding gaps: no modifyOtherKeys / CSI u (Ctrl+Shift+letter sends the
plain control code, Ctrl+1/9/0 type the digit); Alt as Meta on Linux
assumes AltGr arrives as Ctrl+Alt or its own key; a Mac's Option as Meta
takes the character from the logical key, else the US position of the
physical key, so a non-US Mac layout's Option+key may send the US letter.
- Desktop typing uses key events (no IME composition for CJK input). Touch
platforms use the field.
- A descendant that keeps the PTY open after the command exits is read for
@@ -110,7 +141,7 @@ emulator. Auth flows that print a link, wait for a pasted token and continue
`chat_shell_plain.go`, `chat_shell_runner.go`, `chat_shell_supervise.go`,
`chat_shell_run_handlers.go`, `chat_shell_share.go`, `chat.go`,
`websocket.go`; `internal/pipeline/chat_shell_runs.go`; `go.mod`, `go.sum`.
- App: `lib/features/chat/shell/chat_shell_terminal_{session,view,keys,theme,links,page}.dart`,
- App: `lib/features/chat/shell/chat_shell_terminal_{session,view,keys,theme,links,page,input,key_input,keymap}.dart`,
`chat_shell_terminals.dart`, `chat_shell_output_view.dart`,
`chat_shell_run{,_card}.dart`, `chat_shell_card_actions.dart`,
`chat_shell_runs_{controller,repository}.dart`, `chat_shell_metrics.dart`;