Skip to content

Commit f299323

Browse files
committed
Merge remote-tracking branch 'origin/main' into pr-fix/148
# Conflicts: # Makefile # specs/renderer-spec.md # src/clayterm.h # term-native.ts # term.ts # test/width.test.ts
2 parents 23559ee + 9e6f17b commit f299323

41 files changed

Lines changed: 2144 additions & 168 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/pointer-shape-osc22.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@bomb.sh/tty": minor
3+
---
4+
5+
Adds a `cursor` property to `open()`, so the mouse pointer changes shape (OSC 22) as it moves over elements
6+
7+
When the terminal confirms support through the probe (`term.capabilities.pointerShape`), `render()` appends the shape change to `output`, so writing `output` keeps the pointer in sync. The shape resets to `default` when the pointer leaves, when a frame renders without `pointer`, or when `update()` withdraws the capability. `detectTerminal()` also seeds the capability from a known-support table for terminals that set shapes without answering the query (ghostty, kitty, foot, xterm ≥ 367), so those work out of the box. For anything the table misses, assert support with `term.update([{ type: "capability", key: "pointer-shape", value: true }])`.
8+
9+
```ts
10+
term.render([open("link", { cursor: "pointer" }), text("Docs"), close()], { pointer });
11+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
"@bomb.sh/tty": minor
3+
---
4+
5+
Adds synchronized output (DEC mode 2026) driven by the `sync-output` capability.
6+
7+
When `RuntimeCapabilities.syncOutput` is true, every full-screen render is wrapped in Begin/End Synchronized Update (`CSI ? 2026 h` / `CSI ? 2026 l`) so the terminal presents the frame as one atomic repaint without tearing. The capability is raised only on positive evidence, resolved from three channels — a DECRPM 2026 probe reply (`CSI ? 2026 $ p`), an XTGETTCAP `Sync` reply (the terminal's own terminfo-declared synchronization sequence, value discarded in favor of the 2026 form), and detection-time seeding from the `Sync` extended capability in the parsed terminfo entry or the `TMUX` environment variable (tmux consumes mode 2026 from inner applications). Probe replies outrank detection-time evidence in both directions, so a DECRPM 0 or 4 reply turns the capability off even when detection seeded it. Frames render unwrapped when the capability is false or unknown. Zero-diff frames emit nothing whether or not wrapping is active, and line mode is never wrapped.
8+
9+
#### Migration
10+
11+
`Capabilities` gains a required `syncOutput` field. An object literal passed to `createTerm` as `terminfo.capabilities` must include it:
12+
13+
```diff
14+
terminfo: {
15+
capabilities: {
16+
colors: 256,
17+
trueColor: false,
18+
bce: true,
19+
autoMargin: true,
20+
xenl: true,
21+
altScreen: true,
22+
styledUnderline: false,
23+
+ syncOutput: false,
24+
},
25+
}
26+
```

‎.github/workflows/benchmark.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
run: deno install
7474

7575
- name: Upload build artifact
76-
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
76+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
7777
with:
7878
name: bench-build
7979
retention-days: 1
@@ -97,12 +97,12 @@ jobs:
9797
deno-version: v2.x
9898

9999
- name: Setup Node
100-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
100+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
101101
with:
102102
node-version: 24
103103

104104
- name: Download build artifact
105-
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
105+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
106106
with:
107107
name: bench-build
108108

@@ -118,7 +118,7 @@ jobs:
118118
run: deno install
119119

120120
- name: Run walltime benchmarks
121-
uses: CodSpeedHQ/action@c4fd08a3a159bd0cc208da1e0edf32b8c47d75e5 # v5.4.0
121+
uses: CodSpeedHQ/action@f842b9a3ffe213dbb81768fd7f7eeb4dfcf1c369 # v5.4.2
122122
with:
123123
mode: walltime
124124
run: |

‎.github/workflows/preview.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: echo "version=$(git describe --abbrev=0 --tags | sed 's/^v//')-pr+$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
3535

3636
- name: Setup Node
37-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
37+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
3838
with:
3939
node-version: 24
4040

‎.github/workflows/publish.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
deno-version: v2.8.3
4949

5050
- name: setup node
51-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
51+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
5252
with:
5353
node-version: 24
5454
registry-url: "https://registry.npmjs.org"

‎.github/workflows/size-report.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
deno-version: v2.8.3
3434

3535
- name: setup node
36-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v4
36+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v4
3737
with:
3838
node-version: 24
3939

‎.github/workflows/verify.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: deno task test
4848

4949
- name: upload wasm artifact
50-
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
50+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
5151
with:
5252
name: clayterm-wasm
5353
path: |
@@ -83,7 +83,7 @@ jobs:
8383
deno-version: v2.8.3
8484

8585
- name: download wasm artifact
86-
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
86+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
8787
with:
8888
name: clayterm-wasm
8989
path: .
@@ -110,7 +110,7 @@ jobs:
110110
deno-version: v2.8.3
111111

112112
- name: Setup Node
113-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
113+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
114114
with:
115115
node-version: 24
116116

‎AGENTS.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ Do not include any agent marketing material (e.g. "Generated with...",
3333
- The renderer MUST NOT manage terminal state (alternate buffer, mouse
3434
reporting, keyboard protocol modes). Cursor visibility and positioning are
3535
renderer-managed only when a `caret` declaration is present on a `text()`
36-
directive (see renderer-spec.md §7.6).
36+
directive (see renderer-spec.md §7.6). The mouse pointer shape is
37+
renderer-managed only while the `pointerShape` capability is true (see
38+
renderer-spec.md §7.10).
3739

3840
- Each frame is a complete snapshot. The renderer carries no UI tree state
3941
between frames — only cell buffers for diffing.

‎Makefile‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ EXPORTS = \
1515
-Wl,--export=clayterm_size \
1616
-Wl,--export=init \
1717
-Wl,--export=set_capabilities \
18+
-Wl,--export=pointer_shape \
19+
-Wl,--export=set_pointer_shape \
20+
-Wl,--export=pointer_shape \
21+
-Wl,--export=set_pointer_shape \
1822
-Wl,--export=reduce \
1923
-Wl,--export=output \
2024
-Wl,--export=length \
2125
-Wl,--export=measure \
22-
-Wl,--export=Clay_SetPointerState \
2326
-Wl,--export=pointer_over_count \
2427
-Wl,--export=pointer_over_id_string_length \
2528
-Wl,--export=pointer_over_id_string_ptr \

‎debug-terminfo.ts‎

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// debug-terminfo.ts — pinpoint where the terminfo capability chain breaks.
2+
// Run directly in the terminal you are testing, from the repo root:
3+
//
4+
// deno run -A debug-terminfo.ts
5+
// node debug-terminfo.ts
6+
//
7+
// Walks the full chain and reports which link fails: environment identity,
8+
// detection (static Capabilities), the probe round-trip with a per-query
9+
// ✓/✗ breakdown, the parser's CapabilityEvents, and the term's merged
10+
// RuntimeCapabilities. The pointer shape section at the end exercises the
11+
// one capability render() consumes today; if no OSC 22 reply arrives, a
12+
// set-only check flashes the hand cursor so query-less terminals (ghostty)
13+
// can be told apart from terminals without OSC 22 at all.
14+
import { Buffer } from "node:buffer";
15+
import process from "node:process";
16+
import {
17+
type CapabilityEvent,
18+
close,
19+
createInput,
20+
createTerm,
21+
detectTerminal,
22+
open,
23+
text,
24+
} from "./mod.ts";
25+
26+
const decode = new TextDecoder();
27+
const esc = (b: Uint8Array) => JSON.stringify(decode.decode(b)).slice(1, -1);
28+
const json = (v: unknown) => JSON.stringify(v);
29+
30+
console.log("── environment");
31+
console.log(" TERM:", process.env.TERM ?? "(unset)");
32+
console.log(
33+
" TERM_PROGRAM:",
34+
process.env.TERM_PROGRAM ?? "(unset)",
35+
process.env.TERM_PROGRAM_VERSION ?? "",
36+
);
37+
console.log(" COLORTERM:", process.env.COLORTERM ?? "(unset)");
38+
if (process.env.TMUX) {
39+
console.log(" ⚠ running inside tmux — queries may not pass through");
40+
}
41+
42+
const info = await detectTerminal();
43+
console.log("── detection");
44+
console.log(" probe bytes:", info.probe.length);
45+
console.log(" static capabilities:", json(info.capabilities));
46+
47+
if (!process.stdin.isTTY) {
48+
console.log(" ✗ stdin is not a TTY; run this directly in your terminal");
49+
process.exit(1);
50+
}
51+
52+
console.log("── probing (2s window, raw mode on; type nothing)…");
53+
if (typeof process.stdin.setRawMode === "function") {
54+
process.stdin.setRawMode(true);
55+
}
56+
process.stdout.write(info.probe);
57+
58+
const chunks: Buffer[] = [];
59+
const onData = (chunk: Buffer) => chunks.push(chunk);
60+
process.stdin.on("data", onData);
61+
await new Promise((r) => setTimeout(r, 2000));
62+
process.stdin.removeListener("data", onData);
63+
64+
const reply = Buffer.concat(chunks);
65+
console.log("── raw reply");
66+
console.log(" bytes:", reply.length);
67+
console.log(
68+
" escaped:",
69+
reply.length ? esc(reply) : "(nothing — the terminal answered nothing)",
70+
);
71+
72+
console.log("── which queries were answered");
73+
const replyText = decode.decode(reply);
74+
const markers: [string, string][] = [
75+
["foreground (OSC 10)", "\x1b]10;"],
76+
["background (OSC 11)", "\x1b]11;"],
77+
["cursor color (OSC 12)", "\x1b]12;"],
78+
["colors (OSC 21)", "\x1b]21;"],
79+
["POINTER SHAPE (OSC 22)", "\x1b]22;"],
80+
["XTGETTCAP (DCS)", "\x1bP"],
81+
["sync output (DECRPM 2026)", "?2026"],
82+
["kitty keyboard (?u)", "?u"],
83+
["kitty graphics (APC)", "\x1b_G"],
84+
];
85+
for (const [name, marker] of markers) {
86+
console.log(` ${replyText.includes(marker) ? "✓" : "✗"} ${name}`);
87+
}
88+
89+
// The query tells us about reply support, not set support. Ghostty sets
90+
// shapes since 1.0 but never answers the query, so give the terminal a
91+
// chance to show what it can do: set the hand for 1.5s, then restore.
92+
if (!replyText.includes("\x1b]22;")) {
93+
console.log("── set-only check (watch your cursor)");
94+
process.stdout.write("\x1b]22;pointer\x1b\\");
95+
await new Promise((r) => setTimeout(r, 1500));
96+
process.stdout.write("\x1b]22;default\x1b\\");
97+
console.log(
98+
" the cursor should have flashed to a hand just now. If it did," +
99+
" this terminal can SET shapes but never answers the query" +
100+
" (ghostty behaves exactly like this) — detectTerminal()'s" +
101+
" known-support table should already cover it. If it did not" +
102+
" change, OSC 22 is not supported at all.",
103+
);
104+
}
105+
106+
if (typeof process.stdin.setRawMode === "function") {
107+
process.stdin.setRawMode(false);
108+
}
109+
110+
console.log("── parser");
111+
const input = await createInput({ terminfo: info });
112+
let events = input.scan(new Uint8Array(reply)).events;
113+
events = [...events, ...input.scan(new Uint8Array(0)).events];
114+
const caps = events.filter((e): e is CapabilityEvent =>
115+
e.type === "capability"
116+
);
117+
if (caps.length === 0) {
118+
console.log(" (no capability events parsed)");
119+
}
120+
for (const c of caps) {
121+
console.log(` capability: ${c.key} = ${json(c.value)}`);
122+
}
123+
124+
console.log("── term (merged view)");
125+
const term = await createTerm({ width: 40, height: 6, terminfo: info });
126+
term.update(caps);
127+
console.log(" merged capabilities:", json(term.capabilities));
128+
const staticCaps = info.capabilities as unknown as Record<string, unknown>;
129+
const mergedCaps = term.capabilities as unknown as Record<string, unknown>;
130+
const raised = Object.keys(mergedCaps).filter((k) =>
131+
json(mergedCaps[k]) !== json(staticCaps[k])
132+
);
133+
console.log(
134+
" raised by the probe:",
135+
raised.length > 0 ? raised.join(", ") : "(nothing — probe added no evidence)",
136+
);
137+
138+
// Pointer shape is the one capability render() consumes today, so it doubles
139+
// as the end-to-end emission check.
140+
console.log("── pointer shape (renderer-spec §7.10)");
141+
const result = term.render(
142+
[open("box", { cursor: "pointer" }), text("hover"), close()],
143+
{ pointer: { x: 2, y: 2, down: false } },
144+
);
145+
const emitted = decode
146+
.decode(result.output)
147+
.includes("\x1b]22;pointer\x1b\\");
148+
console.log(" OSC 22 in render output:", emitted);
149+
150+
console.log("── verdict");
151+
if (emitted) {
152+
console.log(
153+
" ✓ render emits OSC 22" +
154+
(info.capabilities.pointerShape && !replyText.includes("\x1b]22;")
155+
? " — statically granted by the known-support table (no query reply," +
156+
" which is expected for set-only terminals like ghostty)"
157+
: " — the probe confirmed support and the parser folded it in") +
158+
". If the demos still show nothing, hover a key/button — and note the" +
159+
" shape only changes while the pointer is over an element that" +
160+
" declares one.",
161+
);
162+
} else if (!replyText.includes("\x1b]22;")) {
163+
console.log(
164+
info.capabilities.pointerShape
165+
? " ✗ no OSC 22 reply and no emission despite a static grant — please" +
166+
" report this with the escaped reply above."
167+
: " ✗ your terminal did not answer the OSC 22 query and it is not on" +
168+
" the known-support table. If the set-only check above moved your" +
169+
" cursor, it can set shapes but we cannot detect it — run the demos" +
170+
" with TTY_POINTER_SHAPES=1 (or nominate the terminal for the" +
171+
" table). If the cursor never changed, OSC 22 is not supported at" +
172+
" all (iTerm2, Terminal.app, VS Code, tmux without passthrough).",
173+
);
174+
} else if (caps.length === 0) {
175+
console.log(
176+
" ✗ the terminal replied but the parser produced no capability events." +
177+
" Please report this with the escaped reply above.",
178+
);
179+
} else {
180+
console.log(
181+
" ✗ capability recognized but render did not emit OSC 22. Please report" +
182+
" this with the escaped reply above.",
183+
);
184+
}
185+
process.exit(0);

0 commit comments

Comments
 (0)