Commit Graph

18 Commits

Author SHA1 Message Date
alan f7ef4d1445 Terminal emulator: faster write path (ASCII runs, reused lines, no per-char allocation)
- Parser reads the written strings directly (no rune list per write) and
  handles printable ASCII runs and C0 controls straight from the string;
  a run is written into the line in one call (Buffer.writeAscii,
  BufferLine.setAsciiCells), as writeChar would one by one.
- A line leaving a full scrollback (or a one-line region scroll) is
  cleared and reused instead of allocating a 4 KiB line; lines with
  anchors (selection ends) still leave detached. Lines track the cells
  written since made or cleared, so a clear touches only those.
- Grapheme join rejects characters that cannot join before reading the
  cell (it built a String per character); width table covers plane 1.
- Switch dispatch for C0 controls, direct calls for CSI and SGR (torn-off
  handlers are slow in JavaScript); CSI params emptied without clear();
  circular buffer index without %; insert keeps the start index wrapped.
- Terminal.write(notify: false) lets a host notify once per frame.
- tool/perf/terminal_parse_bench.dart: parse throughput in the VM or V8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 02:34:08 +00:00
alan e526150b1e Merge branch 'worktree-agent-a9a25296deadb0eaa'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 01:15:53 +00:00
alan 018d37f103 Terminal: grapheme-aware widths, drawn box/Powerline glyphs, line pictures
Emulator (vendored xterm):
- Widths follow glibc wcwidth on generated Unicode 16 tables
  (tool/gen_unicode_tables.py); combining marks, variation selectors,
  ZWJ sequences, skin tones, flags and Hangul jamo join the previous cell,
  stored as interned clusters (CellContent.clusterFlag) and drawn and
  copied whole. U+FE0F and flags take two columns, as modern terminals
  do; a wide character never starts in the last column.
- Box drawing, block elements and Powerline separators are drawn as
  geometry filling the cell; rows are whole pixels high.
- Backgrounds merge per colour; each line is a picture reused until the
  line changes (BufferLine.version); a line drawn unchanged settles into
  one laid out paragraph with a span per style. TerminalStyle and
  TerminalTheme compare by value.

App: bundled Symbols Nerd Font Mono subset (568 KiB, MIT) as the
terminal's first fallback, loaded on first use; line height 1.1;
?terminalUnicode=1 fixture showcase; bench gains a progress workload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 01:14:48 +00:00
alan 9ab7f50cce Terminal: find field takes the keyboard; docs, capture kit right-click
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 00:52:19 +00:00
alan 6832ec789e Terminal: find, zoom, scrollback, scroll keys, context menu, bell, link hover, OSC 52/7, cursor blink, stale selection
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 00:33:53 +00:00
alan fea34941d3 xterm: answer DSR 6 one-based; list the local patches
The cursor position report sent zero-based coordinates (the app's
terminal session overrides it with the same fix, which keeps working).
The vendored README now lists every local patch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:39:00 +00:00
alan 2bcb62b5d8 xterm: draw strikethrough, concealed text, overline and underline styles
SGR 9 (strikethrough) and 53 (overline) were stored but never drawn, and
SGR 8 (conceal) still showed the text. They are drawn now, and underline
styles use the matching line style: double (21, 4:2), curly (4:3, wavy),
dotted (4:4) and dashed (4:5). Concealed cells keep their background.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:38:35 +00:00
alan 822d77b1df xterm: report focus changes (?1004)
Terminal.focusInput sends CSI I / CSI O while the program has enabled
focus reporting, and TerminalView calls it when its focus node gains or
loses focus (not for read-only views). The mode was parsed but never
acted on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:37:09 +00:00
alan 9b90806093 xterm: fix mouse wheel, drag, motion and middle-button reporting
- Wheel buttons were encoded as 68/69 (64 + 4/5, i.e. Shift + wheel down/
  wheel right); they are 64 up and 65 down.
- Wheel, click and drag positions use the view's own screen cell: the
  wheel used the window position, and clicks used the buffer row
  (counting scrollback) instead of the screen row. Default encoding sent
  the row one too high.
- A new TerminalMouseListener reports mouse presses, releases, drags
  (1002) and motion (1003, also without a button) from pointer events,
  with Ctrl/Alt modifiers. Before, a drag became a text selection and
  motion was never sent. Holding Shift at the press leaves the pointer to
  selection while the program owns the mouse.
- The middle button's press and release were reported as the right
  button. SGR releases name the released button.
- With mouse tracking on, the wheel is reported on the main screen too.
- TerminalController reports every pointer input kind by default; the
  program's mouse mode decides what is sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:36:32 +00:00
alan 8f758bc721 xterm: answer OSC 10/11/12 queries; OSC 8 links, OSC 52 and OSC 7
OSC 10/11/12 ; ? is answered with rgb:rrrr/gggg/bbbb from the view's theme
(RenderTerminal reports it through Terminal.setReportedColors), terminated
like the query (BEL or ST). OSC 8 hyperlinks are stored on the cells (a
16-bit id in the attributes; Terminal.hyperlinkAt), survive SGR resets and
end with an empty URI. OSC 52 sets reach Terminal.onClipboardSet decoded;
clipboard reads are not supported. OSC 7 reaches onWorkingDirectoryChange.

OSC bodies keep their semicolons (titles, URIs), and an OSC cut short by
another escape no longer swallows that escape's first byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:32:21 +00:00
alan bbb2d112ed xterm: DECSCUSR cursor shapes; block cursor shows the character
CSI Ps SP q is stored as Terminal.cursorShape / cursorShapeBlinks (Ps 0
returns to the view's configured cursorType; RIS clears it) and reported
by DECRQSS " q". The painter draws the requested shape. A focused block
cursor now redraws the character under it in the background colour
instead of hiding it, spans both columns of a wide character, and the
underline and bar cursors are drawn in the cursor's cell (they were drawn
at the top of the terminal).

Blinking is stored but not animated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:30:10 +00:00
alan 31d00e057c xterm: implement RIS (ESC c) and DECSTR (CSI ! p)
ESC c was ignored, so `reset` could not recover a terminal left in the
alternate screen with a hidden cursor, a scroll region or mouse modes.
RIS now resets every mode, the attributes, character sets, tab stops,
margins and saved cursors, returns to the main screen and clears it
(scrollback is kept, as in xterm). DECSTR resets modes, attributes and
margins without touching the text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:27:50 +00:00
alan 30b32921fe xterm: restore the cursor leaving 1049; arrow keys follow DECCKM
Resetting mode 1049 switched back to the main screen without restoring the
cursor saved when it was set. The keytab input handler read application
cursor keys from the keypad mode (DECKPAM) instead of DECCKM (CSI ?1 h/l);
Terminal.cursorKeysMode is the mode to read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:26:47 +00:00
alan 326e7710d4 xterm: add SCOSC/SCORC, CHT, CBT, HPA, HPR and VPR; fix HTS
CSI s / CSI u save and restore the cursor (without parameters; prefixed
forms such as the kitty keyboard query CSI ? u are left alone). CSI I and
CSI Z move by tab stops, CSI ` sets the column, CSI a and CSI e move
relative. ESC H (HTS) set no tab stop because it called isSetAt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:26:18 +00:00
alan 7592aa1a82 xterm: consume DCS, SOS, PM and APC strings; answer DECRQSS
ESC P, ESC X, ESC ^ and ESC _ now open a control string whose body is
swallowed up to ST (ESC \), across writes; CAN/SUB or a non-ST ESC abort
it. Previously the bodies were printed (nvim's DECRQSS ESC P $qm ESC \
showed as "$qm"). DECRQSS m and r are answered with DCS 1 $ r ... ST,
other requests with DCS 0 $ r ST. ESC ESC restarts the escape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:25:14 +00:00
alan e94f4856e3 xterm: parse colon subparameters, intermediates and empty CSI params
CSI parameters now record colon subparameters (ITU T.416), so SGR 4:3 is a
curly underline instead of 4 and 3 = 43 (yellow background), and
38:2::r:g:b, 38:2:r:g:b and 38:5:n set colours. Underline styles 4:0-4:5
and 21 (double) are stored on the cell; 58/59 underline colours are
consumed and ignored; 53/55 toggle overline; 22 clears bold and faint;
truncated 38;5 no longer throws.

Intermediate bytes and private prefixes are kept, so CSI > 4;2 m
(modifyOtherKeys) is no longer applied as SGR. An empty parameter reads as
0 (default), so CSI ;5H and CSI 3H position the cursor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:23:47 +00:00
alan 5b47db180f Depend on the vendored xterm through a path dependency
The app now builds against app/third_party/xterm instead of the pub.dev
4.0.0 release. The vendored package is excluded from the app's lints; its
README records the upstream version and that we patch it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:20:08 +00:00
alan a6e04895ba Vendor pristine xterm.dart 4.0.0 under app/third_party/xterm
Unmodified copy of lib/, LICENSE (MIT), pubspec.yaml and CHANGELOG.md from
pub.dev xterm 4.0.0; the upstream README is kept as UPSTREAM_README.md.
Committed on its own so later patches are reviewable as diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:17:41 +00:00