Skip to content

Give a pty embed's program the clipboard, cursor color, cell size and clusters - #195

Open
brainkim wants to merge 5 commits into
mainfrom
fix/pty-embed-protocol
Open

brainkim wants to merge 5 commits into
mainfrom
fix/pty-embed-protocol

Conversation

@brainkim

Copy link
Copy Markdown
Member

A TermDOM page run as the program of an <embed type="application/x-pty">, as each Parkour tab is, asks its terminal for things the embed's emulator did not answer. This closes those gaps, with no new option, export or event.

What the program can now do:

  • Clipboard (OSC 52): a write goes to the terminal's clipboard and a query is answered from it, while the embed is visible and the page has an interactive terminal. Only the clipboard selection, and at most 1 MiB.
  • Cursor colour (OSC 12 and 112): sets, queries and resets it, and the caret the page draws for the embed takes the colour.
  • Cell and window size in pixels (CSI 14 t, 16 t, 18 t): answered once the page has measured its own cell.
  • Title stack (CSI 22 t and 23 t): pushes and pops the title, ten deep.
  • Grapheme clusters (mode 2027): reported and settable, and with it on a cluster takes the width the page's own measure gives it.

The images and canvas guide gains a "What the program can do" section.

One decision for review. The clipboard passes straight through: a program in an embed can write the user's clipboard and read it. That is what a real terminal gives a program, and an embed only runs with ptyEmbeds: "auto", but it removed OSC 52 from the test "nothing a program writes reaches the terminal but its screen". The alternative is an event on the embed that the page answers.

Known gap: a string starting with U+0600 still measures differently from the page's own width.

Tests: new cases in tests/vt.test.ts and tests/embed-pty.test.ts; the Ghostty and xterm.js oracle ignores the 2027 report. This touches src/internal/pty.ts and tests/embed-pty.test.ts, as #193 does, and merges with it cleanly.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig

brainkim and others added 5 commits November 11, 2026 15:22
… clusters

A TermDOM page run as an embed's program, as a Parkour tab is, asked its
terminal for things the embed did not answer, and wrote things it
dropped:

OSC 52 was dropped, so a copy in the program went nowhere. The text now
goes to the clipboard of the page's terminal, and a program that asks
for the clipboard hears what that terminal answers. An OSC 52 may be a
megabyte, where other OSCs stop at 4096 characters, and one longer is
dropped whole.

OSC 12 and 112 set and reset the cursor's color, which the terminal's
cursor takes while the embed has focus, as it takes the shape.

CSI 16 t and 14 t report a cell and the screen in pixels once the page's
terminal has measured a cell. Before that the embed stays silent, and
the program guesses as the page does.

Mode 2027 is the program's to set and ask after. Under it characters
join into grapheme clusters as wide as TermDOM measures them, so a page
in the program need not probe for where a keycap or a Devanagari
conjunct left the cursor. Without it they join as before.

XTWINOPS 22 and 23 put the title away and bring it back.

Co-Authored-By: Claude <noreply@anthropic.com>
The terminal's answer can land after the first frame, and on Deno the
embed was asked for a cell's pixels before it had them.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant