Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

22.9 KB
Raw Blame

Vendored xterm.dart

This directory contains the MIT-licensed xterm 4.0.0 package used by the desktop app. It is pinned in-tree because that release corrupts IndexAwareCircularBuffer ownership when Buffer.scrollUp or Buffer.scrollDown moves line objects through repeated operator []= calls.

The local patch adds an atomic same-length replaceRange operation and uses it for vertical scroll regions. This preserves line identity (and selection anchors) without temporarily storing the same BufferLine in multiple slots. Remove the vendored dependency once the upstream package ships an equivalent fix and the regression in test/terminal_session_test.dart passes against it.

Local patches

  • Single-byte output avoids a code-point list copy (lib/src/utils/byte_consumer.dart). On native runtimes, Latin-1 strings use their immutable code-unit view, whose entries already equal their Unicode code points. Wider text and browser runtimes retain the original rune decoder: mixed queue-list types slowed Unicode parsing in the JavaScript benchmark. Queue positions, rollback, split escape sequences and supplementary characters keep their existing semantics. Regressions: test/terminal_byte_consumer_test.dart, also run in Chrome. Compare an earlier revision with the working tree using python3 tool/benchmark_terminal_parser.py --flutter /path/to/flutter --baseline REVISION --output /tmp/parser-result.json from desktop/. That benchmark measures parsing, not rendering or whole-app energy.

  • OSC 8 hyperlinks are kept per cell (lib/src/core/escape/parser.dart, lib/src/core/cursor.dart, lib/src/core/buffer/line.dart, lib/src/core/buffer/buffer.dart, lib/src/terminal.dart). Upstream drops OSC 8, so a Claude Code markdown link printed as just its label (!125) had no address to open. The target rides on CursorStyle.hyperlink, which SGR resets leave alone, and BufferLine.getHyperlink reads it back; the per-line array is allocated only once a linked cell is written. Regressions: the OSC 8 hyperlinks group in test/terminal_links_test.dart.

  • Pane-local wheel coordinates (lib/src/terminal_view.dart). Convert the pointer's global position to renderer-local coordinates before constructing alternate-screen mouse-wheel reports. Offset panes otherwise report the wrong cell (often clamped to the bottom/right edge), so a TUI can receive a wheel event over its prompt instead of its scrollable content. Regression: test/swarm_terminal_scroll_test.dart checks every four-pane preset, exact emitted coordinates, and normal-buffer history scrolling.

  • Browser accessibility input and editor switching (lib/src/ui/custom_text_edit.dart). The browser's text-input strategy needs an editable semantics node when accessibility is enabled. The custom adapter now publishes its editing value and focus through one such node, while the enclosing Focus omits duplicate semantics. That prevents switching between terminal and remote-viewer editors from deactivating the new DOM editor. Read-only surfaces stay read-only; native input uses its existing path. semanticLabel lets the viewer reuse the IME adapter. Validation includes the native input regressions and desktop/scripts/check-workspace.cjs, which checks actual received terminal bytes and remote viewer input after switching.

  • Linux clipboard and Meta keys leave shell editing intact (lib/src/ui/shortcut/shortcuts.dart, lib/src/terminal_view.dart, lib/src/core/input/handler.dart). Linux uses Ctrl-Shift-C/V/A for clipboard copy/paste/select-all, preserving Ctrl-A and Ctrl-V for the program in the terminal. Left-Alt printable keys send an escape prefix with the actual keyboard-layout character, preserving case and punctuation; AltGr and macOS Option remain native text composition. The fallback letter handler respects Shift and emits lowercase otherwise. Desktop creates Linux-target terminals on Linux. Regressions: test/terminal_clipboard_test.dart, with existing IME coverage in test/terminal_view_interaction_test.dart.

  • Remote grids survive viewport resizing (lib/src/terminal_view.dart, lib/src/ui/render.dart). TerminalView.resizeBuffer defaults to true; Harness sets it to false so a smaller local pane reports its desired size without deleting rows from the captured remote screen. The next remote keyframe supplies the resized grid. Repeated output does not repeat the resize request. Regressions: test/terminal_initial_output_test.dart, including a tall screen with its cursor parked above the newest output, five fresh panes, delayed snapshots, and preserved reading positions on return.

  • On-demand terminal find (lib/src/core/buffer/line.dart, lib/src/terminal.dart). Text mutations advance a local line version so a search can reuse decoded rows; color-only changes keep the version. Optional resize listeners run after buffer reflow without replacing the transport's onResize callback. Search attaches only while visible with a nonempty query. Regressions: test/terminal_search_test.dart, test/terminal_find_test.dart.

  • Host-handled primary clicks (lib/src/terminal_view.dart, lib/src/ui/gesture/gesture_handler.dart). onTapUp was declared but never dispatched by the single-click path. It now runs, and a consuming onTapDown lets Desktop own modifier-clicks without also sending mouse reports to a TUI. Ordinary clicks and drag selection keep their existing behavior. Regressions: test/terminal_link_gesture_test.dart, test/terminal_panel_links_test.dart.

  • Alternate-screen scrolling reaches the program even when its grid is taller than the pane (lib/src/ui/scroll_handler.dart). With resizeBuffer: false the local grid is the remote one, so a remote screen that has not taken this pane's size yet — or that another client keeps larger — leaves the alternate screen a few pixels of local scroll extent. The buffer's Scrollable sits inside TerminalScrollGestureHandler, and a Scrollable with somewhere to go wins the trackpad pan and the wheel signal, so the TUI received nothing and the pane could not be scrolled. While the alternate screen is up that Scrollable now takes no user scrolling; programmatic tail alignment is unaffected, and the normal screen still scrolls local history. Regressions: test/terminal_alt_buffer_scroll_test.dart.

  • The alternate screen's scroll view keeps listening after its position is replaced (lib/src/ui/infinite_scroll_view.dart). attach listens to the ScrollPosition with _onScroll, but the position setter moved markNeedsLayout instead. Scrollable replaces its position whenever its dependencies change — the pane grid reparenting a terminal is enough — so _onScroll stayed on the discarded position and every later wheel or trackpad scroll reached nothing: a Claude Code pane scrolled two or three times and then stopped for good, with no error anywhere. The setter now moves _onScroll. Regression: the reparent test in test/terminal_alt_buffer_scroll_test.dart.

  • A committed IME word stays painted until the terminal echoes it (lib/src/ui/ime_echo_hold.dart, lib/src/terminal_view.dart). Upstream clears the pre-edit preview the moment a composition commits, but a remote terminal echoes it a round trip later — about half a second from a browser through the relay — so a word typed with Telex vanished, and an agent's placeholder reappeared, before the echo brought it back. The commit is now held where the echo will land, the next composition is drawn after it, and each part lets go as the terminal shows it, on Return or another terminal key, or after two seconds. Plain typing never starts a hold, so a prompt that does not echo shows nothing new; a view whose echo never matches stops holding after two expiries. While a preview shows, a prompt's dim placeholder after the cursor ("Ask Codex to do anything", drawn with SGR 2) is painted over with its own background (lib/src/ui/prompt_placeholder.dart, TerminalPainter.paintCellCover), as the program does once the text echoes; a row with any non-dim text after the cursor is left alone. The cursor is drawn after the preview, not on its first cell, where the block hid a lone composing letter (Telex a waits for the next key). Regressions: test/ime_echo_hold_test.dart, test/terminal_view_ime_echo_test.dart, test/prompt_placeholder_test.dart.

Each of these has to survive an upstream bump — the tests named are what catch it if one is dropped.

  1. Atomic replaceRange for scroll regions (the reason this copy exists at all — see above). Regression: test/terminal_session_test.dart.

  2. Backspace is only handed to the native text input client on Apple platforms (lib/src/terminal_view.dart). The key is deliberately not turned into bytes there, so that an IME can use it internally (Telex types ư as u + backspace + ư); macOS returns it as the deleteBackward: selector over TextInputClient.performSelectors. The GTK embedder has no such channel method and names GDK_KEY_BackSpace explicitly to ignore it — correct for an EditableText, wrong for the bare TextInputClient here — so upstream's unconditional version dropped the key entirely on Linux and no byte reached the pty. ⌥⌫ is excluded from the hand-off for the mirror-image reason: AppKit answers it with deleteWordBackward:, a selector CustomTextEdit does not implement, so the chord reached neither the platform nor the pty and deleted nothing at all. It falls through to keyInput, where AltAsMetaInputHandler makes it ESC + \x7f. Regression: the macOS/Linux pair in test/terminal_view_interaction_test.dart, and the ⌥⌫ pane tests in test/terminal_input_test.dart.

  3. A Meta chord is left for the app on every platform, not just Apple (lib/src/terminal_view.dart). Every shortcut in lib/shortcuts/app_shortcuts.dart is declared meta: true, which is Super on Linux; while this was gated on macOS/iOS a focused terminal answered Super+key itself and no app shortcut worked with a pane open. Regression: test/terminal_view_interaction_test.dart.

  4. Erase-left accepts a cursor in the first column (lib/src/core/buffer/line.dart, lib/src/core/buffer/buffer.dart). CSI 1 K at column zero previously passed an empty range to BufferLine.eraseRange, which read cell -1 while checking a wide-character boundary. The range guard now accepts an empty range, and erase-left includes the cursor cell as required by its terminal contract. Regression: test/terminal_session_test.dart.

  5. String sequences (DCS/APC/PM/SOS) are consumed instead of leaking (lib/src/core/escape/parser.dart). ESC P had no handler, so its body was handed to the text path one fragment at a time. tmux wraps passthrough as ESC P tmux; <body> ESC \ and doubles every ESC inside that body, so a program asking the outer terminal for its background colour from inside tmux painted tmux;]11;? into the pane — seen in Claude Code's theme picker. Only ST ends the body: neither the doubled ESC ESC nor an inner OSC's BEL may terminate it, and a body split across two pty chunks rolls back and waits the same way _consumeOsc does. Regression: the two string-sequence tests in test/terminal_session_test.dart.

  6. The selection/highlight rectangle is painted at the render box's own paint offset, not at (0,0) (lib/src/ui/render.dart). _paintHighlights/ _paintSelection/_paintSegment never received the offset paint() is handed — unlike the line-glyph and cursor paints right above them, which both add it — so whenever this box has a non-zero paint offset (the pane's own padding, in this app) the highlighted rectangle was drawn shifted away from the glyphs it was supposed to cover, leaving trailing selected characters rendered outside the box instead of inside it. No regression test (would need a golden/paint-offset test harness this repo doesn't have yet) — verify visually: drag-select text ending near the right edge of a padded pane and confirm the highlight covers every selected glyph.

  7. BufferLine.getText renders a blank cell as a literal space instead of dropping it (lib/src/core/buffer/line.dart). A cell whose stored codePoint is 0 — never written, or erased — was skipped outright rather than emitting anything, so a gap laid out with cursor-forward (CSI C) instead of literal space bytes (the normal way TUI output from Claude Code, Codex, etc. positions text and indentation) copied as nothing: two words glued together with no separator, leading indentation gone. Only the second half of a wide character also stores codePoint 0 and must still be skipped (checked via the preceding cell's width being 2), and only trailing blank cells stay trimmed — a wholly blank line still copies as empty, not as columns of padding. Regression: test/terminal_session_test.dart ('copied text keeps cursor-positioned gaps as spaces...' and the erase-left test, which now expects a leading space where the erased cell is).

  8. Shift+Left/Right reach the TUI in both screen buffers (lib/src/core/input/keytab/keytab_default.dart). The upstream mapping required the alternate screen, so a normal-screen Codex terminal emitted no input for its "shift + left to answer" queued-question shortcut. Both horizontal chords now send the xterm modifier sequence in either buffer; vertical scrolling and app-owned Meta shortcuts keep their bindings. Regression: the macOS/Linux pair in test/terminal_panel_focus_test.dart exercises physical key events through TerminalPanel to binary PTY input.

  9. A software keyboard is allowed to compose (lib/src/ui/custom_text_edit.dart). The strict autocorrect: false / enableSuggestions: false this connection attached with is right for a hardware keyboard — a desktop IME composes through marked text, which neither flag touches — but on a phone those two flags ARE the IME: iOS maps autocorrect onto UITextAutocorrectionTypeNo and Android maps enableSuggestions onto TYPE_TEXT_FLAG_NO_SUGGESTIONS, and with no pre-edit buffer to work in a Vietnamese Telex keyboard converted nothing — hoom reached the pty as four raw letters instead of hôm, and a CJK candidate window never opened. iOS and Android now attach with composition left on (iOS needs autocorrect, the only knob it has; Android needs enableSuggestions and keeps autocorrection itself off), and smart dashes and quotes — which default to ENABLED, and which iOS only acts on once autocorrect is on — are switched off on every platform so " and --flag stay syntax rather than typography. Regression: mobile/test/terminal_ime_input_test.dart, the only build that reaches the mobile branch.

  10. Return does not leave the line it just sent sitting in the prompt (lib/src/ui/custom_text_edit.dart). iOS answers the Return key by calling performAction and then inserting the \n into its own buffer anyway: shouldChangeTextInRange: returns YES for the default return key (FlutterTextInputPlugin.mm). So an editing value the terminal has ALREADY acted on arrives right after the action — by which point resetEditingState has emptied the mirror, so the diff retyped the whole line into the pty and followed it with a literal LF. A TUI reads that as Ctrl+J, a soft newline rather than a submit, so the message the user just sent reappeared in the prompt underneath its own answer. That one value is now recognised by its shape, dropped, and the native buffer put back on the state the action left. It is one shot, so real typing after a submit is never swallowed, and Android performs its editor action without the second insert so nothing there matches. Regression: mobile/test/terminal_ime_input_test.dart.

  11. Block Elements (U+2580–U+259F) are painted as rectangles, not font glyphs (lib/src/ui/block_glyphs.dart, lib/src/ui/painter.dart, lib/src/ui/render.dart, lib/src/terminal_view.dart). A cell is TerminalStyle.height (1.2) times the font size, rounded to whole pixels by SkParagraph (13 pt → 16 px), but a font's block glyphs only cover the face's own ascent and descent — and SF Mono's don't reach the cell's edges horizontally either — so anything drawn with blocks (Claude Code's mascot, progress bars, TUI borders) showed a dark band under every row and seams between columns. paintCellForeground now hands those code points to paintBlockGlyph, which fills the cell's own rectangle(s) with every edge snapped to a device pixel (the view feeds the painter MediaQuery.devicePixelRatioOf) and anti-aliasing off; the snapping is what makes neighbours tile on Impeller, which ignores the flag. The three shade characters are a full cell at 25/50/75 % coverage, and inverse/faint follow the text path. Box drawing (U+2500–U+257F) still comes from the font. Regression: test/terminal_block_glyph_test.dart, which also rasterises through the real painter.

  12. Only lines that changed are drawn again (lib/src/core/buffer/line.dart, lib/src/ui/line_picture_cache.dart, lib/src/ui/painter.dart, lib/src/ui/render.dart). Every frame with output — and every cursor blink, twice a second — drew each visible cell again, one paragraph per glyph, though usually one line had changed. BufferLine.paintVersion now moves whenever anything a line draws changes (colours too, unlike textVersion), but not when a cell is rewritten with the value it already holds, because a TUI redrawing its screen rewrites mostly identical cells. The renderer keeps each visible line's drawing as a Picture keyed by the line object and replays it while the version holds; lines keep their identity as they scroll (patch 1), so streaming output records only the newest line. A line is recorded at its sub-device-pixel phase and replayed moved by whole device pixels, so block-glyph snapping (patch 11) lands exactly where a direct paint would put it even at a fractional pixel ratio. The cache holds only what the last frame drew and is cleared with the theme, font, text scale, pixel ratio, and whenever the view stops rendering. Regression: test/terminal_line_paint_cache_test.dart, including a pixel-for-pixel comparison of replayed and directly painted lines.

  13. A line's backgrounds are filled a run at a time, before its glyphs (lib/src/ui/painter.dart). Neighbouring cells with the same background colour share one rectangle — the same area, one-pixel overlap included — and a single Paint serves them all. Painting every background before any glyph also means a glyph that overhangs its cell (italic, a wide face) now shows over a coloured neighbour just as it always did over the default background, instead of being clipped by that neighbour's fill. Regression: test/terminal_line_paint_cache_test.dart (backgrounds identical to the per-cell fill; glyph edges the only difference).

  14. Plain ASCII in one style is drawn as one paragraph (lib/src/ui/painter.dart). Two or more neighbouring printable-ASCII, single-width cells with the same colours and attributes are laid out and drawn together, with ligatures, contextual alternates and kerning disabled so each glyph keeps its cell. A weight/slant is only batched when every printable ASCII character measures exactly one cell wide in it, so a face whose bold or italic runs wider (or a proportional face) stays cell by cell. Wide characters, non-ASCII, block glyphs and the substituted U+23FA still go through paintCellForeground. Runs of bare spaces draw nothing, as before; underlined spaces become U+00A0 as in the per-cell path. Regression: test/terminal_line_paint_cache_test.dart (where runs are cut, and a rendering within antialiasing of the per-cell one).

  15. deleteDetection keeps its pad (lib/src/ui/custom_text_edit.dart). Upstream seeds the hidden input buffer with two spaces so an on-screen keyboard's Backspace (which sends no key event) still deletes something and is seen, but never puts them back: after two deletes the buffer was empty and every later Backspace changed nothing, so nothing reached the PTY — a pasted [Image #1] at an agent prompt could not be removed on a phone. The pad is restored whenever deletes eat into it. Only reached with deleteDetection: true, which the app sets for touch browsers alone (isTouchBrowser in lib/widgets/terminal_panel.dart). Regression: test/terminal_delete_detection_test.dart.

  16. A browser sends its own Backspace (lib/src/terminal_view.dart). Native macOS/iOS hand a bare Backspace to Apple's text input client, which answers with deleteBackward: (see 15's neighbour in custom_text_edit.dart). Flutter web reports the same platforms — macOS in Chrome on a Mac, iOS on an iPhone — but sends no performSelectors: the browser only deleted from the hidden input, so with nothing typed there a Backspace never reached the PTY. On the web the key now goes to keyInput everywhere. Regression: test/web/terminal_backspace_test.dart (run with --platform=chrome).

  17. Private-use icons are drawn with a symbol face, fitted to the cell (lib/src/ui/painter.dart, lib/src/ui/terminal_text_style.dart). Claude Code and shell prompts print Nerd Font icons from the private-use area as one column, and the stock text faces have none of them, so they showed as empty boxes. TerminalStyle.symbolFontFamily names a face for them (the app bundles Symbols Nerd Font Mono, and leaves it out when the terminal font is a Nerd Font itself). Only the code points that face has (isBundledSymbol) use it; any other private-use character, such as SF Mono's Apple logo at U+F8FF, stays on the text face at its size. An icon is one em wide, wider than the cell, so it is drawn at the size that fits the cell width (measured once the face has loaded; paragraphs laid out before then are dropped), centred, and clipped to its cell. Powerline separators (U+E0B0–U+E0D7) join the coloured cells beside them instead: each is stretched so its ink (powerlineSeparatorInk, read from the bundled face) fills the cell edge to edge and top to bottom. The filled ones (the triangles and thick half circles) are drawn as paths instead (powerlineSeparatorPath): the face puts their corners outside its em, so a corner began half a pixel inside the cell, and Linux's rasteriser left that pixel empty. An underlined icon draws its underline as an underlined U+00A0 in the text face, level with the text beside it. Regression: test/terminal_glyph_presentation_test.dart, which rasterises through the real painter.