Files
pipelines/app/third_party/xterm
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
..

xterm (vendored)

This is our maintained copy of xterm.dart, vendored from the pub.dev release 4.0.0 (MIT, see LICENSE; the upstream README is kept as UPSTREAM_README.md). Upstream is unmaintained, so the app depends on this directory through a path dependency and we patch it here.

The commit that added this directory is the pristine upstream copy; every later change is a local patch. Review them with git log -p -- app/third_party/xterm.

Tests for the patches live in the app tree, app/test/third_party_xterm/, so they run under the memory watchdog with the rest of the app tests. The app's analysis_options.yaml excludes this directory from its strict lints; the code still compiles as part of every app build.

Local patches (keep this list current):

  • CSI parsing: colon subparameters (4:3, 38:2::r:g:b, 58/59), intermediates and private prefixes (CSI > 4;2 m is not SGR), empty parameters as defaults; SGR 21 is double underline, 53/55 overline
  • 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; 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 (onWorkingDirectoryChange)
  • alternate screen 1049 restores the cursor; arrow keys follow DECCKM
  • mouse: wheel 64/65, screen-cell coordinates, drag (1002) and motion (1003) reporting, middle button, Shift+drag selects (ui/mouse_listener.dart)
  • 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)
  • Unicode: cell widths follow glibc wcwidth on Unicode 16 tables (utils/unicode_width.dart, generated utils/unicode_tables.dart by tool/gen_unicode_tables.py); grapheme clusters (combining marks, variation selectors, emoji ZWJ sequences, skin tones, flags, Hangul jamo) join the previous cell (core/buffer/grapheme_join.dart) and are stored interned (core/buffer/graphemes.dart, CellContent.clusterFlag), drawn whole and copied whole; U+FE0F and flags take two columns; a wide character never starts in the last column
  • rendering: box drawing, block elements and Powerline separators drawn as geometry filling the cell (ui/cell_glyphs.dart); whole-pixel row height; one paragraph per line for plain text with a span per style (ui/text_runs.dart), backgrounds merged per colour; a picture per line reused until the line changes (ui/row_pictures.dart, BufferLine.version); glyphs wider than their cells scaled to fit; TerminalStyle and TerminalTheme compare by value