@gkoreli/ghostty-vt-js 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +89 -0
- package/THIRD_PARTY_NOTICES.md +45 -0
- package/dist/browser-terminal/buffer.d.ts +93 -0
- package/dist/browser-terminal/buffer.d.ts.map +1 -0
- package/dist/browser-terminal/buffer.js +337 -0
- package/dist/browser-terminal/buffer.js.map +1 -0
- package/dist/browser-terminal/encoding.d.ts +17 -0
- package/dist/browser-terminal/encoding.d.ts.map +1 -0
- package/dist/browser-terminal/encoding.js +22 -0
- package/dist/browser-terminal/encoding.js.map +1 -0
- package/dist/browser-terminal/event-emitter.d.ts +8 -0
- package/dist/browser-terminal/event-emitter.d.ts.map +1 -0
- package/dist/browser-terminal/event-emitter.js +27 -0
- package/dist/browser-terminal/event-emitter.js.map +1 -0
- package/dist/browser-terminal/frame-hold.d.ts +13 -0
- package/dist/browser-terminal/frame-hold.d.ts.map +1 -0
- package/dist/browser-terminal/frame-hold.js +17 -0
- package/dist/browser-terminal/frame-hold.js.map +1 -0
- package/dist/browser-terminal/geometry.d.ts +229 -0
- package/dist/browser-terminal/geometry.d.ts.map +1 -0
- package/dist/browser-terminal/geometry.js +299 -0
- package/dist/browser-terminal/geometry.js.map +1 -0
- package/dist/browser-terminal/ghostty.d.ts +478 -0
- package/dist/browser-terminal/ghostty.d.ts.map +1 -0
- package/dist/browser-terminal/ghostty.js +1212 -0
- package/dist/browser-terminal/ghostty.js.map +1 -0
- package/dist/browser-terminal/gpu/adapter.d.ts +70 -0
- package/dist/browser-terminal/gpu/adapter.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/adapter.js +260 -0
- package/dist/browser-terminal/gpu/adapter.js.map +1 -0
- package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.d.ts +33 -0
- package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.js +159 -0
- package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.js.map +1 -0
- package/dist/browser-terminal/gpu/core/context-loss-watchdog.d.ts +35 -0
- package/dist/browser-terminal/gpu/core/context-loss-watchdog.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/context-loss-watchdog.js +73 -0
- package/dist/browser-terminal/gpu/core/context-loss-watchdog.js.map +1 -0
- package/dist/browser-terminal/gpu/core/frame.d.ts +68 -0
- package/dist/browser-terminal/gpu/core/frame.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/frame.js +167 -0
- package/dist/browser-terminal/gpu/core/frame.js.map +1 -0
- package/dist/browser-terminal/gpu/core/glyph-atlas.d.ts +136 -0
- package/dist/browser-terminal/gpu/core/glyph-atlas.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/glyph-atlas.js +281 -0
- package/dist/browser-terminal/gpu/core/glyph-atlas.js.map +1 -0
- package/dist/browser-terminal/gpu/core/procedural-shapes.d.ts +24 -0
- package/dist/browser-terminal/gpu/core/procedural-shapes.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/procedural-shapes.js +316 -0
- package/dist/browser-terminal/gpu/core/procedural-shapes.js.map +1 -0
- package/dist/browser-terminal/gpu/core/webgl2-renderer.d.ts +107 -0
- package/dist/browser-terminal/gpu/core/webgl2-renderer.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/core/webgl2-renderer.js +698 -0
- package/dist/browser-terminal/gpu/core/webgl2-renderer.js.map +1 -0
- package/dist/browser-terminal/gpu/create-renderer.d.ts +15 -0
- package/dist/browser-terminal/gpu/create-renderer.d.ts.map +1 -0
- package/dist/browser-terminal/gpu/create-renderer.js +33 -0
- package/dist/browser-terminal/gpu/create-renderer.js.map +1 -0
- package/dist/browser-terminal/index.d.ts +47 -0
- package/dist/browser-terminal/index.d.ts.map +1 -0
- package/dist/browser-terminal/index.js +75 -0
- package/dist/browser-terminal/index.js.map +1 -0
- package/dist/browser-terminal/input-handler.d.ts +262 -0
- package/dist/browser-terminal/input-handler.d.ts.map +1 -0
- package/dist/browser-terminal/input-handler.js +978 -0
- package/dist/browser-terminal/input-handler.js.map +1 -0
- package/dist/browser-terminal/interfaces.d.ts +230 -0
- package/dist/browser-terminal/interfaces.d.ts.map +1 -0
- package/dist/browser-terminal/interfaces.js +5 -0
- package/dist/browser-terminal/interfaces.js.map +1 -0
- package/dist/browser-terminal/link-detector.d.ts +76 -0
- package/dist/browser-terminal/link-detector.d.ts.map +1 -0
- package/dist/browser-terminal/link-detector.js +165 -0
- package/dist/browser-terminal/link-detector.js.map +1 -0
- package/dist/browser-terminal/providers/osc8-link-provider.d.ts +56 -0
- package/dist/browser-terminal/providers/osc8-link-provider.d.ts.map +1 -0
- package/dist/browser-terminal/providers/osc8-link-provider.js +204 -0
- package/dist/browser-terminal/providers/osc8-link-provider.js.map +1 -0
- package/dist/browser-terminal/providers/url-regex-provider.d.ts +68 -0
- package/dist/browser-terminal/providers/url-regex-provider.d.ts.map +1 -0
- package/dist/browser-terminal/providers/url-regex-provider.js +107 -0
- package/dist/browser-terminal/providers/url-regex-provider.js.map +1 -0
- package/dist/browser-terminal/renderer-interface.d.ts +59 -0
- package/dist/browser-terminal/renderer-interface.d.ts.map +1 -0
- package/dist/browser-terminal/renderer-interface.js +2 -0
- package/dist/browser-terminal/renderer-interface.js.map +1 -0
- package/dist/browser-terminal/renderer.d.ts +254 -0
- package/dist/browser-terminal/renderer.d.ts.map +1 -0
- package/dist/browser-terminal/renderer.js +905 -0
- package/dist/browser-terminal/renderer.js.map +1 -0
- package/dist/browser-terminal/scrollbar-overlay.d.ts +45 -0
- package/dist/browser-terminal/scrollbar-overlay.d.ts.map +1 -0
- package/dist/browser-terminal/scrollbar-overlay.js +89 -0
- package/dist/browser-terminal/scrollbar-overlay.js.map +1 -0
- package/dist/browser-terminal/selection-manager.d.ts +180 -0
- package/dist/browser-terminal/selection-manager.d.ts.map +1 -0
- package/dist/browser-terminal/selection-manager.js +913 -0
- package/dist/browser-terminal/selection-manager.js.map +1 -0
- package/dist/browser-terminal/terminal.d.ts +423 -0
- package/dist/browser-terminal/terminal.d.ts.map +1 -0
- package/dist/browser-terminal/terminal.js +1754 -0
- package/dist/browser-terminal/terminal.js.map +1 -0
- package/dist/browser-terminal/types.d.ts +595 -0
- package/dist/browser-terminal/types.d.ts.map +1 -0
- package/dist/browser-terminal/types.js +467 -0
- package/dist/browser-terminal/types.js.map +1 -0
- package/dist/browser-terminal/viewport-scroller.d.ts +94 -0
- package/dist/browser-terminal/viewport-scroller.d.ts.map +1 -0
- package/dist/browser-terminal/viewport-scroller.js +159 -0
- package/dist/browser-terminal/viewport-scroller.js.map +1 -0
- package/dist/browser-terminal/vt/effects.d.ts +114 -0
- package/dist/browser-terminal/vt/effects.d.ts.map +1 -0
- package/dist/browser-terminal/vt/effects.js +143 -0
- package/dist/browser-terminal/vt/effects.js.map +1 -0
- package/dist/browser-terminal/vt/enums.d.ts +155 -0
- package/dist/browser-terminal/vt/enums.d.ts.map +1 -0
- package/dist/browser-terminal/vt/enums.js +161 -0
- package/dist/browser-terminal/vt/enums.js.map +1 -0
- package/dist/browser-terminal/vt/mouse.d.ts +166 -0
- package/dist/browser-terminal/vt/mouse.d.ts.map +1 -0
- package/dist/browser-terminal/vt/mouse.js +259 -0
- package/dist/browser-terminal/vt/mouse.js.map +1 -0
- package/dist/browser-terminal/vt/paste.d.ts +53 -0
- package/dist/browser-terminal/vt/paste.d.ts.map +1 -0
- package/dist/browser-terminal/vt/paste.js +89 -0
- package/dist/browser-terminal/vt/paste.js.map +1 -0
- package/dist/browser-terminal/vt/render-state.d.ts +208 -0
- package/dist/browser-terminal/vt/render-state.d.ts.map +1 -0
- package/dist/browser-terminal/vt/render-state.js +776 -0
- package/dist/browser-terminal/vt/render-state.js.map +1 -0
- package/dist/browser-terminal/vt/style.d.ts +54 -0
- package/dist/browser-terminal/vt/style.d.ts.map +1 -0
- package/dist/browser-terminal/vt/style.js +92 -0
- package/dist/browser-terminal/vt/style.js.map +1 -0
- package/dist/browser-terminal/wasm-loader.d.ts +39 -0
- package/dist/browser-terminal/wasm-loader.d.ts.map +1 -0
- package/dist/browser-terminal/wasm-loader.js +73 -0
- package/dist/browser-terminal/wasm-loader.js.map +1 -0
- package/dist/browser-terminal/write-buffer.d.ts +40 -0
- package/dist/browser-terminal/write-buffer.d.ts.map +1 -0
- package/dist/browser-terminal/write-buffer.js +144 -0
- package/dist/browser-terminal/write-buffer.js.map +1 -0
- package/dist/protocol/index.d.ts +135 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +76 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/react/index.d.ts +59 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +146 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.d.ts +130 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +191 -0
- package/dist/server/index.js.map +1 -0
- package/dist/terminal-screen-emulator/emulator.d.ts +66 -0
- package/dist/terminal-screen-emulator/emulator.d.ts.map +1 -0
- package/dist/terminal-screen-emulator/emulator.js +286 -0
- package/dist/terminal-screen-emulator/emulator.js.map +1 -0
- package/dist/terminal-screen-emulator/index.d.ts +82 -0
- package/dist/terminal-screen-emulator/index.d.ts.map +1 -0
- package/dist/terminal-screen-emulator/index.js +92 -0
- package/dist/terminal-screen-emulator/index.js.map +1 -0
- package/dist/terminal-screen-emulator/types.d.ts +382 -0
- package/dist/terminal-screen-emulator/types.d.ts.map +1 -0
- package/dist/terminal-screen-emulator/types.js +91 -0
- package/dist/terminal-screen-emulator/types.js.map +1 -0
- package/dist/terminal-screen-emulator/wasm-loader.d.ts +71 -0
- package/dist/terminal-screen-emulator/wasm-loader.d.ts.map +1 -0
- package/dist/terminal-screen-emulator/wasm-loader.js +162 -0
- package/dist/terminal-screen-emulator/wasm-loader.js.map +1 -0
- package/dist/themes/index.d.ts +6 -0
- package/dist/themes/index.d.ts.map +1 -0
- package/dist/themes/index.js +51 -0
- package/dist/themes/index.js.map +1 -0
- package/dist/wasm/alloc.d.ts +170 -0
- package/dist/wasm/alloc.d.ts.map +1 -0
- package/dist/wasm/alloc.js +307 -0
- package/dist/wasm/alloc.js.map +1 -0
- package/dist/wasm/compile.d.ts +73 -0
- package/dist/wasm/compile.d.ts.map +1 -0
- package/dist/wasm/compile.js +82 -0
- package/dist/wasm/compile.js.map +1 -0
- package/dist/wasm/exports.d.ts +234 -0
- package/dist/wasm/exports.d.ts.map +1 -0
- package/dist/wasm/exports.js +15 -0
- package/dist/wasm/exports.js.map +1 -0
- package/dist/wasm/fn-table.d.ts +119 -0
- package/dist/wasm/fn-table.d.ts.map +1 -0
- package/dist/wasm/fn-table.js +168 -0
- package/dist/wasm/fn-table.js.map +1 -0
- package/dist/wasm/memory.d.ts +59 -0
- package/dist/wasm/memory.d.ts.map +1 -0
- package/dist/wasm/memory.js +89 -0
- package/dist/wasm/memory.js.map +1 -0
- package/dist/wasm/type-layouts.d.ts +61 -0
- package/dist/wasm/type-layouts.d.ts.map +1 -0
- package/dist/wasm/type-layouts.js +32 -0
- package/dist/wasm/type-layouts.js.map +1 -0
- package/package.json +94 -0
- package/wasm/ghostty-vt.wasm +0 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ViewportScroller — scrollback viewport position + smooth-scroll animation.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `terminal.ts` (which had grown monolithic) as the owner of
|
|
5
|
+
* one cohesive piece of state: **where the viewport is** in the scrollback
|
|
6
|
+
* buffer, and how it animates between positions.
|
|
7
|
+
*
|
|
8
|
+
* ## Coordinate model
|
|
9
|
+
*
|
|
10
|
+
* `y` counts lines *up* from the live screen: `0` = at bottom (following
|
|
11
|
+
* output), `scrollbackLength` = at the very top of history. It can be
|
|
12
|
+
* fractional mid-animation — consumers that index buffers must
|
|
13
|
+
* `Math.floor()` it (the renderer and hit-testing already do).
|
|
14
|
+
*
|
|
15
|
+
* ## Smooth scrolling
|
|
16
|
+
*
|
|
17
|
+
* Asymptotic ease-out (move a fixed fraction of the remaining distance per
|
|
18
|
+
* frame), matching the feel of native terminal scrolling. Re-targeting while
|
|
19
|
+
* an animation is in flight does NOT restart it — the running animation
|
|
20
|
+
* simply steers toward the new target, which is what makes continuous wheel
|
|
21
|
+
* input feel smooth instead of choppy.
|
|
22
|
+
*
|
|
23
|
+
* ## Write anchoring
|
|
24
|
+
*
|
|
25
|
+
* When new output pushes lines into scrollback while the user is scrolled
|
|
26
|
+
* up, the viewport must shift by the same delta or the content they're
|
|
27
|
+
* reading visually jumps. `shiftAnchor()` applies that correction to the
|
|
28
|
+
* position AND any in-flight animation's target/origin (otherwise the
|
|
29
|
+
* animation would unwind the correction and snap to the bottom). See
|
|
30
|
+
* coder/ghostty-web#150 for the original bug this fixes.
|
|
31
|
+
*/
|
|
32
|
+
export class ViewportScroller {
|
|
33
|
+
deps;
|
|
34
|
+
/** Viewport position in lines above the live screen. Fractional during animation. */
|
|
35
|
+
_y = 0;
|
|
36
|
+
targetY = 0;
|
|
37
|
+
animationStartTime;
|
|
38
|
+
animationFrame;
|
|
39
|
+
constructor(deps) {
|
|
40
|
+
this.deps = deps;
|
|
41
|
+
}
|
|
42
|
+
/** Current position (fractional mid-animation — floor before indexing buffers). */
|
|
43
|
+
get y() {
|
|
44
|
+
return this._y;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The position scrolling is heading toward: the animation target while one
|
|
48
|
+
* is in flight, else the current position. Wheel input accumulates against
|
|
49
|
+
* this (not `y`) so successive wheel ticks compound instead of fighting
|
|
50
|
+
* the animation.
|
|
51
|
+
*/
|
|
52
|
+
get currentTarget() {
|
|
53
|
+
return this.animationFrame !== undefined ? this.targetY : this._y;
|
|
54
|
+
}
|
|
55
|
+
/** Scroll by lines (positive = down toward live output, negative = up into history). */
|
|
56
|
+
scrollLines(amount) {
|
|
57
|
+
const maxScroll = this.deps.getScrollbackLength();
|
|
58
|
+
const newY = Math.max(0, Math.min(maxScroll, this._y - amount));
|
|
59
|
+
this.jumpTo(newY, maxScroll > 0);
|
|
60
|
+
}
|
|
61
|
+
/** Scroll by pages (one page = visible rows). */
|
|
62
|
+
scrollPages(amount) {
|
|
63
|
+
this.scrollLines(amount * this.deps.getRows());
|
|
64
|
+
}
|
|
65
|
+
scrollToTop() {
|
|
66
|
+
const maxScroll = this.deps.getScrollbackLength();
|
|
67
|
+
if (maxScroll > 0)
|
|
68
|
+
this.jumpTo(maxScroll, true);
|
|
69
|
+
}
|
|
70
|
+
scrollToBottom() {
|
|
71
|
+
this.jumpTo(0, this.deps.getScrollbackLength() > 0);
|
|
72
|
+
}
|
|
73
|
+
/** Jump to an absolute line (0 = bottom, scrollbackLength = top), clamped. */
|
|
74
|
+
scrollToLine(line) {
|
|
75
|
+
const maxScroll = this.deps.getScrollbackLength();
|
|
76
|
+
this.jumpTo(Math.max(0, Math.min(maxScroll, line)), maxScroll > 0);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Animate toward `targetY` (clamped). Respects the host's smooth-scroll
|
|
80
|
+
* duration; 0 jumps. Retargeting mid-flight steers the running animation.
|
|
81
|
+
*/
|
|
82
|
+
smoothScrollTo(targetY) {
|
|
83
|
+
const maxScroll = this.deps.getScrollbackLength();
|
|
84
|
+
const newTarget = Math.max(0, Math.min(maxScroll, targetY));
|
|
85
|
+
if (this.deps.getSmoothScrollDuration() === 0) {
|
|
86
|
+
this.targetY = newTarget;
|
|
87
|
+
this.jumpTo(newTarget, maxScroll > 0, /* force */ true);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.targetY = newTarget;
|
|
91
|
+
if (this.animationFrame !== undefined)
|
|
92
|
+
return; // steer, don't restart
|
|
93
|
+
this.animationStartTime = Date.now();
|
|
94
|
+
this.animate();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Shift position (and any in-flight animation anchors) after new output
|
|
98
|
+
* grew the scrollback while scrolled up — keeps the content the user is
|
|
99
|
+
* reading visually stable. No-op when `delta <= 0`.
|
|
100
|
+
*/
|
|
101
|
+
shiftAnchor(delta) {
|
|
102
|
+
if (delta <= 0 || this._y === 0)
|
|
103
|
+
return;
|
|
104
|
+
const maxScroll = this.deps.getScrollbackLength();
|
|
105
|
+
this._y = Math.min(maxScroll, this._y + delta);
|
|
106
|
+
if (this.animationFrame !== undefined) {
|
|
107
|
+
this.targetY = Math.min(maxScroll, this.targetY + delta);
|
|
108
|
+
}
|
|
109
|
+
this.deps.onScroll(Math.floor(this._y));
|
|
110
|
+
}
|
|
111
|
+
/** True when the viewport is scrolled up into history. */
|
|
112
|
+
get scrolledUp() {
|
|
113
|
+
return this._y !== 0;
|
|
114
|
+
}
|
|
115
|
+
/** Cancel any in-flight animation (dispose / teardown path). */
|
|
116
|
+
cancelAnimation() {
|
|
117
|
+
if (this.animationFrame !== undefined) {
|
|
118
|
+
cancelAnimationFrame(this.animationFrame);
|
|
119
|
+
this.animationFrame = undefined;
|
|
120
|
+
}
|
|
121
|
+
this.animationStartTime = undefined;
|
|
122
|
+
}
|
|
123
|
+
jumpTo(newY, showScrollbar, force = false) {
|
|
124
|
+
if (newY === this._y && !force)
|
|
125
|
+
return;
|
|
126
|
+
this._y = newY;
|
|
127
|
+
this.deps.onScroll(Math.floor(this._y));
|
|
128
|
+
if (showScrollbar)
|
|
129
|
+
this.deps.showScrollbar();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Asymptotic ease-out: move `1 - (1/frames)^2` of the remaining distance
|
|
133
|
+
* each frame, snapping when within 0.01 lines. Duration is honored
|
|
134
|
+
* approximately (frame-rate dependent), which is fine for a feel-driven
|
|
135
|
+
* animation.
|
|
136
|
+
*/
|
|
137
|
+
animate = () => {
|
|
138
|
+
if (this.animationStartTime === undefined)
|
|
139
|
+
return;
|
|
140
|
+
const distance = this.targetY - this._y;
|
|
141
|
+
if (Math.abs(distance) < 0.01) {
|
|
142
|
+
this._y = this.targetY;
|
|
143
|
+
this.deps.onScroll(Math.floor(this._y));
|
|
144
|
+
if (this.deps.getScrollbackLength() > 0)
|
|
145
|
+
this.deps.showScrollbar();
|
|
146
|
+
this.animationFrame = undefined;
|
|
147
|
+
this.animationStartTime = undefined;
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const framesForDuration = (this.deps.getSmoothScrollDuration() / 1000) * 60;
|
|
151
|
+
const moveRatio = 1 - (1 / framesForDuration) ** 2;
|
|
152
|
+
this._y += distance * moveRatio;
|
|
153
|
+
this.deps.onScroll(Math.floor(this._y));
|
|
154
|
+
if (this.deps.getScrollbackLength() > 0)
|
|
155
|
+
this.deps.showScrollbar();
|
|
156
|
+
this.animationFrame = requestAnimationFrame(this.animate);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=viewport-scroller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewport-scroller.js","sourceRoot":"","sources":["../../src/browser-terminal/viewport-scroller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAgBH,MAAM,OAAO,gBAAgB;IAOE;IAN7B,qFAAqF;IAC7E,EAAE,GAAG,CAAC,CAAC;IACP,OAAO,GAAG,CAAC,CAAC;IACZ,kBAAkB,CAAU;IAC5B,cAAc,CAAU;IAEhC,YAA6B,IAA0B;QAA1B,SAAI,GAAJ,IAAI,CAAsB;IAAG,CAAC;IAE3D,mFAAmF;IACnF,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;IACpE,CAAC;IAED,wFAAwF;IACxF,WAAW,CAAC,MAAc;QACxB,MAAM,SAAS,GAAG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E,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,EAAE,IAAI,QAAQ,GAAG,SAAS,CAAC;QAEhC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAEnE,IAAI,CAAC,cAAc,GAAG,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC,CAAC;CACH"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VT effect callbacks — `GHOSTTY_TERMINAL_OPT_*` (terminal.h:60-95, 399-595).
|
|
3
|
+
*
|
|
4
|
+
* Effects are how libghostty-vt delivers everything that is not pure grid
|
|
5
|
+
* state: query responses (DSR / DA / XTVERSION / XTWINOPS), BEL, title
|
|
6
|
+
* changes, and more. Without effects installed, the engine *generates* query
|
|
7
|
+
* responses and silently drops them — which is why shells and TUIs that probe
|
|
8
|
+
* the terminal (e.g. `ESC[6n` cursor position) hang against an effect-less
|
|
9
|
+
* embedder.
|
|
10
|
+
*
|
|
11
|
+
* Installation uses the synthetic-module function-table trick — see
|
|
12
|
+
* `../../wasm/fn-table.ts` for the mechanism and its rules. No fork of
|
|
13
|
+
* `vendor/ghostty`, no `WebAssembly.Function`, works in stable Chrome / Node /
|
|
14
|
+
* Bun today (verified 2026-07-24 on Node 22.22 and Bun 1.3.14).
|
|
15
|
+
*
|
|
16
|
+
* # Effect callback contract (from `terminal.h`, enforced by convention here)
|
|
17
|
+
*
|
|
18
|
+
* These are the rules every handler passed to {@link installEffects} MUST
|
|
19
|
+
* follow. They are load-bearing; violations produce hangs, traps, or corrupted
|
|
20
|
+
* parses, not error messages.
|
|
21
|
+
*
|
|
22
|
+
* 1. **Callbacks fire synchronously *inside* `ghostty_terminal_vt_write`.**
|
|
23
|
+
* The engine is mid-parse when your handler runs.
|
|
24
|
+
* 2. **Never re-enter the terminal.** A handler must not call `vt_write` (or
|
|
25
|
+
* anything that leads to it — `Terminal.write()` included) on the same
|
|
26
|
+
* terminal. `terminal.h`: "Callbacks must not call ghostty_terminal_vt_write
|
|
27
|
+
* on the same terminal (no reentrancy)." Route data *outward* (events,
|
|
28
|
+
* sockets) and let inbound data come back through the write queue
|
|
29
|
+
* (`../write-buffer.ts`), which makes accidental re-entry structurally
|
|
30
|
+
* impossible at the public-API layer.
|
|
31
|
+
* 3. **Be cheap.** Callbacks block further IO processing (`terminal.h`).
|
|
32
|
+
* Firing an event emitter or `WebSocket.send` (buffered, non-blocking) is
|
|
33
|
+
* fine — this matches xterm.js, whose parser fires `onData` for query
|
|
34
|
+
* responses synchronously mid-parse (`InputHandler` → `triggerDataEvent`).
|
|
35
|
+
* Doing layout, awaiting, or heavy allocation is not.
|
|
36
|
+
* 4. **Callback arguments are borrowed.** The `data` pointer passed to
|
|
37
|
+
* `write_pty` points into WASM scratch memory that is only valid for the
|
|
38
|
+
* duration of the call. This module copies the bytes out *before*
|
|
39
|
+
* dispatching to your handler — handlers receive an owned copy.
|
|
40
|
+
* 5. **Responses flow to the PTY, not back into the parser.** `write_pty`
|
|
41
|
+
* bytes are the terminal answering a query; they belong to the *process*
|
|
42
|
+
* side (for example: `onData` → WebSocket → server-side PTY). This mirrors
|
|
43
|
+
* Ghostty's own reference embedder (`vendor/ghostty/example/c-vt-effects`),
|
|
44
|
+
* which forwards them straight to the pty fd.
|
|
45
|
+
*
|
|
46
|
+
* # Extension path (deliberately not implemented yet)
|
|
47
|
+
*
|
|
48
|
+
* `ENQUIRY` / `XTVERSION` / `SIZE` / `COLOR_SCHEME` / `DEVICE_ATTRIBUTES` /
|
|
49
|
+
* `CLIPBOARD_WRITE` (OSC 52) are
|
|
50
|
+
* *value-producing* effects: the callback returns `bool`/`GhosttyString` and
|
|
51
|
+
* fills an out-struct, and the engine encodes the response itself. Wiring them
|
|
52
|
+
* follows the same pattern as below plus struct writes via `type-layouts.ts`
|
|
53
|
+
* offsets. Add them one at a time with a test each; the DA1 feature set is a
|
|
54
|
+
* product decision (which capabilities we advertise), not just plumbing.
|
|
55
|
+
* Note: plain DSR (`ESC[6n` / `ESC[5n`) needs none of them — those responses
|
|
56
|
+
* arrive fully-encoded through `WRITE_PTY`.
|
|
57
|
+
*/
|
|
58
|
+
import type { GhosttyWasmExports } from "../../wasm/exports.js";
|
|
59
|
+
/**
|
|
60
|
+
* Handlers for the supported effects. All optional — only the effects you
|
|
61
|
+
* provide are registered; the rest stay disabled (engine default).
|
|
62
|
+
*/
|
|
63
|
+
export interface EffectHandlers {
|
|
64
|
+
/**
|
|
65
|
+
* Query responses to forward to the PTY (rule 5). `data` is an owned copy
|
|
66
|
+
* (rule 4). Typical wiring: decode and fire the terminal's `onData` event.
|
|
67
|
+
*/
|
|
68
|
+
onWritePty?(data: Uint8Array): void;
|
|
69
|
+
/** BEL (0x07) processed by the parser — real bells only, no byte-sniffing. */
|
|
70
|
+
onBell?(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Title changed via OSC 0 / OSC 2. The new title is NOT passed by the
|
|
73
|
+
* engine — read it with `ghostty_terminal_get(TITLE)` (borrowed string;
|
|
74
|
+
* copy before the next write). `ghostty_terminal_get` is a read, not a
|
|
75
|
+
* parse — safe to call from inside the callback (Ghostty's own effects
|
|
76
|
+
* example does exactly this).
|
|
77
|
+
*/
|
|
78
|
+
onTitleChanged?(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Pwd changed via OSC 7 / OSC 9;9 / OSC 1337. Same read-on-signal shape as
|
|
81
|
+
* {@link onTitleChanged}: the engine passes nothing — read the new value
|
|
82
|
+
* with `ghostty_terminal_get(PWD)`. Also fires when the shell *clears* the
|
|
83
|
+
* pwd (empty OSC 7), in which case the getter returns "". The value is a
|
|
84
|
+
* raw `file://` URI per `terminal.h` — decode scheme/host if you care.
|
|
85
|
+
* Available since vendor/ghostty@002fd4142 (our 2026-07 submodule bump).
|
|
86
|
+
*/
|
|
87
|
+
onPwdChanged?(): void;
|
|
88
|
+
}
|
|
89
|
+
/** Handle to installed effects. Dispose BEFORE freeing the terminal. */
|
|
90
|
+
export interface InstalledEffects {
|
|
91
|
+
/**
|
|
92
|
+
* Unregister the callbacks (`ghostty_terminal_set(term, OPT, 0)`) and
|
|
93
|
+
* recycle their table slots. Idempotent. Must run before
|
|
94
|
+
* `ghostty_terminal_free` — a freed terminal handle must never be passed
|
|
95
|
+
* back to `terminal_set` (fn-table.ts rule 3 covers the slot side).
|
|
96
|
+
*/
|
|
97
|
+
dispose(): void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Install effect callbacks on a terminal.
|
|
101
|
+
*
|
|
102
|
+
* Mirrors `ghostty_terminal_set(term, GHOSTTY_TERMINAL_OPT_<EFFECT>, fn)` for
|
|
103
|
+
* each provided handler. The `void* value` of `terminal_set` for callback
|
|
104
|
+
* options IS the function pointer itself (verified against
|
|
105
|
+
* `vendor/ghostty/src/terminal/c/terminal.zig` `setTyped`), i.e. our table
|
|
106
|
+
* index.
|
|
107
|
+
*
|
|
108
|
+
* @param exports - The WASM instance the terminal lives in.
|
|
109
|
+
* @param terminalHandle - The `GhosttyTerminal` handle (`Terminal.handle`).
|
|
110
|
+
* @param handlers - Effect handlers. See {@link EffectHandlers} and the
|
|
111
|
+
* contract in the file header.
|
|
112
|
+
*/
|
|
113
|
+
export declare function installEffects(exports: GhosttyWasmExports, terminalHandle: number, handlers: EffectHandlers): InstalledEffects;
|
|
114
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../../src/browser-terminal/vt/effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAGhE;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,UAAU,CAAC,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,8EAA8E;IAC9E,MAAM,CAAC,IAAI,IAAI,CAAC;IAChB;;;;;;OAMG;IACH,cAAc,CAAC,IAAI,IAAI,CAAC;IACxB;;;;;;;OAOG;IACH,YAAY,CAAC,IAAI,IAAI,CAAC;CACvB;AAED,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAcD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,kBAAkB,EAC3B,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,cAAc,GACvB,gBAAgB,CAkElB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VT effect callbacks — `GHOSTTY_TERMINAL_OPT_*` (terminal.h:60-95, 399-595).
|
|
3
|
+
*
|
|
4
|
+
* Effects are how libghostty-vt delivers everything that is not pure grid
|
|
5
|
+
* state: query responses (DSR / DA / XTVERSION / XTWINOPS), BEL, title
|
|
6
|
+
* changes, and more. Without effects installed, the engine *generates* query
|
|
7
|
+
* responses and silently drops them — which is why shells and TUIs that probe
|
|
8
|
+
* the terminal (e.g. `ESC[6n` cursor position) hang against an effect-less
|
|
9
|
+
* embedder.
|
|
10
|
+
*
|
|
11
|
+
* Installation uses the synthetic-module function-table trick — see
|
|
12
|
+
* `../../wasm/fn-table.ts` for the mechanism and its rules. No fork of
|
|
13
|
+
* `vendor/ghostty`, no `WebAssembly.Function`, works in stable Chrome / Node /
|
|
14
|
+
* Bun today (verified 2026-07-24 on Node 22.22 and Bun 1.3.14).
|
|
15
|
+
*
|
|
16
|
+
* # Effect callback contract (from `terminal.h`, enforced by convention here)
|
|
17
|
+
*
|
|
18
|
+
* These are the rules every handler passed to {@link installEffects} MUST
|
|
19
|
+
* follow. They are load-bearing; violations produce hangs, traps, or corrupted
|
|
20
|
+
* parses, not error messages.
|
|
21
|
+
*
|
|
22
|
+
* 1. **Callbacks fire synchronously *inside* `ghostty_terminal_vt_write`.**
|
|
23
|
+
* The engine is mid-parse when your handler runs.
|
|
24
|
+
* 2. **Never re-enter the terminal.** A handler must not call `vt_write` (or
|
|
25
|
+
* anything that leads to it — `Terminal.write()` included) on the same
|
|
26
|
+
* terminal. `terminal.h`: "Callbacks must not call ghostty_terminal_vt_write
|
|
27
|
+
* on the same terminal (no reentrancy)." Route data *outward* (events,
|
|
28
|
+
* sockets) and let inbound data come back through the write queue
|
|
29
|
+
* (`../write-buffer.ts`), which makes accidental re-entry structurally
|
|
30
|
+
* impossible at the public-API layer.
|
|
31
|
+
* 3. **Be cheap.** Callbacks block further IO processing (`terminal.h`).
|
|
32
|
+
* Firing an event emitter or `WebSocket.send` (buffered, non-blocking) is
|
|
33
|
+
* fine — this matches xterm.js, whose parser fires `onData` for query
|
|
34
|
+
* responses synchronously mid-parse (`InputHandler` → `triggerDataEvent`).
|
|
35
|
+
* Doing layout, awaiting, or heavy allocation is not.
|
|
36
|
+
* 4. **Callback arguments are borrowed.** The `data` pointer passed to
|
|
37
|
+
* `write_pty` points into WASM scratch memory that is only valid for the
|
|
38
|
+
* duration of the call. This module copies the bytes out *before*
|
|
39
|
+
* dispatching to your handler — handlers receive an owned copy.
|
|
40
|
+
* 5. **Responses flow to the PTY, not back into the parser.** `write_pty`
|
|
41
|
+
* bytes are the terminal answering a query; they belong to the *process*
|
|
42
|
+
* side (for example: `onData` → WebSocket → server-side PTY). This mirrors
|
|
43
|
+
* Ghostty's own reference embedder (`vendor/ghostty/example/c-vt-effects`),
|
|
44
|
+
* which forwards them straight to the pty fd.
|
|
45
|
+
*
|
|
46
|
+
* # Extension path (deliberately not implemented yet)
|
|
47
|
+
*
|
|
48
|
+
* `ENQUIRY` / `XTVERSION` / `SIZE` / `COLOR_SCHEME` / `DEVICE_ATTRIBUTES` /
|
|
49
|
+
* `CLIPBOARD_WRITE` (OSC 52) are
|
|
50
|
+
* *value-producing* effects: the callback returns `bool`/`GhosttyString` and
|
|
51
|
+
* fills an out-struct, and the engine encodes the response itself. Wiring them
|
|
52
|
+
* follows the same pattern as below plus struct writes via `type-layouts.ts`
|
|
53
|
+
* offsets. Add them one at a time with a test each; the DA1 feature set is a
|
|
54
|
+
* product decision (which capabilities we advertise), not just plumbing.
|
|
55
|
+
* Note: plain DSR (`ESC[6n` / `ESC[5n`) needs none of them — those responses
|
|
56
|
+
* arrive fully-encoded through `WRITE_PTY`.
|
|
57
|
+
*/
|
|
58
|
+
import { FnTable, WasmValType } from "../../wasm/fn-table.js";
|
|
59
|
+
import { TerminalOption } from "./enums.js";
|
|
60
|
+
/** One FnTable per WASM instance (fn-table.ts rule 2), shared across terminals. */
|
|
61
|
+
const fnTables = new WeakMap();
|
|
62
|
+
function fnTableFor(exports) {
|
|
63
|
+
let ft = fnTables.get(exports.__indirect_function_table);
|
|
64
|
+
if (!ft) {
|
|
65
|
+
ft = new FnTable(exports.__indirect_function_table);
|
|
66
|
+
fnTables.set(exports.__indirect_function_table, ft);
|
|
67
|
+
}
|
|
68
|
+
return ft;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Install effect callbacks on a terminal.
|
|
72
|
+
*
|
|
73
|
+
* Mirrors `ghostty_terminal_set(term, GHOSTTY_TERMINAL_OPT_<EFFECT>, fn)` for
|
|
74
|
+
* each provided handler. The `void* value` of `terminal_set` for callback
|
|
75
|
+
* options IS the function pointer itself (verified against
|
|
76
|
+
* `vendor/ghostty/src/terminal/c/terminal.zig` `setTyped`), i.e. our table
|
|
77
|
+
* index.
|
|
78
|
+
*
|
|
79
|
+
* @param exports - The WASM instance the terminal lives in.
|
|
80
|
+
* @param terminalHandle - The `GhosttyTerminal` handle (`Terminal.handle`).
|
|
81
|
+
* @param handlers - Effect handlers. See {@link EffectHandlers} and the
|
|
82
|
+
* contract in the file header.
|
|
83
|
+
*/
|
|
84
|
+
export function installEffects(exports, terminalHandle, handlers) {
|
|
85
|
+
const fnTable = fnTableFor(exports);
|
|
86
|
+
const installed = [];
|
|
87
|
+
// GhosttyTerminalWritePtyFn: (GhosttyTerminal, void*, const uint8_t*, size_t) -> void
|
|
88
|
+
// wasm32: (i32, i32, i32, i32) -> ()
|
|
89
|
+
if (handlers.onWritePty) {
|
|
90
|
+
const onWritePty = handlers.onWritePty;
|
|
91
|
+
const fn = fnTable.install((_term, _userdata, dataPtr, len) => {
|
|
92
|
+
// Rule 4: copy out of borrowed WASM memory before dispatching.
|
|
93
|
+
// `slice()` copies; and the view must be constructed per-call because
|
|
94
|
+
// memory.buffer detaches when the memory grows.
|
|
95
|
+
const copy = new Uint8Array(exports.memory.buffer, dataPtr, len).slice();
|
|
96
|
+
onWritePty(copy);
|
|
97
|
+
}, [WasmValType.I32, WasmValType.I32, WasmValType.I32, WasmValType.I32]);
|
|
98
|
+
installed.push({ option: TerminalOption.WRITE_PTY, fn });
|
|
99
|
+
}
|
|
100
|
+
// GhosttyTerminalBellFn: (GhosttyTerminal, void*) -> void — (i32, i32) -> ()
|
|
101
|
+
if (handlers.onBell) {
|
|
102
|
+
const onBell = handlers.onBell;
|
|
103
|
+
const fn = fnTable.install(() => onBell(), [WasmValType.I32, WasmValType.I32]);
|
|
104
|
+
installed.push({ option: TerminalOption.BELL, fn });
|
|
105
|
+
}
|
|
106
|
+
// GhosttyTerminalTitleChangedFn: (GhosttyTerminal, void*) -> void — (i32, i32) -> ()
|
|
107
|
+
if (handlers.onTitleChanged) {
|
|
108
|
+
const onTitleChanged = handlers.onTitleChanged;
|
|
109
|
+
const fn = fnTable.install(() => onTitleChanged(), [WasmValType.I32, WasmValType.I32]);
|
|
110
|
+
installed.push({ option: TerminalOption.TITLE_CHANGED, fn });
|
|
111
|
+
}
|
|
112
|
+
// GhosttyTerminalPwdChangedFn: (GhosttyTerminal, void*) -> void — (i32, i32) -> ()
|
|
113
|
+
if (handlers.onPwdChanged) {
|
|
114
|
+
const onPwdChanged = handlers.onPwdChanged;
|
|
115
|
+
const fn = fnTable.install(() => onPwdChanged(), [WasmValType.I32, WasmValType.I32]);
|
|
116
|
+
installed.push({ option: TerminalOption.PWD_CHANGED, fn });
|
|
117
|
+
}
|
|
118
|
+
for (const { option, fn } of installed) {
|
|
119
|
+
const result = exports.ghostty_terminal_set(terminalHandle, option, fn.index);
|
|
120
|
+
if (result !== 0) {
|
|
121
|
+
// Roll back everything installed so far — half-installed effects are
|
|
122
|
+
// worse than none (some queries answered, others dropped).
|
|
123
|
+
for (const { option: opt, fn: f } of installed) {
|
|
124
|
+
exports.ghostty_terminal_set(terminalHandle, opt, 0);
|
|
125
|
+
f.release();
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`ghostty_terminal_set(option=${option}) failed: ${result}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
let disposed = false;
|
|
131
|
+
return {
|
|
132
|
+
dispose() {
|
|
133
|
+
if (disposed)
|
|
134
|
+
return;
|
|
135
|
+
disposed = true;
|
|
136
|
+
for (const { option, fn } of installed) {
|
|
137
|
+
exports.ghostty_terminal_set(terminalHandle, option, 0);
|
|
138
|
+
fn.release();
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.js","sourceRoot":"","sources":["../../../src/browser-terminal/vt/effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAoB,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EAAE,cAAc,EAAE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;QACvC,MAAM,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;QAC9E,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;YACjB,qEAAqE;YACrE,2DAA2D;YAC3D,KAAK,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,SAAS,EAAE,CAAC;gBAC/C,OAAO,CAAC,oBAAoB,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;gBACrD,CAAC,CAAC,OAAO,EAAE,CAAC;YACd,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,+BAA+B,MAAM,aAAa,MAAM,EAAE,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO;QACL,OAAO;YACL,IAAI,QAAQ;gBAAE,OAAO;YACrB,QAAQ,GAAG,IAAI,CAAC;YAChB,KAAK,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,SAAS,EAAE,CAAC;gBACvC,OAAO,CAAC,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;gBACxD,EAAE,CAAC,OAAO,EAAE,CAAC;YACf,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module browser-terminal/vt/enums
|
|
3
|
+
*
|
|
4
|
+
* C-header enum constants used by `ghostty_*_get` / `ghostty_*_set` keyed
|
|
5
|
+
* accessors. One namespace per header so each enum sits next to the wrapper
|
|
6
|
+
* that uses it, with a citation back to the canonical declaration in
|
|
7
|
+
* `vendor/ghostty/include/ghostty/vt/*.h`.
|
|
8
|
+
*
|
|
9
|
+
* All values are checked against the upstream headers; if Ghostty adds an
|
|
10
|
+
* enumerator the path is `wasm:update` → bump this file → wire the new
|
|
11
|
+
* data kind in the relevant wrapper. Don't reorder — the numeric values are
|
|
12
|
+
* the C ABI.
|
|
13
|
+
*/
|
|
14
|
+
/** `GhosttyTerminalData` — kinds for `ghostty_terminal_get` (`terminal.h`). */
|
|
15
|
+
export declare const TerminalData: {
|
|
16
|
+
readonly COLS: 1;
|
|
17
|
+
readonly ROWS: 2;
|
|
18
|
+
readonly CURSOR_X: 3;
|
|
19
|
+
readonly CURSOR_Y: 4;
|
|
20
|
+
readonly CURSOR_PENDING_WRAP: 5;
|
|
21
|
+
readonly ACTIVE_SCREEN: 6;
|
|
22
|
+
readonly CURSOR_VISIBLE: 7;
|
|
23
|
+
readonly KITTY_KEYBOARD_FLAGS: 8;
|
|
24
|
+
readonly SCROLLBAR: 9;
|
|
25
|
+
readonly CURSOR_STYLE: 10;
|
|
26
|
+
readonly MOUSE_TRACKING: 11;
|
|
27
|
+
readonly TITLE: 12;
|
|
28
|
+
readonly PWD: 13;
|
|
29
|
+
readonly TOTAL_ROWS: 14;
|
|
30
|
+
readonly SCROLLBACK_ROWS: 15;
|
|
31
|
+
readonly WIDTH_PX: 16;
|
|
32
|
+
readonly HEIGHT_PX: 17;
|
|
33
|
+
readonly COLOR_FOREGROUND: 18;
|
|
34
|
+
readonly COLOR_BACKGROUND: 19;
|
|
35
|
+
readonly COLOR_CURSOR: 20;
|
|
36
|
+
readonly COLOR_PALETTE: 21;
|
|
37
|
+
readonly VIEWPORT_ACTIVE: 32;
|
|
38
|
+
readonly VT_PROCESSING_ERROR: 33;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* `GhosttyTerminalOption` — keys for `ghostty_terminal_set` (`terminal.h:399-595`).
|
|
42
|
+
*
|
|
43
|
+
* VT_NOTE: `WRITE_PTY`/`BELL`/`ENQUIRY`/`XTVERSION`/`TITLE_CHANGED`/`SIZE`/
|
|
44
|
+
* `COLOR_SCHEME`/`DEVICE_ATTRIBUTES` are *effect* callbacks. We install
|
|
45
|
+
* WRITE_PTY / BELL / TITLE_CHANGED from JS via the function-table trick in
|
|
46
|
+
* `../../wasm/fn-table.ts` (no `WebAssembly.Function` needed) — see
|
|
47
|
+
* `./effects.ts` for the callback contract and the extension path for the
|
|
48
|
+
* value-producing effects (ENQUIRY/XTVERSION/SIZE/COLOR_SCHEME/
|
|
49
|
+
* DEVICE_ATTRIBUTES).
|
|
50
|
+
*/
|
|
51
|
+
export declare const TerminalOption: {
|
|
52
|
+
readonly USERDATA: 0;
|
|
53
|
+
readonly WRITE_PTY: 1;
|
|
54
|
+
readonly BELL: 2;
|
|
55
|
+
readonly ENQUIRY: 3;
|
|
56
|
+
readonly XTVERSION: 4;
|
|
57
|
+
readonly TITLE_CHANGED: 5;
|
|
58
|
+
readonly SIZE: 6;
|
|
59
|
+
readonly COLOR_SCHEME: 7;
|
|
60
|
+
readonly DEVICE_ATTRIBUTES: 8;
|
|
61
|
+
readonly TITLE: 9;
|
|
62
|
+
readonly PWD: 10;
|
|
63
|
+
readonly COLOR_FOREGROUND: 11;
|
|
64
|
+
readonly COLOR_BACKGROUND: 12;
|
|
65
|
+
readonly COLOR_CURSOR: 13;
|
|
66
|
+
readonly COLOR_PALETTE: 14;
|
|
67
|
+
/** Effect: pwd changed via OSC 7 / OSC 9;9 / OSC 1337. `GhosttyTerminalPwdChangedFn`. */
|
|
68
|
+
readonly PWD_CHANGED: 25;
|
|
69
|
+
/** Effect: OSC 52 clipboard write. `GhosttyTerminalClipboardWriteFn` (value-producing). */
|
|
70
|
+
readonly CLIPBOARD_WRITE: 26;
|
|
71
|
+
/** Scrollback cap in bytes (`u32*`). Pairs with SCROLLBACK_MAX_LINES. */
|
|
72
|
+
readonly SCROLLBACK_MAX_BYTES: 27;
|
|
73
|
+
/** Scrollback cap in lines (`u32*`). */
|
|
74
|
+
readonly SCROLLBACK_MAX_LINES: 28;
|
|
75
|
+
/** Effect: OSC 9 / OSC 777 desktop notification. Unwired — see NEXT.md. */
|
|
76
|
+
readonly DESKTOP_NOTIFICATION: 29;
|
|
77
|
+
/** Effect: OSC 9;4 progress report (ConEmu-style). Unwired — see NEXT.md. */
|
|
78
|
+
readonly PROGRESS_REPORT: 30;
|
|
79
|
+
};
|
|
80
|
+
/** `GhosttyTerminalScrollViewportTag` from `terminal.h`. */
|
|
81
|
+
export declare const ScrollViewportTag: {
|
|
82
|
+
readonly TOP: 0;
|
|
83
|
+
readonly BOTTOM: 1;
|
|
84
|
+
readonly DELTA: 2;
|
|
85
|
+
readonly ROW: 3;
|
|
86
|
+
};
|
|
87
|
+
/** `GhosttyRenderStateData` — kinds for `ghostty_render_state_get` (`render.h:120-220`). */
|
|
88
|
+
export declare const RenderStateData: {
|
|
89
|
+
readonly COLS: 1;
|
|
90
|
+
readonly ROWS: 2;
|
|
91
|
+
readonly DIRTY: 3;
|
|
92
|
+
readonly ROW_ITERATOR: 4;
|
|
93
|
+
readonly COLOR_BACKGROUND: 5;
|
|
94
|
+
readonly COLOR_FOREGROUND: 6;
|
|
95
|
+
readonly COLOR_CURSOR: 7;
|
|
96
|
+
readonly COLOR_CURSOR_HAS_VALUE: 8;
|
|
97
|
+
readonly COLOR_PALETTE: 9;
|
|
98
|
+
readonly CURSOR_VISUAL_STYLE: 10;
|
|
99
|
+
readonly CURSOR_VISIBLE: 11;
|
|
100
|
+
readonly CURSOR_BLINKING: 12;
|
|
101
|
+
readonly CURSOR_PASSWORD_INPUT: 13;
|
|
102
|
+
readonly CURSOR_VIEWPORT_HAS_VALUE: 14;
|
|
103
|
+
readonly CURSOR_VIEWPORT_X: 15;
|
|
104
|
+
readonly CURSOR_VIEWPORT_Y: 16;
|
|
105
|
+
readonly CURSOR_VIEWPORT_WIDE_TAIL: 17;
|
|
106
|
+
};
|
|
107
|
+
/** `GhosttyRenderStateOption` — keys for `ghostty_render_state_set` (`render.h`). */
|
|
108
|
+
export declare const RenderStateOption: {
|
|
109
|
+
readonly DIRTY: 0;
|
|
110
|
+
};
|
|
111
|
+
/** `GhosttyRenderStateRowData` — kinds for `ghostty_render_state_row_get` (`render.h`). */
|
|
112
|
+
export declare const RenderStateRowData: {
|
|
113
|
+
readonly DIRTY: 1;
|
|
114
|
+
readonly RAW: 2;
|
|
115
|
+
readonly CELLS: 3;
|
|
116
|
+
readonly SELECTION: 4;
|
|
117
|
+
};
|
|
118
|
+
/** `GhosttyRenderStateRowCellsData` — kinds for `ghostty_render_state_row_cells_get` (`render.h`). */
|
|
119
|
+
export declare const RenderStateRowCellsData: {
|
|
120
|
+
readonly RAW: 1;
|
|
121
|
+
readonly STYLE: 2;
|
|
122
|
+
readonly GRAPHEMES_LEN: 3;
|
|
123
|
+
readonly GRAPHEMES_BUF: 4;
|
|
124
|
+
readonly BG_COLOR: 5;
|
|
125
|
+
readonly FG_COLOR: 6;
|
|
126
|
+
readonly SELECTED: 7;
|
|
127
|
+
readonly HAS_STYLING: 8;
|
|
128
|
+
readonly GRAPHEMES_UTF8: 9;
|
|
129
|
+
};
|
|
130
|
+
/** `GhosttyCellData` — kinds for `ghostty_cell_get` (`screen.h`). */
|
|
131
|
+
export declare const CellData: {
|
|
132
|
+
readonly CODEPOINT: 1;
|
|
133
|
+
readonly CONTENT_TAG: 2;
|
|
134
|
+
readonly WIDE: 3;
|
|
135
|
+
readonly HAS_TEXT: 4;
|
|
136
|
+
readonly HAS_STYLING: 5;
|
|
137
|
+
readonly STYLE_ID: 6;
|
|
138
|
+
readonly HAS_HYPERLINK: 7;
|
|
139
|
+
readonly PROTECTED: 8;
|
|
140
|
+
readonly SEMANTIC_CONTENT: 9;
|
|
141
|
+
readonly COLOR_PALETTE: 10;
|
|
142
|
+
readonly COLOR_RGB: 11;
|
|
143
|
+
};
|
|
144
|
+
/** `GhosttyRowData` — kinds for `ghostty_row_get` (`screen.h`). */
|
|
145
|
+
export declare const RowData: {
|
|
146
|
+
readonly WRAP: 1;
|
|
147
|
+
readonly WRAP_CONTINUATION: 2;
|
|
148
|
+
readonly GRAPHEME: 3;
|
|
149
|
+
readonly STYLED: 4;
|
|
150
|
+
readonly HYPERLINK: 5;
|
|
151
|
+
readonly SEMANTIC_PROMPT: 6;
|
|
152
|
+
readonly KITTY_VIRTUAL_PLACEHOLDER: 7;
|
|
153
|
+
readonly DIRTY: 8;
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../../src/browser-terminal/vt/enums.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;CA0Bf,CAAC;AAEX;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;IAmBzB,yFAAyF;;IAEzF,2FAA2F;;IAG3F,yEAAyE;;IAEzE,wCAAwC;;IAExC,2EAA2E;;IAE3E,6EAA6E;;CAErE,CAAC;AAEX,4DAA4D;AAC5D,eAAO,MAAM,iBAAiB;;;;;CAKpB,CAAC;AAEX,4FAA4F;AAC5F,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;CAkBlB,CAAC;AAEX,qFAAqF;AACrF,eAAO,MAAM,iBAAiB;;CAEpB,CAAC;AAEX,2FAA2F;AAC3F,eAAO,MAAM,kBAAkB;;;;;CAKrB,CAAC;AAEX,sGAAsG;AACtG,eAAO,MAAM,uBAAuB;;;;;;;;;;CAU1B,CAAC;AAEX,qEAAqE;AACrE,eAAO,MAAM,QAAQ;;;;;;;;;;;;CAYX,CAAC;AAEX,mEAAmE;AACnE,eAAO,MAAM,OAAO;;;;;;;;;CASV,CAAC"}
|