@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,161 @@
|
|
|
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 const TerminalData = {
|
|
16
|
+
COLS: 1,
|
|
17
|
+
ROWS: 2,
|
|
18
|
+
CURSOR_X: 3,
|
|
19
|
+
CURSOR_Y: 4,
|
|
20
|
+
CURSOR_PENDING_WRAP: 5,
|
|
21
|
+
ACTIVE_SCREEN: 6,
|
|
22
|
+
CURSOR_VISIBLE: 7,
|
|
23
|
+
KITTY_KEYBOARD_FLAGS: 8,
|
|
24
|
+
SCROLLBAR: 9,
|
|
25
|
+
CURSOR_STYLE: 10,
|
|
26
|
+
MOUSE_TRACKING: 11,
|
|
27
|
+
TITLE: 12,
|
|
28
|
+
PWD: 13,
|
|
29
|
+
TOTAL_ROWS: 14,
|
|
30
|
+
SCROLLBACK_ROWS: 15,
|
|
31
|
+
WIDTH_PX: 16,
|
|
32
|
+
HEIGHT_PX: 17,
|
|
33
|
+
COLOR_FOREGROUND: 18,
|
|
34
|
+
COLOR_BACKGROUND: 19,
|
|
35
|
+
COLOR_CURSOR: 20,
|
|
36
|
+
COLOR_PALETTE: 21,
|
|
37
|
+
// vendor/ghostty@4c725242b additions (append-only upstream; 22-25 are the
|
|
38
|
+
// *_DEFAULT color variants, 26-29 kitty image config, not yet surfaced):
|
|
39
|
+
VIEWPORT_ACTIVE: 32,
|
|
40
|
+
VT_PROCESSING_ERROR: 33,
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* `GhosttyTerminalOption` — keys for `ghostty_terminal_set` (`terminal.h:399-595`).
|
|
44
|
+
*
|
|
45
|
+
* VT_NOTE: `WRITE_PTY`/`BELL`/`ENQUIRY`/`XTVERSION`/`TITLE_CHANGED`/`SIZE`/
|
|
46
|
+
* `COLOR_SCHEME`/`DEVICE_ATTRIBUTES` are *effect* callbacks. We install
|
|
47
|
+
* WRITE_PTY / BELL / TITLE_CHANGED from JS via the function-table trick in
|
|
48
|
+
* `../../wasm/fn-table.ts` (no `WebAssembly.Function` needed) — see
|
|
49
|
+
* `./effects.ts` for the callback contract and the extension path for the
|
|
50
|
+
* value-producing effects (ENQUIRY/XTVERSION/SIZE/COLOR_SCHEME/
|
|
51
|
+
* DEVICE_ATTRIBUTES).
|
|
52
|
+
*/
|
|
53
|
+
export const TerminalOption = {
|
|
54
|
+
USERDATA: 0,
|
|
55
|
+
WRITE_PTY: 1,
|
|
56
|
+
BELL: 2,
|
|
57
|
+
ENQUIRY: 3,
|
|
58
|
+
XTVERSION: 4,
|
|
59
|
+
TITLE_CHANGED: 5,
|
|
60
|
+
SIZE: 6,
|
|
61
|
+
COLOR_SCHEME: 7,
|
|
62
|
+
DEVICE_ATTRIBUTES: 8,
|
|
63
|
+
TITLE: 9,
|
|
64
|
+
PWD: 10,
|
|
65
|
+
COLOR_FOREGROUND: 11,
|
|
66
|
+
COLOR_BACKGROUND: 12,
|
|
67
|
+
COLOR_CURSOR: 13,
|
|
68
|
+
COLOR_PALETTE: 14,
|
|
69
|
+
// vendor/ghostty@4c725242b additions (append-only upstream; 15-24 are
|
|
70
|
+
// kitty-image / APC / selection / cursor-default / glyph-protocol options,
|
|
71
|
+
// not yet surfaced):
|
|
72
|
+
/** Effect: pwd changed via OSC 7 / OSC 9;9 / OSC 1337. `GhosttyTerminalPwdChangedFn`. */
|
|
73
|
+
PWD_CHANGED: 25,
|
|
74
|
+
/** Effect: OSC 52 clipboard write. `GhosttyTerminalClipboardWriteFn` (value-producing). */
|
|
75
|
+
CLIPBOARD_WRITE: 26,
|
|
76
|
+
// vendor/ghostty@6ad1fe7d8 additions (2026-07-29). Still append-only.
|
|
77
|
+
/** Scrollback cap in bytes (`u32*`). Pairs with SCROLLBACK_MAX_LINES. */
|
|
78
|
+
SCROLLBACK_MAX_BYTES: 27,
|
|
79
|
+
/** Scrollback cap in lines (`u32*`). */
|
|
80
|
+
SCROLLBACK_MAX_LINES: 28,
|
|
81
|
+
/** Effect: OSC 9 / OSC 777 desktop notification. Unwired — see NEXT.md. */
|
|
82
|
+
DESKTOP_NOTIFICATION: 29,
|
|
83
|
+
/** Effect: OSC 9;4 progress report (ConEmu-style). Unwired — see NEXT.md. */
|
|
84
|
+
PROGRESS_REPORT: 30,
|
|
85
|
+
};
|
|
86
|
+
/** `GhosttyTerminalScrollViewportTag` from `terminal.h`. */
|
|
87
|
+
export const ScrollViewportTag = {
|
|
88
|
+
TOP: 0,
|
|
89
|
+
BOTTOM: 1,
|
|
90
|
+
DELTA: 2,
|
|
91
|
+
ROW: 3,
|
|
92
|
+
};
|
|
93
|
+
/** `GhosttyRenderStateData` — kinds for `ghostty_render_state_get` (`render.h:120-220`). */
|
|
94
|
+
export const RenderStateData = {
|
|
95
|
+
COLS: 1,
|
|
96
|
+
ROWS: 2,
|
|
97
|
+
DIRTY: 3,
|
|
98
|
+
ROW_ITERATOR: 4,
|
|
99
|
+
COLOR_BACKGROUND: 5,
|
|
100
|
+
COLOR_FOREGROUND: 6,
|
|
101
|
+
COLOR_CURSOR: 7,
|
|
102
|
+
COLOR_CURSOR_HAS_VALUE: 8,
|
|
103
|
+
COLOR_PALETTE: 9,
|
|
104
|
+
CURSOR_VISUAL_STYLE: 10,
|
|
105
|
+
CURSOR_VISIBLE: 11,
|
|
106
|
+
CURSOR_BLINKING: 12,
|
|
107
|
+
CURSOR_PASSWORD_INPUT: 13,
|
|
108
|
+
CURSOR_VIEWPORT_HAS_VALUE: 14,
|
|
109
|
+
CURSOR_VIEWPORT_X: 15,
|
|
110
|
+
CURSOR_VIEWPORT_Y: 16,
|
|
111
|
+
CURSOR_VIEWPORT_WIDE_TAIL: 17,
|
|
112
|
+
};
|
|
113
|
+
/** `GhosttyRenderStateOption` — keys for `ghostty_render_state_set` (`render.h`). */
|
|
114
|
+
export const RenderStateOption = {
|
|
115
|
+
DIRTY: 0,
|
|
116
|
+
};
|
|
117
|
+
/** `GhosttyRenderStateRowData` — kinds for `ghostty_render_state_row_get` (`render.h`). */
|
|
118
|
+
export const RenderStateRowData = {
|
|
119
|
+
DIRTY: 1,
|
|
120
|
+
RAW: 2,
|
|
121
|
+
CELLS: 3,
|
|
122
|
+
SELECTION: 4,
|
|
123
|
+
};
|
|
124
|
+
/** `GhosttyRenderStateRowCellsData` — kinds for `ghostty_render_state_row_cells_get` (`render.h`). */
|
|
125
|
+
export const RenderStateRowCellsData = {
|
|
126
|
+
RAW: 1,
|
|
127
|
+
STYLE: 2,
|
|
128
|
+
GRAPHEMES_LEN: 3,
|
|
129
|
+
GRAPHEMES_BUF: 4,
|
|
130
|
+
BG_COLOR: 5,
|
|
131
|
+
FG_COLOR: 6,
|
|
132
|
+
SELECTED: 7,
|
|
133
|
+
HAS_STYLING: 8,
|
|
134
|
+
GRAPHEMES_UTF8: 9,
|
|
135
|
+
};
|
|
136
|
+
/** `GhosttyCellData` — kinds for `ghostty_cell_get` (`screen.h`). */
|
|
137
|
+
export const CellData = {
|
|
138
|
+
CODEPOINT: 1,
|
|
139
|
+
CONTENT_TAG: 2,
|
|
140
|
+
WIDE: 3,
|
|
141
|
+
HAS_TEXT: 4,
|
|
142
|
+
HAS_STYLING: 5,
|
|
143
|
+
STYLE_ID: 6,
|
|
144
|
+
HAS_HYPERLINK: 7,
|
|
145
|
+
PROTECTED: 8,
|
|
146
|
+
SEMANTIC_CONTENT: 9,
|
|
147
|
+
COLOR_PALETTE: 10,
|
|
148
|
+
COLOR_RGB: 11,
|
|
149
|
+
};
|
|
150
|
+
/** `GhosttyRowData` — kinds for `ghostty_row_get` (`screen.h`). */
|
|
151
|
+
export const RowData = {
|
|
152
|
+
WRAP: 1,
|
|
153
|
+
WRAP_CONTINUATION: 2,
|
|
154
|
+
GRAPHEME: 3,
|
|
155
|
+
STYLED: 4,
|
|
156
|
+
HYPERLINK: 5,
|
|
157
|
+
SEMANTIC_PROMPT: 6,
|
|
158
|
+
KITTY_VIRTUAL_PLACEHOLDER: 7,
|
|
159
|
+
DIRTY: 8,
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=enums.js.map
|
|
@@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C,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;IACR,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,CAAC;IACd,cAAc,EAAE,CAAC;CACT,CAAC;AAEX,qEAAqE;AACrE,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,CAAC;IACd,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,CAAC;IACd,QAAQ,EAAE,CAAC;IACX,aAAa,EAAE,CAAC;IAChB,SAAS,EAAE,CAAC;IACZ,gBAAgB,EAAE,CAAC;IACnB,aAAa,EAAE,EAAE;IACjB,SAAS,EAAE,EAAE;CACL,CAAC;AAEX,mEAAmE;AACnE,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,CAAC;IACP,iBAAiB,EAAE,CAAC;IACpB,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,eAAe,EAAE,CAAC;IAClB,yBAAyB,EAAE,CAAC;IAC5B,KAAK,EAAE,CAAC;CACA,CAAC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mouse encoding — `mouse.h` + `mouse/encoder.h` + `mouse/event.h`
|
|
3
|
+
* (`vendor/ghostty/include/ghostty/vt/`).
|
|
4
|
+
*
|
|
5
|
+
* Encodes mouse events into terminal escape sequences using the engine's own
|
|
6
|
+
* encoder — the same code native Ghostty uses (`src/input/mouse_encode.zig`).
|
|
7
|
+
* Supports X10, UTF-8, SGR, URxvt, and SGR-Pixels protocols and owns the
|
|
8
|
+
* decisions our old hand-rolled JS encoder got only approximately right:
|
|
9
|
+
*
|
|
10
|
+
* - `shouldReport` filtering per tracking mode (X10: presses of L/M/R only;
|
|
11
|
+
* normal (1000): no motion; button (1002): motion only while a button is
|
|
12
|
+
* down; any (1003): everything) — `mouse_encode.zig:178-197`.
|
|
13
|
+
* - Legacy (non-SGR) releases encode as button 3; wheel is 64/65; buttons
|
|
14
|
+
* 8-11 are 128+ — `mouse_encode.zig:200-227`.
|
|
15
|
+
* - Out-of-viewport suppression with release-always semantics, coordinate
|
|
16
|
+
* clamping, and motion dedup by cell (`OPT_TRACK_LAST_CELL`).
|
|
17
|
+
*
|
|
18
|
+
* ## Usage (mirrors the `c-vt-encode-mouse` official example)
|
|
19
|
+
*
|
|
20
|
+
* 1. `ghostty.createMouseEncoder()` once.
|
|
21
|
+
* 2. Per event: `syncFromTerminal(term)` (pulls tracking mode + format from
|
|
22
|
+
* live terminal state — apps toggle modes 1000/1002/1003/1005/1006/1015
|
|
23
|
+
* at any time), `setSize(...)` if geometry changed, then `encode(...)`.
|
|
24
|
+
* 3. `encode()` returns `null` when the event should NOT be reported (e.g.
|
|
25
|
+
* tracking disabled, motion in normal mode) — callers just skip sending.
|
|
26
|
+
*
|
|
27
|
+
* VT_NOTE: `GhosttyMousePosition` is **surface-space pixels** (f32), not
|
|
28
|
+
* cells — the encoder maps pixels → cells itself using `OPT_SIZE` geometry
|
|
29
|
+
* (and emits raw pixels for SGR-Pixels mode 1016, which a JS cell-based
|
|
30
|
+
* encoder could never support).
|
|
31
|
+
*
|
|
32
|
+
* ## External references (explore further)
|
|
33
|
+
*
|
|
34
|
+
* - [xterm ctlseqs — Mouse Tracking](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking)
|
|
35
|
+
* — the canonical protocol spec: tracking modes (9/1000/1002/1003),
|
|
36
|
+
* coordinate formats (1005 UTF-8, 1006 SGR, 1015 URxvt, 1016 SGR-Pixels),
|
|
37
|
+
* button/modifier bit layout. When a TUI misbehaves, this is ground truth.
|
|
38
|
+
* - [terminalguide — mouse](https://terminalguide.namepad.de/mouse/) — what
|
|
39
|
+
* real emulators actually do per mode, incl. edge cases ctlseqs leaves
|
|
40
|
+
* ambiguous (wheel in X10, release encoding differences).
|
|
41
|
+
* - `vendor/ghostty/src/input/mouse_encode.zig` — the engine implementation
|
|
42
|
+
* this wraps; outranks both above for "what will WE emit".
|
|
43
|
+
* - `vendor/ghostty/example/c-vt-encode-mouse/src/main.c` — official
|
|
44
|
+
* embedder usage this module mirrors.
|
|
45
|
+
*/
|
|
46
|
+
import type { GhosttyWasmExports } from "../../wasm/exports.js";
|
|
47
|
+
import type { WasmTypeLayouts } from "../../wasm/type-layouts.js";
|
|
48
|
+
import { type Mods } from "../types.js";
|
|
49
|
+
/** `GhosttyMouseAction` — `mouse/event.h:28-39`. */
|
|
50
|
+
export declare const MouseAction: {
|
|
51
|
+
readonly PRESS: 0;
|
|
52
|
+
readonly RELEASE: 1;
|
|
53
|
+
readonly MOTION: 2;
|
|
54
|
+
};
|
|
55
|
+
export type MouseAction = (typeof MouseAction)[keyof typeof MouseAction];
|
|
56
|
+
/** `GhosttyMouseButton` — `mouse/event.h:44-60`. FOUR/FIVE are wheel up/down. */
|
|
57
|
+
export declare const MouseButton: {
|
|
58
|
+
readonly UNKNOWN: 0;
|
|
59
|
+
readonly LEFT: 1;
|
|
60
|
+
readonly RIGHT: 2;
|
|
61
|
+
readonly MIDDLE: 3;
|
|
62
|
+
readonly FOUR: 4;
|
|
63
|
+
readonly FIVE: 5;
|
|
64
|
+
readonly SIX: 6;
|
|
65
|
+
readonly SEVEN: 7;
|
|
66
|
+
readonly EIGHT: 8;
|
|
67
|
+
readonly NINE: 9;
|
|
68
|
+
readonly TEN: 10;
|
|
69
|
+
readonly ELEVEN: 11;
|
|
70
|
+
};
|
|
71
|
+
export type MouseButton = (typeof MouseButton)[keyof typeof MouseButton];
|
|
72
|
+
/** `GhosttyMouseTrackingMode` — `mouse/encoder.h:35-48` (modes 9/1000/1002/1003). */
|
|
73
|
+
export declare const MouseTrackingMode: {
|
|
74
|
+
readonly NONE: 0;
|
|
75
|
+
readonly X10: 1;
|
|
76
|
+
readonly NORMAL: 2;
|
|
77
|
+
readonly BUTTON: 3;
|
|
78
|
+
readonly ANY: 4;
|
|
79
|
+
};
|
|
80
|
+
/** `GhosttyMouseFormat` — `mouse/encoder.h:57-62` (modes 1005/1006/1015/1016). */
|
|
81
|
+
export declare const MouseFormat: {
|
|
82
|
+
readonly X10: 0;
|
|
83
|
+
readonly UTF8: 1;
|
|
84
|
+
readonly SGR: 2;
|
|
85
|
+
readonly URXVT: 3;
|
|
86
|
+
readonly SGR_PIXELS: 4;
|
|
87
|
+
};
|
|
88
|
+
/** `GhosttyMouseEncoderOption` — `mouse/encoder.h:112-125`. */
|
|
89
|
+
export declare const MouseEncoderOption: {
|
|
90
|
+
readonly EVENT: 0;
|
|
91
|
+
readonly FORMAT: 1;
|
|
92
|
+
readonly SIZE: 2;
|
|
93
|
+
readonly ANY_BUTTON_PRESSED: 3;
|
|
94
|
+
readonly TRACK_LAST_CELL: 4;
|
|
95
|
+
};
|
|
96
|
+
/** Surface geometry for pixel→cell mapping (`GhosttyMouseEncoderSize`). CSS px is fine as long as it's consistent. */
|
|
97
|
+
export interface MouseEncoderSize {
|
|
98
|
+
screenWidth: number;
|
|
99
|
+
screenHeight: number;
|
|
100
|
+
cellWidth: number;
|
|
101
|
+
cellHeight: number;
|
|
102
|
+
}
|
|
103
|
+
/** Input for {@link MouseEncoder.encode}. */
|
|
104
|
+
export interface MouseEventInput {
|
|
105
|
+
action: MouseAction;
|
|
106
|
+
/** `null` = motion with no button pressed (`ghostty_mouse_event_clear_button`). */
|
|
107
|
+
button: MouseButton | null;
|
|
108
|
+
/** `GhosttyMods` bitmask — same layout as key mods (SHIFT/CTRL/ALT/SUPER). */
|
|
109
|
+
mods: Mods;
|
|
110
|
+
/** Surface-space pixel X (relative to the terminal canvas origin). */
|
|
111
|
+
x: number;
|
|
112
|
+
/** Surface-space pixel Y. */
|
|
113
|
+
y: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Wrapper around a `GhosttyMouseEncoder` handle. Mirrors the {@link KeyEncoder}
|
|
117
|
+
* pattern: one long-lived encoder + one reusable event handle (mouse motion is
|
|
118
|
+
* high-frequency; allocating per event would churn).
|
|
119
|
+
*
|
|
120
|
+
* The encoder is stateful (`last_cell` dedup, `any_button_pressed`) — use one
|
|
121
|
+
* per terminal and call `reset()` when the terminal resets.
|
|
122
|
+
*/
|
|
123
|
+
export declare class MouseEncoder {
|
|
124
|
+
private readonly exports;
|
|
125
|
+
private readonly layouts;
|
|
126
|
+
private handle;
|
|
127
|
+
/** Reusable `GhosttyMouseEvent` handle (created in ctor, freed on dispose). */
|
|
128
|
+
private eventHandle;
|
|
129
|
+
private encodeBuf?;
|
|
130
|
+
private writtenScratch?;
|
|
131
|
+
private _disposed;
|
|
132
|
+
constructor(opts: {
|
|
133
|
+
exports: GhosttyWasmExports;
|
|
134
|
+
typeLayouts: WasmTypeLayouts;
|
|
135
|
+
});
|
|
136
|
+
/**
|
|
137
|
+
* Pull tracking mode + format from live terminal state. Mirrors
|
|
138
|
+
* `ghostty_mouse_encoder_setopt_from_terminal(encoder, terminal)`
|
|
139
|
+
* (`mouse/encoder.h`). Call before each encode — applications toggle mouse
|
|
140
|
+
* modes at runtime and this is just two enum reads.
|
|
141
|
+
*/
|
|
142
|
+
syncFromTerminal(terminalHandle: number): void;
|
|
143
|
+
/** Set surface geometry (`OPT_SIZE`) for pixel→cell mapping. */
|
|
144
|
+
setSize(size: MouseEncoderSize): void;
|
|
145
|
+
/**
|
|
146
|
+
* Tell the encoder whether any button is currently held (`OPT_ANY_BUTTON_PRESSED`)
|
|
147
|
+
* — required for correct motion filtering in button-tracking mode (1002).
|
|
148
|
+
*/
|
|
149
|
+
setAnyButtonPressed(pressed: boolean): void;
|
|
150
|
+
/** Clear encoder state (`ghostty_mouse_encoder_reset`) — e.g. on terminal reset. */
|
|
151
|
+
reset(): void;
|
|
152
|
+
/**
|
|
153
|
+
* Encode one mouse event. Returns the report bytes, or `null` when the
|
|
154
|
+
* engine decides the event should not be reported (tracking off, motion in
|
|
155
|
+
* normal mode, same-cell motion with dedup, out-of-viewport, ...). "Not
|
|
156
|
+
* all events result in output" — `input/mouse_encode.zig:80`.
|
|
157
|
+
*/
|
|
158
|
+
encode(event: MouseEventInput): Uint8Array | null;
|
|
159
|
+
/** Free the encoder, event handle, and scratch memory. */
|
|
160
|
+
dispose(): void;
|
|
161
|
+
private assertAlive;
|
|
162
|
+
private setBoolOption;
|
|
163
|
+
private ensureWrittenScratch;
|
|
164
|
+
private ensureEncodeBuf;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=mouse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mouse.d.ts","sourceRoot":"","sources":["../../../src/browser-terminal/vt/mouse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAiB,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAEvD,oDAAoD;AACpD,eAAO,MAAM,WAAW;;;;CAId,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE,iFAAiF;AACjF,eAAO,MAAM,WAAW;;;;;;;;;;;;;CAad,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE,qFAAqF;AACrF,eAAO,MAAM,iBAAiB;;;;;;CAMpB,CAAC;AAEX,kFAAkF;AAClF,eAAO,MAAM,WAAW;;;;;;CAMd,CAAC;AAEX,+DAA+D;AAC/D,eAAO,MAAM,kBAAkB;;;;;;CAMrB,CAAC;AAEX,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QrB,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,eAAe;CAQxB"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mouse encoding — `mouse.h` + `mouse/encoder.h` + `mouse/event.h`
|
|
3
|
+
* (`vendor/ghostty/include/ghostty/vt/`).
|
|
4
|
+
*
|
|
5
|
+
* Encodes mouse events into terminal escape sequences using the engine's own
|
|
6
|
+
* encoder — the same code native Ghostty uses (`src/input/mouse_encode.zig`).
|
|
7
|
+
* Supports X10, UTF-8, SGR, URxvt, and SGR-Pixels protocols and owns the
|
|
8
|
+
* decisions our old hand-rolled JS encoder got only approximately right:
|
|
9
|
+
*
|
|
10
|
+
* - `shouldReport` filtering per tracking mode (X10: presses of L/M/R only;
|
|
11
|
+
* normal (1000): no motion; button (1002): motion only while a button is
|
|
12
|
+
* down; any (1003): everything) — `mouse_encode.zig:178-197`.
|
|
13
|
+
* - Legacy (non-SGR) releases encode as button 3; wheel is 64/65; buttons
|
|
14
|
+
* 8-11 are 128+ — `mouse_encode.zig:200-227`.
|
|
15
|
+
* - Out-of-viewport suppression with release-always semantics, coordinate
|
|
16
|
+
* clamping, and motion dedup by cell (`OPT_TRACK_LAST_CELL`).
|
|
17
|
+
*
|
|
18
|
+
* ## Usage (mirrors the `c-vt-encode-mouse` official example)
|
|
19
|
+
*
|
|
20
|
+
* 1. `ghostty.createMouseEncoder()` once.
|
|
21
|
+
* 2. Per event: `syncFromTerminal(term)` (pulls tracking mode + format from
|
|
22
|
+
* live terminal state — apps toggle modes 1000/1002/1003/1005/1006/1015
|
|
23
|
+
* at any time), `setSize(...)` if geometry changed, then `encode(...)`.
|
|
24
|
+
* 3. `encode()` returns `null` when the event should NOT be reported (e.g.
|
|
25
|
+
* tracking disabled, motion in normal mode) — callers just skip sending.
|
|
26
|
+
*
|
|
27
|
+
* VT_NOTE: `GhosttyMousePosition` is **surface-space pixels** (f32), not
|
|
28
|
+
* cells — the encoder maps pixels → cells itself using `OPT_SIZE` geometry
|
|
29
|
+
* (and emits raw pixels for SGR-Pixels mode 1016, which a JS cell-based
|
|
30
|
+
* encoder could never support).
|
|
31
|
+
*
|
|
32
|
+
* ## External references (explore further)
|
|
33
|
+
*
|
|
34
|
+
* - [xterm ctlseqs — Mouse Tracking](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking)
|
|
35
|
+
* — the canonical protocol spec: tracking modes (9/1000/1002/1003),
|
|
36
|
+
* coordinate formats (1005 UTF-8, 1006 SGR, 1015 URxvt, 1016 SGR-Pixels),
|
|
37
|
+
* button/modifier bit layout. When a TUI misbehaves, this is ground truth.
|
|
38
|
+
* - [terminalguide — mouse](https://terminalguide.namepad.de/mouse/) — what
|
|
39
|
+
* real emulators actually do per mode, incl. edge cases ctlseqs leaves
|
|
40
|
+
* ambiguous (wheel in X10, release encoding differences).
|
|
41
|
+
* - `vendor/ghostty/src/input/mouse_encode.zig` — the engine implementation
|
|
42
|
+
* this wraps; outranks both above for "what will WE emit".
|
|
43
|
+
* - `vendor/ghostty/example/c-vt-encode-mouse/src/main.c` — official
|
|
44
|
+
* embedder usage this module mirrors.
|
|
45
|
+
*/
|
|
46
|
+
import { withBytes } from "../../wasm/alloc.js";
|
|
47
|
+
import { fieldOffset, readU32, structSize, writeU32 } from "../../wasm/memory.js";
|
|
48
|
+
import { GhosttyResult } from "../types.js";
|
|
49
|
+
/** `GhosttyMouseAction` — `mouse/event.h:28-39`. */
|
|
50
|
+
export const MouseAction = {
|
|
51
|
+
PRESS: 0,
|
|
52
|
+
RELEASE: 1,
|
|
53
|
+
MOTION: 2,
|
|
54
|
+
};
|
|
55
|
+
/** `GhosttyMouseButton` — `mouse/event.h:44-60`. FOUR/FIVE are wheel up/down. */
|
|
56
|
+
export const MouseButton = {
|
|
57
|
+
UNKNOWN: 0,
|
|
58
|
+
LEFT: 1,
|
|
59
|
+
RIGHT: 2,
|
|
60
|
+
MIDDLE: 3,
|
|
61
|
+
FOUR: 4,
|
|
62
|
+
FIVE: 5,
|
|
63
|
+
SIX: 6,
|
|
64
|
+
SEVEN: 7,
|
|
65
|
+
EIGHT: 8,
|
|
66
|
+
NINE: 9,
|
|
67
|
+
TEN: 10,
|
|
68
|
+
ELEVEN: 11,
|
|
69
|
+
};
|
|
70
|
+
/** `GhosttyMouseTrackingMode` — `mouse/encoder.h:35-48` (modes 9/1000/1002/1003). */
|
|
71
|
+
export const MouseTrackingMode = {
|
|
72
|
+
NONE: 0,
|
|
73
|
+
X10: 1,
|
|
74
|
+
NORMAL: 2,
|
|
75
|
+
BUTTON: 3,
|
|
76
|
+
ANY: 4,
|
|
77
|
+
};
|
|
78
|
+
/** `GhosttyMouseFormat` — `mouse/encoder.h:57-62` (modes 1005/1006/1015/1016). */
|
|
79
|
+
export const MouseFormat = {
|
|
80
|
+
X10: 0,
|
|
81
|
+
UTF8: 1,
|
|
82
|
+
SGR: 2,
|
|
83
|
+
URXVT: 3,
|
|
84
|
+
SGR_PIXELS: 4,
|
|
85
|
+
};
|
|
86
|
+
/** `GhosttyMouseEncoderOption` — `mouse/encoder.h:112-125`. */
|
|
87
|
+
export const MouseEncoderOption = {
|
|
88
|
+
EVENT: 0,
|
|
89
|
+
FORMAT: 1,
|
|
90
|
+
SIZE: 2,
|
|
91
|
+
ANY_BUTTON_PRESSED: 3,
|
|
92
|
+
TRACK_LAST_CELL: 4,
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Wrapper around a `GhosttyMouseEncoder` handle. Mirrors the {@link KeyEncoder}
|
|
96
|
+
* pattern: one long-lived encoder + one reusable event handle (mouse motion is
|
|
97
|
+
* high-frequency; allocating per event would churn).
|
|
98
|
+
*
|
|
99
|
+
* The encoder is stateful (`last_cell` dedup, `any_button_pressed`) — use one
|
|
100
|
+
* per terminal and call `reset()` when the terminal resets.
|
|
101
|
+
*/
|
|
102
|
+
export class MouseEncoder {
|
|
103
|
+
exports;
|
|
104
|
+
layouts;
|
|
105
|
+
handle;
|
|
106
|
+
/** Reusable `GhosttyMouseEvent` handle (created in ctor, freed on dispose). */
|
|
107
|
+
eventHandle;
|
|
108
|
+
encodeBuf;
|
|
109
|
+
writtenScratch;
|
|
110
|
+
_disposed = false;
|
|
111
|
+
constructor(opts) {
|
|
112
|
+
this.exports = opts.exports;
|
|
113
|
+
this.layouts = opts.typeLayouts;
|
|
114
|
+
const outPtr = this.exports.ghostty_wasm_alloc_opaque();
|
|
115
|
+
try {
|
|
116
|
+
const result = this.exports.ghostty_mouse_encoder_new(0, outPtr);
|
|
117
|
+
if (result !== GhosttyResult.SUCCESS)
|
|
118
|
+
throw new Error(`ghostty_mouse_encoder_new failed: ${result}`);
|
|
119
|
+
this.handle = readU32(this.exports.memory, outPtr);
|
|
120
|
+
const evtResult = this.exports.ghostty_mouse_event_new(0, outPtr);
|
|
121
|
+
if (evtResult !== GhosttyResult.SUCCESS) {
|
|
122
|
+
this.exports.ghostty_mouse_encoder_free(this.handle);
|
|
123
|
+
throw new Error(`ghostty_mouse_event_new failed: ${evtResult}`);
|
|
124
|
+
}
|
|
125
|
+
this.eventHandle = readU32(this.exports.memory, outPtr);
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
this.exports.ghostty_wasm_free_opaque(outPtr);
|
|
129
|
+
}
|
|
130
|
+
// Cell-level motion dedup on by default — equivalent to the "don't spam
|
|
131
|
+
// reports for sub-cell movement" throttling embedders otherwise hand-roll.
|
|
132
|
+
this.setBoolOption(MouseEncoderOption.TRACK_LAST_CELL, true);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Pull tracking mode + format from live terminal state. Mirrors
|
|
136
|
+
* `ghostty_mouse_encoder_setopt_from_terminal(encoder, terminal)`
|
|
137
|
+
* (`mouse/encoder.h`). Call before each encode — applications toggle mouse
|
|
138
|
+
* modes at runtime and this is just two enum reads.
|
|
139
|
+
*/
|
|
140
|
+
syncFromTerminal(terminalHandle) {
|
|
141
|
+
this.assertAlive();
|
|
142
|
+
this.exports.ghostty_mouse_encoder_setopt_from_terminal(this.handle, terminalHandle);
|
|
143
|
+
}
|
|
144
|
+
/** Set surface geometry (`OPT_SIZE`) for pixel→cell mapping. */
|
|
145
|
+
setSize(size) {
|
|
146
|
+
this.assertAlive();
|
|
147
|
+
const structName = "GhosttyMouseEncoderSize";
|
|
148
|
+
const byteSize = structSize(this.layouts, structName);
|
|
149
|
+
withBytes(this.exports, byteSize, (ptr) => {
|
|
150
|
+
const memory = this.exports.memory;
|
|
151
|
+
// The struct's `size` field is the ABI-versioning discriminator — must
|
|
152
|
+
// be set to sizeof(struct) per encoder.h.
|
|
153
|
+
writeU32(memory, ptr + fieldOffset(this.layouts, structName, "size"), byteSize);
|
|
154
|
+
writeU32(memory, ptr + fieldOffset(this.layouts, structName, "screen_width"), size.screenWidth);
|
|
155
|
+
writeU32(memory, ptr + fieldOffset(this.layouts, structName, "screen_height"), size.screenHeight);
|
|
156
|
+
writeU32(memory, ptr + fieldOffset(this.layouts, structName, "cell_width"), size.cellWidth);
|
|
157
|
+
writeU32(memory, ptr + fieldOffset(this.layouts, structName, "cell_height"), size.cellHeight);
|
|
158
|
+
this.exports.ghostty_mouse_encoder_setopt(this.handle, MouseEncoderOption.SIZE, ptr);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Tell the encoder whether any button is currently held (`OPT_ANY_BUTTON_PRESSED`)
|
|
163
|
+
* — required for correct motion filtering in button-tracking mode (1002).
|
|
164
|
+
*/
|
|
165
|
+
setAnyButtonPressed(pressed) {
|
|
166
|
+
this.setBoolOption(MouseEncoderOption.ANY_BUTTON_PRESSED, pressed);
|
|
167
|
+
}
|
|
168
|
+
/** Clear encoder state (`ghostty_mouse_encoder_reset`) — e.g. on terminal reset. */
|
|
169
|
+
reset() {
|
|
170
|
+
this.assertAlive();
|
|
171
|
+
this.exports.ghostty_mouse_encoder_reset(this.handle);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Encode one mouse event. Returns the report bytes, or `null` when the
|
|
175
|
+
* engine decides the event should not be reported (tracking off, motion in
|
|
176
|
+
* normal mode, same-cell motion with dedup, out-of-viewport, ...). "Not
|
|
177
|
+
* all events result in output" — `input/mouse_encode.zig:80`.
|
|
178
|
+
*/
|
|
179
|
+
encode(event) {
|
|
180
|
+
this.assertAlive();
|
|
181
|
+
const exports = this.exports;
|
|
182
|
+
const memory = exports.memory;
|
|
183
|
+
const evt = this.eventHandle;
|
|
184
|
+
exports.ghostty_mouse_event_set_action(evt, event.action);
|
|
185
|
+
if (event.button === null) {
|
|
186
|
+
exports.ghostty_mouse_event_clear_button(evt);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
exports.ghostty_mouse_event_set_button(evt, event.button);
|
|
190
|
+
}
|
|
191
|
+
exports.ghostty_mouse_event_set_mods(evt, event.mods);
|
|
192
|
+
// GhosttyMousePosition is an { f32 x, f32 y } struct passed by pointer on
|
|
193
|
+
// wasm32 (verified via type reflection: set_position is (i32, i32) -> ()).
|
|
194
|
+
const posStruct = "GhosttyMousePosition";
|
|
195
|
+
withBytes(exports, structSize(this.layouts, posStruct), (posPtr) => {
|
|
196
|
+
const dv = new DataView(memory.buffer);
|
|
197
|
+
dv.setFloat32(posPtr + fieldOffset(this.layouts, posStruct, "x"), event.x, true);
|
|
198
|
+
dv.setFloat32(posPtr + fieldOffset(this.layouts, posStruct, "y"), event.y, true);
|
|
199
|
+
exports.ghostty_mouse_event_set_position(evt, posPtr);
|
|
200
|
+
});
|
|
201
|
+
// Encode with OUT_OF_SPACE retry (KeyEncoder pattern). Reports are tiny
|
|
202
|
+
// (< 32 bytes) so the retry path is theoretical.
|
|
203
|
+
const writtenPtr = this.ensureWrittenScratch();
|
|
204
|
+
let cap = 64;
|
|
205
|
+
let buf = this.ensureEncodeBuf(cap);
|
|
206
|
+
writeU32(memory, writtenPtr, 0);
|
|
207
|
+
let result = exports.ghostty_mouse_encoder_encode(this.handle, evt, buf, cap, writtenPtr);
|
|
208
|
+
if (result === GhosttyResult.OUT_OF_SPACE) {
|
|
209
|
+
cap = readU32(memory, writtenPtr);
|
|
210
|
+
buf = this.ensureEncodeBuf(cap);
|
|
211
|
+
result = exports.ghostty_mouse_encoder_encode(this.handle, evt, buf, cap, writtenPtr);
|
|
212
|
+
}
|
|
213
|
+
if (result !== GhosttyResult.SUCCESS) {
|
|
214
|
+
throw new Error(`ghostty_mouse_encoder_encode failed: ${result}`);
|
|
215
|
+
}
|
|
216
|
+
const written = readU32(memory, writtenPtr);
|
|
217
|
+
if (written === 0)
|
|
218
|
+
return null;
|
|
219
|
+
return new Uint8Array(memory.buffer, buf, written).slice();
|
|
220
|
+
}
|
|
221
|
+
/** Free the encoder, event handle, and scratch memory. */
|
|
222
|
+
dispose() {
|
|
223
|
+
if (this._disposed)
|
|
224
|
+
return;
|
|
225
|
+
this._disposed = true;
|
|
226
|
+
if (this.encodeBuf)
|
|
227
|
+
this.exports.ghostty_wasm_free_u8_array(this.encodeBuf.ptr, this.encodeBuf.capacity);
|
|
228
|
+
if (this.writtenScratch !== undefined)
|
|
229
|
+
this.exports.ghostty_wasm_free_usize(this.writtenScratch);
|
|
230
|
+
this.exports.ghostty_mouse_event_free(this.eventHandle);
|
|
231
|
+
this.exports.ghostty_mouse_encoder_free(this.handle);
|
|
232
|
+
}
|
|
233
|
+
assertAlive() {
|
|
234
|
+
if (this._disposed)
|
|
235
|
+
throw new Error("MouseEncoder has been disposed");
|
|
236
|
+
}
|
|
237
|
+
setBoolOption(option, value) {
|
|
238
|
+
this.assertAlive();
|
|
239
|
+
withBytes(this.exports, 1, (ptr) => {
|
|
240
|
+
new Uint8Array(this.exports.memory.buffer, ptr, 1)[0] = value ? 1 : 0;
|
|
241
|
+
this.exports.ghostty_mouse_encoder_setopt(this.handle, option, ptr);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
ensureWrittenScratch() {
|
|
245
|
+
if (this.writtenScratch === undefined)
|
|
246
|
+
this.writtenScratch = this.exports.ghostty_wasm_alloc_usize();
|
|
247
|
+
return this.writtenScratch;
|
|
248
|
+
}
|
|
249
|
+
ensureEncodeBuf(capacity) {
|
|
250
|
+
if (!this.encodeBuf || this.encodeBuf.capacity < capacity) {
|
|
251
|
+
if (this.encodeBuf)
|
|
252
|
+
this.exports.ghostty_wasm_free_u8_array(this.encodeBuf.ptr, this.encodeBuf.capacity);
|
|
253
|
+
const ptr = this.exports.ghostty_wasm_alloc_u8_array(capacity);
|
|
254
|
+
this.encodeBuf = { ptr, capacity };
|
|
255
|
+
}
|
|
256
|
+
return this.encodeBuf.ptr;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=mouse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mouse.js","sourceRoot":"","sources":["../../../src/browser-terminal/vt/mouse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAElF,OAAO,EAAE,aAAa,EAAa,MAAM,aAAa,CAAC;AAEvD,oDAAoD;AACpD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,CAAC;CACD,CAAC;AAGX,iFAAiF;AACjF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,EAA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AC,QAAQ,CAAC,CAAC;YACzG,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;YAC/D,IAAI,CAAC,SAAS,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;QACrC,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paste utilities — `paste.h` (`vendor/ghostty/include/ghostty/vt/paste.h`).
|
|
3
|
+
*
|
|
4
|
+
* Validates and encodes paste data for terminal input. The dangerous cases
|
|
5
|
+
* (per `paste.h` and the `c-vt-paste` official example):
|
|
6
|
+
*
|
|
7
|
+
* - **Newline injection**: a pasted `\n` outside bracketed paste executes
|
|
8
|
+
* whatever precedes it as a command.
|
|
9
|
+
* - **Bracket escape**: pasted data containing `\x1b[201~` (the bracketed
|
|
10
|
+
* paste END sequence) breaks out of the paste bracket and injects raw
|
|
11
|
+
* input — the classic "paste from a malicious webpage" attack.
|
|
12
|
+
*
|
|
13
|
+
* `pasteEncode()` is the engine's own mitigation and what `Terminal.paste()`
|
|
14
|
+
* uses: strips unsafe control bytes (NUL, ESC, DEL, ...), wraps in
|
|
15
|
+
* `\x1b[200~ ... \x1b[201~` when bracketed mode is active, converts `\n` to
|
|
16
|
+
* `\r` when it isn't. `pasteIsSafe()` is the conservative pre-check UIs can
|
|
17
|
+
* use to warn the user *before* pasting (it flags data unsafe regardless of
|
|
18
|
+
* terminal state).
|
|
19
|
+
*
|
|
20
|
+
* ## External references (explore further)
|
|
21
|
+
*
|
|
22
|
+
* - [xterm ctlseqs — Bracketed Paste Mode](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode)
|
|
23
|
+
* — canonical spec for DEC mode 2004 and the `ESC[200~`/`ESC[201~` bracket.
|
|
24
|
+
* - [Jann Horn — "Don't copy-paste from website to terminal"](https://thejh.net/misc/website-terminal-copy-paste)
|
|
25
|
+
* — the canonical demo of this attack class, including the variant that
|
|
26
|
+
* defeats naive bracketed paste by embedding `ESC[201~` in the pasted text
|
|
27
|
+
* (exactly what `is_safe` flags and `encode` strips). Read before deciding
|
|
28
|
+
* whether a UI confirmation prompt is warranted.
|
|
29
|
+
* - `vendor/ghostty/src/terminal/c/paste.zig` + `example/c-vt-paste` — the
|
|
30
|
+
* engine implementation and official usage this module mirrors.
|
|
31
|
+
*/
|
|
32
|
+
import type { GhosttyWasmExports } from "../../wasm/exports.js";
|
|
33
|
+
/**
|
|
34
|
+
* Conservative safety check for paste data. Mirrors
|
|
35
|
+
* `ghostty_paste_is_safe(data, len)` from `paste.h`.
|
|
36
|
+
*
|
|
37
|
+
* Returns `false` if the data contains newlines or the bracketed-paste end
|
|
38
|
+
* sequence — regardless of current terminal state. Intended for UI-level
|
|
39
|
+
* "are you sure?" prompts; {@link pasteEncode} sanitizes independently.
|
|
40
|
+
*/
|
|
41
|
+
export declare function pasteIsSafe(exports: GhosttyWasmExports, data: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Encode paste data for the pty. Mirrors `ghostty_paste_encode(...)` from
|
|
44
|
+
* `paste.h`: strips unsafe control bytes, brackets the payload when
|
|
45
|
+
* `bracketed` is true, converts newlines to carriage returns when it isn't.
|
|
46
|
+
*
|
|
47
|
+
* Two-pass on `OUT_OF_SPACE` per the header contract: a first call with the
|
|
48
|
+
* input-sized buffer usually fits (encoding only grows by the 12-byte
|
|
49
|
+
* bracket overhead), and on `OUT_OF_SPACE` we retry with the engine-reported
|
|
50
|
+
* required size. Returns a latin1 "binary string" ready for `onData`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function pasteEncode(exports: GhosttyWasmExports, data: string, bracketed: boolean): string;
|
|
53
|
+
//# sourceMappingURL=paste.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paste.d.ts","sourceRoot":"","sources":["../../../src/browser-terminal/vt/paste.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAKhE;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAO9E;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAiCjG"}
|