@crunchloop/ghostty-web 0.4.1

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.
@@ -0,0 +1,2445 @@
1
+ export declare class CanvasRenderer {
2
+ private canvas;
3
+ private ctx;
4
+ private fontSize;
5
+ private fontFamily;
6
+ private cursorStyle;
7
+ private cursorBlink;
8
+ private theme;
9
+ private devicePixelRatio;
10
+ private metrics;
11
+ private palette;
12
+ private cursorVisible;
13
+ private cursorBlinkInterval?;
14
+ private lastCursorPosition;
15
+ private onRequestRender;
16
+ private lastViewportY;
17
+ private currentBuffer;
18
+ /**
19
+ * Decoded kitty graphics images, keyed by image id. Each entry caches
20
+ * a canvas painted from the WASM-side RGBA bytes so per-frame compositing
21
+ * is just a drawImage call.
22
+ *
23
+ * Staleness key combines width/height/format/dataPtr/dataLen — the
24
+ * kitty protocol allows reusing an id with new bytes, and dataLen alone
25
+ * is too weak (transposed dims or format change can keep byte count
26
+ * identical). dataPtr is the WASM byteOffset, which changes whenever
27
+ * ghostty frees + re-allocates the image bytes (i.e., on retransmit).
28
+ */
29
+ private kittyImageCache;
30
+ /**
31
+ * Per-frame index of virtual placements keyed by image id. Populated
32
+ * once at the start of each render() pass (cheap — typically zero or
33
+ * a handful of entries). Looked up by U+10EEEE placeholder cells in
34
+ * renderPlaceholderCell to find the placement's grid dimensions.
35
+ */
36
+ private kittyVirtualPlacements;
37
+ /**
38
+ * Direct (non-virtual) placements that need compositing this frame.
39
+ * Built once per render() in precomputeKittyState so renderKittyImages
40
+ * doesn't re-walk the iterator. Empty when no kitty graphics are active.
41
+ */
42
+ private currentDirectPlacements;
43
+ /**
44
+ * Last frame's direct-placement signatures, keyed by image id. Used to
45
+ * detect placement add/remove/move/redecode so we can mark the affected
46
+ * rows for repaint (clearing stale image pixels) and skip the composite
47
+ * pass entirely when nothing has changed. dataLen is the same staleness
48
+ * discriminator used by kittyImageCache.
49
+ */
50
+ private lastKittyDirectSigs;
51
+ /**
52
+ * Rows whose image footprint changed since last frame (placement added,
53
+ * removed, moved, resized, or re-decoded under the same id). Added to
54
+ * rowsToRender so the underlying text repaints — which clears stale
55
+ * image pixels — before we composite the current placements on top.
56
+ */
57
+ private kittyDamagedRows;
58
+ /**
59
+ * Cached IRenderable on the current render() call so renderCellText
60
+ * can call into it (e.g. getGrapheme) without us threading the buffer
61
+ * through every helper. Set at the top of render(), cleared at the end.
62
+ */
63
+ private currentRenderBuffer;
64
+ private currentKittyGraphics;
65
+ private selectionManager?;
66
+ private currentSelectionCoords;
67
+ private hoveredHyperlinkId;
68
+ private previousHoveredHyperlinkId;
69
+ private hoveredLinkRange;
70
+ private previousHoveredLinkRange;
71
+ constructor(canvas: HTMLCanvasElement, options?: RendererOptions);
72
+ /**
73
+ * Build a CSS font string with proper quoting for font families with spaces.
74
+ * Example: "Fira Code, monospace" -> '"Fira Code", monospace'
75
+ */
76
+ private buildFontString;
77
+ private measureFont;
78
+ /**
79
+ * Remeasure font metrics (call after font loads or changes)
80
+ */
81
+ remeasureFont(): void;
82
+ private rgbToCSS;
83
+ /**
84
+ * Resize canvas to fit terminal dimensions
85
+ */
86
+ resize(cols: number, rows: number): void;
87
+ /**
88
+ * Render the terminal buffer to canvas
89
+ */
90
+ render(buffer: IRenderable, forceAll?: boolean, viewportY?: number, scrollbackProvider?: IScrollbackProvider, scrollbarOpacity?: number): void;
91
+ /**
92
+ * Render a single line using two-pass approach:
93
+ * 1. First pass: Draw all cell backgrounds
94
+ * 2. Second pass: Draw all cell text and decorations
95
+ *
96
+ * This two-pass approach is necessary for proper rendering of complex scripts
97
+ * like Devanagari where diacritics (like vowel sign ि) can extend LEFT of the
98
+ * base character into the previous cell's visual area. If we draw backgrounds
99
+ * and text in a single pass (cell by cell), the background of cell N would
100
+ * cover any left-extending portions of graphemes from cell N-1.
101
+ */
102
+ private renderLine;
103
+ /**
104
+ * Render a cell's background only (Pass 1 of two-pass rendering)
105
+ * Selection highlighting is integrated here to avoid z-order issues with
106
+ * complex glyphs (like Devanagari) that extend outside their cell bounds.
107
+ */
108
+ private renderCellBackground;
109
+ /**
110
+ * Render a cell's text and decorations (Pass 2 of two-pass rendering)
111
+ * Selection foreground color is applied here to match the selection background.
112
+ */
113
+ private renderCellText;
114
+ /**
115
+ * Render block drawing characters as filled rectangles for pixel-perfect rendering.
116
+ * Returns true if the character was handled, false if it should be rendered as text.
117
+ */
118
+ private renderBlockChar;
119
+ /**
120
+ * Render Powerline glyphs as vector shapes for pixel-perfect cell height.
121
+ * Powerline glyphs (U+E0B0-U+E0BF) are designed to span the full cell height,
122
+ * but font rendering often makes them slightly taller/shorter than the cell.
123
+ * Drawing them as paths ensures they exactly fill the cell bounds.
124
+ * Returns true if the character was handled, false if it should be rendered as text.
125
+ */
126
+ private renderPowerlineGlyph;
127
+ /**
128
+ * Composite all visible kitty graphics placements onto the canvas.
129
+ * Cheap when no graphics are active (one method check, one terminal_get).
130
+ * Decode work is amortized across frames via kittyImageCache.
131
+ */
132
+ /**
133
+ * Walk the placement iterator once at frame start, partitioning the
134
+ * results: virtual placements go into kittyVirtualPlacements (keyed
135
+ * by image id) for placeholder-cell lookup; direct visible placements
136
+ * stay implicit and get re-iterated by renderKittyImages later.
137
+ *
138
+ * Also caches the storage handle for renderPlaceholderCell so the
139
+ * per-cell hot path doesn't have to re-resolve it.
140
+ */
141
+ private precomputeKittyState;
142
+ /**
143
+ * Get (or decode + cache) the canvas-ready bitmap for a kitty image.
144
+ * Returns null if the image isn't stored or decode fails. Shared by
145
+ * renderKittyImages (direct placements) and renderPlaceholderCell
146
+ * (unicode-placeholder cells).
147
+ */
148
+ private getOrDecodeKittyImage;
149
+ /**
150
+ * Render a Block Elements codepoint (U+2580..U+259F) as fillRect(s) in
151
+ * the current fillStyle. Returns true if the codepoint is a handled
152
+ * block element; false to fall through to fillText.
153
+ *
154
+ * Drawing block elements through the font produces ~1-device-px gaps
155
+ * at cell edges at integer dpr because the rasterized glyph doesn't
156
+ * exactly fill the cell box. In half-block image renderings (ansimage,
157
+ * pixterm) those gaps line up into a visible cell grid. Native
158
+ * terminals draw block elements programmatically for the same reason.
159
+ *
160
+ * The eighths blocks (U+2581..U+2587 lower; U+2589..U+258F left) and
161
+ * full block (U+2588) are stripes of n/8 of the cell. Shading blocks
162
+ * (U+2591..U+2593) modulate globalAlpha for 25/50/75% fill. Quadrant
163
+ * blocks (U+2596..U+259F) split the cell into a 2x2 grid and fill
164
+ * some subset.
165
+ */
166
+ private renderBlockElement;
167
+ /**
168
+ * Substitute a cell's text rendering with a slice of a kitty graphics
169
+ * image. Called from renderCellText when the cell's codepoint is
170
+ * U+10EEEE.
171
+ *
172
+ * Decodes the image_id from cell.fg_* (low 24 bits; high byte from
173
+ * an optional third combining diacritic) and the row/col-of-image
174
+ * from the first two combining diacritics on the cell. Looks up the
175
+ * virtual placement (from precomputeKittyState) for grid dims, then
176
+ * draws the matching slice scaled to one terminal cell.
177
+ *
178
+ * Returns true if the cell was handled as a placeholder; false to
179
+ * fall through to normal text rendering (e.g., unknown image, no
180
+ * matching virtual placement, or malformed diacritics).
181
+ */
182
+ private renderPlaceholderCell;
183
+ private renderKittyImages;
184
+ /**
185
+ * Decode a kitty graphics image into a canvas suitable for drawImage.
186
+ * Expands non-RGBA formats into RGBA via putImageData; PNG payloads
187
+ * (which require a JS-side decoder set up via ghostty_sys_set) are
188
+ * not supported in this MVP and return null.
189
+ */
190
+ private decodeKittyImageToCanvas;
191
+ /**
192
+ * Render cursor
193
+ */
194
+ private renderCursor;
195
+ /**
196
+ * Set a callback the renderer invokes when its internal state changes
197
+ * outside the normal render-driven path (today: cursor-blink toggles).
198
+ * Lets an event-driven Terminal wake its render scheduler instead of
199
+ * polling every frame to catch the blink flip.
200
+ */
201
+ setOnRequestRender(fn: (() => void) | null): void;
202
+ private startCursorBlink;
203
+ private stopCursorBlink;
204
+ /**
205
+ * Update theme colors
206
+ */
207
+ setTheme(theme: ITheme): void;
208
+ /**
209
+ * Update font size
210
+ */
211
+ setFontSize(size: number): void;
212
+ /**
213
+ * Update font family
214
+ */
215
+ setFontFamily(family: string): void;
216
+ /**
217
+ * Update cursor style
218
+ */
219
+ setCursorStyle(style: 'block' | 'underline' | 'bar'): void;
220
+ /**
221
+ * Enable/disable cursor blinking
222
+ */
223
+ setCursorBlink(enabled: boolean): void;
224
+ /**
225
+ * Get current font metrics
226
+ */
227
+ /**
228
+ * Render scrollbar (Phase 2)
229
+ * Shows scroll position and allows click/drag interaction
230
+ * @param opacity Opacity level (0-1) for fade in/out effect
231
+ */
232
+ private renderScrollbar;
233
+ getMetrics(): FontMetrics;
234
+ /**
235
+ * Get canvas element (needed by SelectionManager)
236
+ */
237
+ getCanvas(): HTMLCanvasElement;
238
+ /**
239
+ * Set selection manager (for rendering selection)
240
+ */
241
+ setSelectionManager(manager: SelectionManager): void;
242
+ /**
243
+ * Check if a cell at (x, y) is within the current selection.
244
+ * Uses cached selection coordinates for performance.
245
+ */
246
+ private isInSelection;
247
+ /**
248
+ * Set the currently hovered hyperlink ID for rendering underlines
249
+ */
250
+ setHoveredHyperlinkId(hyperlinkId: number): void;
251
+ /**
252
+ * Set the currently hovered link range for rendering underlines (for regex-detected URLs)
253
+ * Pass null to clear the hover state
254
+ */
255
+ setHoveredLinkRange(range: {
256
+ startX: number;
257
+ startY: number;
258
+ endX: number;
259
+ endY: number;
260
+ } | null): void;
261
+ /**
262
+ * Get character cell width (for coordinate conversion)
263
+ */
264
+ get charWidth(): number;
265
+ /**
266
+ * Get character cell height (for coordinate conversion)
267
+ */
268
+ get charHeight(): number;
269
+ /**
270
+ * Clear entire canvas
271
+ */
272
+ clear(): void;
273
+ /**
274
+ * Cleanup resources
275
+ */
276
+ dispose(): void;
277
+ }
278
+
279
+ /**
280
+ * Cell style flags (bitfield)
281
+ */
282
+ export declare enum CellFlags {
283
+ BOLD = 1,
284
+ ITALIC = 2,
285
+ UNDERLINE = 4,
286
+ STRIKETHROUGH = 8,
287
+ INVERSE = 16,
288
+ INVISIBLE = 32,
289
+ BLINK = 64,
290
+ FAINT = 128
291
+ }
292
+
293
+ /**
294
+ * Cursor position and visibility
295
+ */
296
+ export declare interface Cursor {
297
+ x: number;
298
+ y: number;
299
+ visible: boolean;
300
+ }
301
+
302
+ /**
303
+ * Dirty state from RenderState. Mirrors GhosttyRenderStateDirty.
304
+ */
305
+ export declare enum DirtyState {
306
+ NONE = 0,
307
+ PARTIAL = 1,
308
+ FULL = 2
309
+ }
310
+
311
+ export declare class EventEmitter<T> {
312
+ private listeners;
313
+ fire(arg: T): void;
314
+ event: IEvent<T>;
315
+ dispose(): void;
316
+ }
317
+
318
+ export declare class FitAddon implements ITerminalAddon {
319
+ private _terminal?;
320
+ private _resizeObserver?;
321
+ private _resizeDebounceTimer?;
322
+ private _lastCols?;
323
+ private _lastRows?;
324
+ private _isResizing;
325
+ /**
326
+ * Activate the addon (called by Terminal.loadAddon)
327
+ */
328
+ activate(terminal: ITerminalCore): void;
329
+ /**
330
+ * Dispose the addon and clean up resources
331
+ */
332
+ dispose(): void;
333
+ /**
334
+ * Fit the terminal to its container
335
+ *
336
+ * Calculates optimal dimensions and resizes the terminal.
337
+ * Does nothing if dimensions cannot be calculated or haven't changed.
338
+ */
339
+ fit(): void;
340
+ /**
341
+ * Propose dimensions to fit the terminal to its container
342
+ *
343
+ * Calculates cols and rows based on:
344
+ * - Terminal container element dimensions (clientWidth/Height)
345
+ * - Terminal element padding
346
+ * - Font metrics (character cell size)
347
+ * - Scrollbar width reservation
348
+ *
349
+ * @returns Proposed dimensions or undefined if cannot calculate
350
+ */
351
+ proposeDimensions(): ITerminalDimensions | undefined;
352
+ /**
353
+ * Observe the terminal's container for resize events
354
+ *
355
+ * Sets up a ResizeObserver to automatically call fit() when the
356
+ * container size changes. Resize events are debounced to avoid
357
+ * excessive calls during window drag operations.
358
+ *
359
+ * Call dispose() to stop observing.
360
+ */
361
+ observeResize(): void;
362
+ }
363
+
364
+ export declare interface FontMetrics {
365
+ width: number;
366
+ height: number;
367
+ baseline: number;
368
+ }
369
+
370
+ /* Excluded from this release type: getGhostty */
371
+
372
+ /**
373
+ * Main Ghostty WASM wrapper class
374
+ */
375
+ export declare class Ghostty {
376
+ private exports;
377
+ private memory;
378
+ constructor(wasmInstance: WebAssembly.Instance);
379
+ createKeyEncoder(): KeyEncoder;
380
+ createTerminal(cols?: number, rows?: number, config?: GhosttyTerminalConfig): GhosttyTerminal;
381
+ static load(wasmPath?: string): Promise<Ghostty>;
382
+ private static loadFromPath;
383
+ }
384
+
385
+ /**
386
+ * Cell structure matching ghostty_cell_t in C (16 bytes)
387
+ */
388
+ export declare interface GhosttyCell {
389
+ codepoint: number;
390
+ fg_r: number;
391
+ fg_g: number;
392
+ fg_b: number;
393
+ bg_r: number;
394
+ bg_g: number;
395
+ bg_b: number;
396
+ fgIsDefault: boolean;
397
+ bgIsDefault: boolean;
398
+ flags: number;
399
+ width: number;
400
+ hyperlink_id: number;
401
+ grapheme_len: number;
402
+ }
403
+
404
+ /**
405
+ * GhosttyTerminal - High-performance terminal emulator
406
+ *
407
+ * Uses Ghostty's native RenderState for optimal performance:
408
+ * - ONE call to update all state (renderStateUpdate)
409
+ * - ONE call to get all cells (getViewport)
410
+ * - No per-row WASM boundary crossings!
411
+ */
412
+ export declare class GhosttyTerminal {
413
+ private exports;
414
+ private memory;
415
+ private handle;
416
+ private renderHandle;
417
+ private rowIter;
418
+ private rowCells;
419
+ private _cols;
420
+ private _rows;
421
+ /** Cell pool for zero-allocation rendering */
422
+ private cellPool;
423
+ /**
424
+ * Cell pixel dimensions last pushed to the WASM terminal via
425
+ * ghostty_terminal_resize. Zero means "unknown / disabled" — kitty
426
+ * graphics image sizing and CSI 14/16/18 t in-band size reports will
427
+ * return zero/no-op until setCellPixelSize() is called with real values.
428
+ */
429
+ private cellWidthPx;
430
+ private cellHeightPx;
431
+ /**
432
+ * Per-row dirty state for the current render-state snapshot. Cleared on
433
+ * update() and populated lazily by isRowDirty() (or as a side effect of
434
+ * getViewport, which iterates rows anyway).
435
+ */
436
+ private rowDirtyCache;
437
+ /**
438
+ * Per-row soft-wrap state for the current render-state snapshot. Same
439
+ * lifecycle as rowDirtyCache; the two caches are filled in lockstep.
440
+ */
441
+ private rowWrapCache;
442
+ /**
443
+ * Whether cellPool currently holds a valid built viewport.
444
+ *
445
+ * The visible-screen content is a pure function of the WASM terminal state,
446
+ * which only changes via write() (all VT sequences — text, scroll, clear,
447
+ * alt-screen switch) or resize(). So once getViewport() has walked the grid
448
+ * and populated cellPool, the result stays valid until the next write/resize
449
+ * — letting repeated getViewport()/getLine() calls within (and across, when
450
+ * idle) a render pass reuse the pool instead of re-walking it (~3-4 WASM
451
+ * crossings per cell). Cursor blink, selection overlays and scrollback
452
+ * paging don't read cellPool, so they don't invalidate it.
453
+ */
454
+ private viewportValid;
455
+ /**
456
+ * Bytes the terminal would have written back to a real PTY in response
457
+ * to query sequences (DSR, XTVERSION, in-band size reports, ...).
458
+ * Captured by the WRITE_PTY callback installed in the constructor and
459
+ * drained by readResponse(). Each slot is one callback invocation, so
460
+ * a single response sequence may span multiple slots.
461
+ */
462
+ private pendingResponses;
463
+ /**
464
+ * Per-table registry for callback trampolines. Keyed on the WASM
465
+ * module's __indirect_function_table so that multiple Ghostty.load()
466
+ * instances each get their own trampoline slots and routing map —
467
+ * terminal handles are only unique within a single WASM instance, and
468
+ * indices into one module's table are meaningless in another.
469
+ *
470
+ * One trampoline pair (write_pty + size) is installed per table; their
471
+ * slot indices live here alongside the routing map. The dispatchers
472
+ * close over the same instancesByHandle so any GhosttyTerminal coming
473
+ * from this WASM module routes correctly.
474
+ */
475
+ private static callbackRegistries;
476
+ /**
477
+ * Cached pointer to this terminal's registry. We only need it to
478
+ * deregister cleanly in free() / cleanupOnConstructorFailure().
479
+ */
480
+ private callbackRegistry?;
481
+ constructor(exports: GhosttyWasmExports, memory: WebAssembly.Memory, cols?: number, rows?: number, config?: GhosttyTerminalConfig);
482
+ /**
483
+ * Allocate an opaque handle through one of the new(allocator, *outHandle)
484
+ * factory functions. Wraps the boilerplate of: alloc out-pointer, call
485
+ * factory, check Result, read the handle, free out-pointer.
486
+ *
487
+ * If the factory call fails, frees any already-acquired terminal/render
488
+ * resources so the caller-throwing flow doesn't leak across the partially
489
+ * constructed object.
490
+ */
491
+ private allocOpaqueOrFail;
492
+ /**
493
+ * Apply user-supplied colors + palette overrides to the freshly-created
494
+ * terminal via ghostty_terminal_set(COLOR_*).
495
+ *
496
+ * For the palette: the new C ABI takes a full 256-entry array, but coder's
497
+ * config carries only the legacy 16 ANSI entries (each as a 0xRRGGBB int,
498
+ * 0 meaning "use default"). To preserve indices ≥16 we read the existing
499
+ * default palette first, overlay the non-zero entries from config, and
500
+ * write the merged 768-byte buffer back.
501
+ */
502
+ private applyConfig;
503
+ private setColorOption;
504
+ /**
505
+ * Release any resources that have been allocated by the constructor up to
506
+ * this point. Called when a subsequent step fails so we don't leak handles
507
+ * before the throw propagates.
508
+ */
509
+ private cleanupOnConstructorFailure;
510
+ private rsGetU8;
511
+ private rsGetU16;
512
+ private rsGetU32;
513
+ private rsGetRgb;
514
+ private tGetU8;
515
+ private tGetU32;
516
+ get cols(): number;
517
+ get rows(): number;
518
+ write(data: string | Uint8Array): void;
519
+ resize(cols: number, rows: number): void;
520
+ /**
521
+ * Set the maximum bytes of image data the terminal will retain across
522
+ * all kitty graphics images. Zero disables kitty graphics entirely
523
+ * (transmissions will be parsed and dropped). Set this BEFORE any
524
+ * image-bearing data is written to the terminal — there's no
525
+ * retroactive recovery of dropped images.
526
+ *
527
+ * Input is uint64_t* on the C side, so we use a u32-pair little-endian
528
+ * write to keep the byte count exact even past 4GB (probably overkill
529
+ * but free).
530
+ */
531
+ setKittyImageStorageLimit(bytes: number): void;
532
+ /**
533
+ * Get the kitty graphics storage handle for the active screen, or null
534
+ * if storage is disabled or no images are stored. Cheap to call; returns
535
+ * a borrowed pointer.
536
+ */
537
+ getKittyGraphics(): number | null;
538
+ /**
539
+ * Iterate placements in the active screen, yielding render-ready info
540
+ * for each. The optional `onlyVisible` flag (default true) drops
541
+ * placements that don't intersect the viewport — most renderers want
542
+ * this. Use `false` if you need to track invalidated regions for
543
+ * partial damage.
544
+ *
545
+ * Internally this uses the upstream placement iterator + the one-shot
546
+ * placement_render_info call (fills 12 fields in one WASM crossing
547
+ * instead of 5 separate getters).
548
+ */
549
+ iterPlacements(graphics: number, onlyVisible?: boolean): Generator<KittyPlacementInfo>;
550
+ /**
551
+ * Get the pixel data + metadata for an image by id. Returns null if the
552
+ * image isn't stored or isn't in a format we can hand the renderer
553
+ * directly (RGB / RGBA / GRAY / GRAY_ALPHA).
554
+ *
555
+ * The returned `data` is a borrowed view into WASM memory — copy before
556
+ * the next vt_write if you need to retain. Most callers will turn this
557
+ * into an ImageData / canvas immediately and discard the view.
558
+ */
559
+ getKittyImagePixels(graphics: number, imageId: number): KittyImagePixels | null;
560
+ /**
561
+ * Push the renderer's per-cell pixel size into the WASM terminal.
562
+ *
563
+ * The new C ABI doesn't expose a separate "set pixel size" call —
564
+ * dimensions only flow through ghostty_terminal_resize, which takes
565
+ * (cols, rows, cell_width_px, cell_height_px). We cache the cell pixel
566
+ * dims on the instance so subsequent resize() calls keep the values
567
+ * stable, and short-circuit when nothing has changed.
568
+ *
569
+ * The width/height arguments are PER-CELL CSS pixels — matches what
570
+ * the renderer reports via getMetrics(). Coder's old setPixelSize
571
+ * took TOTAL screen pixels (cell_width * cols, cell_height * rows);
572
+ * we renamed to avoid silent value mis-passing.
573
+ *
574
+ * Affects in-band size reports (CSI 14/16/18 t) and kitty graphics
575
+ * placement sizing. Until called, those query paths return zero.
576
+ */
577
+ setCellPixelSize(cellWidthPx: number, cellHeightPx: number): void;
578
+ free(): void;
579
+ /**
580
+ * Update terminal colors at runtime. All color values are applied directly
581
+ * (no sentinel — 0x000000 is valid black). Forces a full redraw on next render.
582
+ *
583
+ * Uses the same ghostty_terminal_set(COLOR_*) path as applyConfig; this
584
+ * is the runtime variant called by Terminal.setTheme().
585
+ */
586
+ setColors(config: GhosttyTerminalConfig): void;
587
+ /**
588
+ * Update render state from terminal.
589
+ *
590
+ * This syncs the RenderState with the current Terminal state.
591
+ * The dirty state (full/partial/none) is stored in the WASM RenderState
592
+ * and can be queried via isRowDirty(). When dirty==full, isRowDirty()
593
+ * returns true for ALL rows.
594
+ *
595
+ * The WASM layer automatically detects screen switches (normal <-> alternate)
596
+ * and returns FULL dirty state when switching screens (e.g., vim exit).
597
+ *
598
+ * Safe to call multiple times - dirty state persists until markClean().
599
+ */
600
+ update(): DirtyState;
601
+ /**
602
+ * Get cursor state from render state.
603
+ * Calls update() first; safe to call repeatedly within a frame.
604
+ */
605
+ getCursor(): RenderStateCursor;
606
+ /**
607
+ * Get default fg/bg/cursor colors from render state.
608
+ */
609
+ getColors(): RenderStateColors;
610
+ /**
611
+ * Check if a specific row is dirty.
612
+ *
613
+ * Backed by a per-row cache populated lazily — first call after update()
614
+ * walks the iterator once and reads the dirty flag for each row, then
615
+ * subsequent calls are O(1). getViewport() also populates the cache as a
616
+ * side effect so a typical "update → for-each-row isRowDirty → getViewport"
617
+ * render loop only iterates rows once.
618
+ */
619
+ isRowDirty(y: number): boolean;
620
+ /**
621
+ * Check if a row is soft-wrapped (continues onto the next row).
622
+ *
623
+ * Same cache discipline as isRowDirty: lazy-populated on first call after
624
+ * update(), or as a side effect of getViewport.
625
+ */
626
+ isRowWrapped(y: number): boolean;
627
+ /**
628
+ * Walk the row iterator once and capture per-row dirty + wrap flags.
629
+ *
630
+ * Calls update() first since callers (isRowDirty / isRowWrapped) typically
631
+ * query right after a terminal write, before any explicit render-state
632
+ * refresh has happened. Same idempotency guarantee as getCursor/getColors:
633
+ * if no terminal change occurred since the last update, this is cheap.
634
+ *
635
+ * Reads ROW_DATA_DIRTY directly from the iterator, then ROW_DATA_RAW to
636
+ * obtain the GhosttyRow (u64) needed to call ghostty_row_get(WRAP_*). The
637
+ * row value is only valid for the current iterator position; we read it
638
+ * inline before advancing.
639
+ */
640
+ private refreshRowMetaCache;
641
+ /**
642
+ * Mark render state as clean — clears both global and per-row dirty.
643
+ *
644
+ * Per the upstream contract, "setting one dirty state doesn't unset the
645
+ * other." Global dirty is cleared via _set(OPTION_DIRTY, FALSE); per-row
646
+ * dirty is cleared by walking the row iterator and calling _row_set on
647
+ * each. Without the per-row pass, the next update() would still report
648
+ * the old per-row flags as dirty even though the terminal hasn't changed.
649
+ */
650
+ markClean(): void;
651
+ /**
652
+ * Populate the cellPool from the current render state and return it.
653
+ *
654
+ * The new C ABI replaces coder's single ghostty_render_state_get_viewport()
655
+ * buffer-fill with a row iterator + per-row cells iterator. We allocate
656
+ * both iterators once at construction time and re-populate them per call:
657
+ *
658
+ * _get(state, ROW_ITERATOR, &rowIter)
659
+ * while (row_iterator_next(rowIter)) {
660
+ * _row_get(rowIter, ROW_DATA_CELLS, &rowCells)
661
+ * while (row_cells_next(rowCells)) {
662
+ * _row_cells_get(rowCells, GRAPHEMES_LEN, &len)
663
+ * _row_cells_get(rowCells, GRAPHEMES_BUF, &codepoint) // if len > 0
664
+ * _row_cells_get(rowCells, FG_COLOR/BG_COLOR, &rgb) // INVALID_VALUE if unset
665
+ * }
666
+ * }
667
+ *
668
+ * This is intentionally minimal: we capture codepoint + fg/bg only.
669
+ * Style flags, cell width (double-width), and hyperlink IDs are deferred
670
+ * — they require parsing the GhosttyStyle sized struct and the per-cell
671
+ * ghostty_cell_get(WIDE)/HAS_HYPERLINK paths. The cellPool fields keep
672
+ * placeholder defaults (flags=0, width=1, hyperlink_id=0).
673
+ *
674
+ * Performance: ~3-4 WASM crossings per visible cell. For an 80x24 viewport
675
+ * that's ~6k crossings per frame. Profile before optimizing — likely
676
+ * candidates are _row_cells_get_multi for batched reads, or RAW + a
677
+ * cached layout map for direct memory access.
678
+ */
679
+ getViewport(): GhosttyCell[];
680
+ /**
681
+ * Helper for the in/out pointer pattern used by ROW_ITERATOR / ROW_DATA_CELLS:
682
+ * write a handle into a 4-byte slot, hand the slot to a populator, then
683
+ * free the slot. The handle value itself is unchanged; the populator uses
684
+ * it to find and rebind the iterator's internal data.
685
+ */
686
+ private populateHandle;
687
+ /**
688
+ * Reset every cell in the pool to "empty" so cells we don't visit during
689
+ * iteration (e.g. iterator stopped early, or grid resized down) don't
690
+ * carry stale values from a previous frame.
691
+ */
692
+ private zeroCellPool;
693
+ /**
694
+ * Get line - for compatibility, extracts from viewport.
695
+ * Ensures render state is fresh by calling update().
696
+ * Returns a COPY of the cells to avoid pool reference issues.
697
+ */
698
+ getLine(y: number): GhosttyCell[] | null;
699
+ /** For compatibility with old API */
700
+ isDirty(): boolean;
701
+ /**
702
+ * Check if a full redraw is needed (screen change, resize, etc.)
703
+ * Note: This calls update() to ensure fresh state. Safe to call multiple times.
704
+ */
705
+ needsFullRedraw(): boolean;
706
+ /** Mark render state as clean after rendering */
707
+ clearDirty(): void;
708
+ isAlternateScreen(): boolean;
709
+ hasBracketedPaste(): boolean;
710
+ hasFocusEvents(): boolean;
711
+ hasMouseTracking(): boolean;
712
+ /** Get dimensions - for compatibility */
713
+ getDimensions(): {
714
+ cols: number;
715
+ rows: number;
716
+ };
717
+ /** Get number of scrollback lines (history, not including active screen) */
718
+ getScrollbackLength(): number;
719
+ /**
720
+ * Get a line from the scrollback buffer.
721
+ * @param offset 0 = oldest scrollback line, (scrollbackLength-1) = most
722
+ * recent scrollback line.
723
+ *
724
+ * Uses ghostty_terminal_grid_ref with POINT_TAG_HISTORY to address rows
725
+ * outside the active viewport. The render-state row iterator only walks
726
+ * the viewport, so scrollback access has to go through grid_ref.
727
+ *
728
+ * Cell content is currently codepoint-only; fg/bg colors, style flags,
729
+ * and hyperlinks are deferred (defaults: 0 colors, flags=0, width=1).
730
+ * The text-extraction tests that drove this commit only check codepoints.
731
+ */
732
+ getScrollbackLine(offset: number): GhosttyCell[] | null;
733
+ /**
734
+ * Get the hyperlink URI for a cell at the given position in the active
735
+ * viewport. Returns null when no hyperlink is attached.
736
+ */
737
+ getHyperlinkUri(row: number, col: number): string | null;
738
+ /**
739
+ * Get the hyperlink URI for a cell in the scrollback buffer.
740
+ */
741
+ getScrollbackHyperlinkUri(offset: number, col: number): string | null;
742
+ private readGridLine;
743
+ /**
744
+ * Decode a GhosttyStyleColor (16 bytes at colorPtr — tag@0:u32,
745
+ * value@8:union) and write the resolved RGB into the cell's fg_*
746
+ * or bg_* triple. Tag values: NONE=0 (leaves zeros so the renderer's
747
+ * theme fallback kicks in), PALETTE=1 (looks up the terminal's
748
+ * effective palette), RGB=2 (direct read).
749
+ */
750
+ private resolveStyleColor;
751
+ private readHyperlinkUri;
752
+ private allocPoint;
753
+ private makeEmptyCell;
754
+ /**
755
+ * Whether any terminal response bytes are queued for readResponse().
756
+ *
757
+ * Responses are delivered synchronously during vt_write() by the
758
+ * WRITE_PTY callback (e.g. DSR replies, XTVERSION, in-band size reports).
759
+ * They sit in pendingResponses until drained.
760
+ */
761
+ hasResponse(): boolean;
762
+ /**
763
+ * Drain queued response bytes, decode as UTF-8, return as a single
764
+ * string. Multiple callback invocations are concatenated. Returns null
765
+ * when nothing's pending so the demo's echo loop can short-circuit.
766
+ */
767
+ readResponse(): string | null;
768
+ /**
769
+ * Install the WRITE_PTY and SIZE trampoline callbacks.
770
+ *
771
+ * Trampolines are shared across all terminals that come from the
772
+ * same WASM instance, but NOT across instances — terminal handles are
773
+ * only unique within their parent module, and table indices in module
774
+ * A are meaningless in module B's table. So we keep a per-table
775
+ * registry (WeakMap keyed on the indirect function table) that owns
776
+ * the slot indices plus the handle→instance routing map for that
777
+ * table.
778
+ *
779
+ * On first use for a given table we instantiate the trampolines,
780
+ * `table.grow(2)`, and write both into the new slots. Subsequent
781
+ * terminals from the same module reuse the registry and just
782
+ * register their handle in instancesByHandle.
783
+ */
784
+ private installCallbacks;
785
+ /**
786
+ * Query arbitrary terminal mode by number.
787
+ * @param mode Mode number (e.g., 25 for cursor visibility, 2004 for bracketed paste)
788
+ * @param isAnsi True for ANSI modes, false for DEC modes (default: false)
789
+ */
790
+ getMode(mode: number, isAnsi?: boolean): boolean;
791
+ private initCellPool;
792
+ /**
793
+ * Get all codepoints for a grapheme cluster at the given position.
794
+ * For most cells this returns a single codepoint, but for complex scripts
795
+ * (Hindi, emoji with ZWJ, etc.) it returns multiple codepoints.
796
+ * @returns Array of codepoints, or null on error
797
+ */
798
+ getGrapheme(row: number, col: number): number[] | null;
799
+ /**
800
+ * Get a string representation of the grapheme at the given position.
801
+ * This properly handles complex scripts like Hindi, emoji with ZWJ, etc.
802
+ */
803
+ getGraphemeString(row: number, col: number): string;
804
+ /**
805
+ * Get all codepoints for a grapheme cluster in the scrollback buffer.
806
+ * @param offset Scrollback line offset (0 = oldest)
807
+ * @param col Column index
808
+ * @returns Array of codepoints, or null on error
809
+ */
810
+ getScrollbackGrapheme(offset: number, col: number): number[] | null;
811
+ /**
812
+ * Get a string representation of a grapheme in the scrollback buffer.
813
+ */
814
+ getScrollbackGraphemeString(offset: number, col: number): string;
815
+ }
816
+
817
+ /**
818
+ * Terminal configuration (passed to ghostty_terminal_new_with_config)
819
+ * All color values use 0xRRGGBB format. A value of 0 means "use default".
820
+ */
821
+ declare interface GhosttyTerminalConfig {
822
+ /** Scrollback buffer size in bytes. Passed to Terminal.max_scrollback. */
823
+ scrollbackLimit?: number;
824
+ fgColor?: number;
825
+ bgColor?: number;
826
+ cursorColor?: number;
827
+ palette?: number[];
828
+ }
829
+
830
+ /**
831
+ * Interface for libghostty-vt WASM exports
832
+ */
833
+ declare interface GhosttyWasmExports extends WebAssembly.Exports {
834
+ memory: WebAssembly.Memory;
835
+ ghostty_wasm_alloc_opaque(): number;
836
+ ghostty_wasm_free_opaque(ptr: number): void;
837
+ ghostty_wasm_alloc_u8_array(len: number): number;
838
+ ghostty_wasm_free_u8_array(ptr: number, len: number): void;
839
+ ghostty_wasm_alloc_u16_array(len: number): number;
840
+ ghostty_wasm_free_u16_array(ptr: number, len: number): void;
841
+ ghostty_wasm_alloc_u8(): number;
842
+ ghostty_wasm_free_u8(ptr: number): void;
843
+ ghostty_wasm_alloc_usize(): number;
844
+ ghostty_wasm_free_usize(ptr: number): void;
845
+ ghostty_sgr_new(allocator: number, parserPtrPtr: number): number;
846
+ ghostty_sgr_free(parser: number): void;
847
+ ghostty_sgr_reset(parser: number): void;
848
+ ghostty_sgr_set_params(parser: number, paramsPtr: number, subsPtr: number, paramsLen: number): number;
849
+ ghostty_sgr_next(parser: number, attrPtr: number): boolean;
850
+ ghostty_sgr_attribute_tag(attrPtr: number): number;
851
+ ghostty_sgr_attribute_value(attrPtr: number, tagPtr: number): number;
852
+ ghostty_wasm_alloc_sgr_attribute(): number;
853
+ ghostty_wasm_free_sgr_attribute(ptr: number): void;
854
+ ghostty_key_encoder_new(allocator: number, encoderPtrPtr: number): number;
855
+ ghostty_key_encoder_free(encoder: number): void;
856
+ ghostty_key_encoder_setopt(encoder: number, option: number, valuePtr: number): number;
857
+ ghostty_key_encoder_encode(encoder: number, eventPtr: number, bufPtr: number, bufLen: number, writtenPtr: number): number;
858
+ ghostty_key_event_new(allocator: number, eventPtrPtr: number): number;
859
+ ghostty_key_event_free(event: number): void;
860
+ ghostty_key_event_set_action(event: number, action: number): void;
861
+ ghostty_key_event_set_key(event: number, key: number): void;
862
+ ghostty_key_event_set_mods(event: number, mods: number): void;
863
+ ghostty_key_event_set_utf8(event: number, ptr: number, len: number): void;
864
+ ghostty_terminal_new(allocatorPtr: number, terminalPtrPtr: number, optionsPtr: number): number;
865
+ ghostty_terminal_free(terminal: TerminalHandle): void;
866
+ ghostty_terminal_resize(terminal: TerminalHandle, cols: number, rows: number, cellWidthPx: number, cellHeightPx: number): number;
867
+ ghostty_terminal_vt_write(terminal: TerminalHandle, dataPtr: number, dataLen: number): void;
868
+ ghostty_render_state_new(allocatorPtr: number, statePtrPtr: number): number;
869
+ ghostty_render_state_free(state: number): void;
870
+ ghostty_render_state_update(state: number, terminal: TerminalHandle): number;
871
+ ghostty_render_state_get(state: number, key: number, outPtr: number): number;
872
+ ghostty_render_state_get_multi(state: number, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
873
+ ghostty_render_state_set(state: number, option: number, valuePtr: number): number;
874
+ ghostty_render_state_colors_get(state: number, outColorsPtr: number): number;
875
+ ghostty_render_state_row_iterator_new(allocatorPtr: number, outIterPtrPtr: number): number;
876
+ ghostty_render_state_row_iterator_free(iter: number): void;
877
+ ghostty_render_state_row_iterator_next(iter: number): boolean;
878
+ ghostty_render_state_row_get(iter: number, key: number, outPtr: number): number;
879
+ ghostty_render_state_row_set(iter: number, option: number, valuePtr: number): number;
880
+ ghostty_render_state_row_cells_new(allocatorPtr: number, outCellsPtrPtr: number): number;
881
+ ghostty_render_state_row_cells_free(cells: number): void;
882
+ ghostty_render_state_row_cells_next(cells: number): boolean;
883
+ ghostty_render_state_row_cells_select(cells: number, col: number): number;
884
+ ghostty_render_state_row_cells_get(cells: number, key: number, outPtr: number): number;
885
+ ghostty_render_state_row_cells_get_multi(cells: number, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
886
+ ghostty_cell_get(cell: bigint, key: number, outPtr: number): number;
887
+ ghostty_row_get(row: bigint, key: number, outPtr: number): number;
888
+ ghostty_terminal_grid_ref(terminal: TerminalHandle, pointPtr: number, outRefPtr: number): number;
889
+ ghostty_grid_ref_cell(refPtr: number, outCellPtr: number): number;
890
+ ghostty_grid_ref_row(refPtr: number, outRowPtr: number): number;
891
+ ghostty_grid_ref_graphemes(refPtr: number, bufPtr: number, bufLen: number, outLenPtr: number): number;
892
+ ghostty_grid_ref_hyperlink_uri(refPtr: number, bufPtr: number, bufLen: number, outLenPtr: number): number;
893
+ ghostty_grid_ref_style(refPtr: number, outStylePtr: number): number;
894
+ ghostty_kitty_graphics_get(graphics: number, key: number, outPtr: number): number;
895
+ ghostty_kitty_graphics_image(graphics: number, imageId: number): number;
896
+ ghostty_kitty_graphics_image_get(image: number, key: number, outPtr: number): number;
897
+ ghostty_kitty_graphics_image_get_multi(image: number, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
898
+ ghostty_kitty_graphics_placement_iterator_new(allocatorPtr: number, outIterPtrPtr: number): number;
899
+ ghostty_kitty_graphics_placement_iterator_free(iter: number): void;
900
+ ghostty_kitty_graphics_placement_iterator_set(iter: number, option: number, valuePtr: number): number;
901
+ ghostty_kitty_graphics_placement_next(iter: number): boolean;
902
+ ghostty_kitty_graphics_placement_get(iter: number, key: number, outPtr: number): number;
903
+ ghostty_kitty_graphics_placement_get_multi(iter: number, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
904
+ ghostty_kitty_graphics_placement_rect(iter: number, image: number, terminal: TerminalHandle, outSelectionPtr: number): number;
905
+ ghostty_kitty_graphics_placement_pixel_size(iter: number, image: number, terminal: TerminalHandle, outWidthPtr: number, outHeightPtr: number): number;
906
+ ghostty_kitty_graphics_placement_grid_size(iter: number, image: number, terminal: TerminalHandle, outColsPtr: number, outRowsPtr: number): number;
907
+ ghostty_kitty_graphics_placement_viewport_pos(iter: number, image: number, terminal: TerminalHandle, outColPtr: number, outRowPtr: number): number;
908
+ ghostty_kitty_graphics_placement_source_rect(iter: number, image: number, outX: number, outY: number, outW: number, outH: number): number;
909
+ ghostty_kitty_graphics_placement_render_info(iter: number, image: number, terminal: TerminalHandle, outInfoPtr: number): number;
910
+ ghostty_terminal_get(terminal: TerminalHandle, key: number, outPtr: number): number;
911
+ ghostty_terminal_get_multi(terminal: TerminalHandle, count: number, keysPtr: number, valuesPtr: number, outWrittenPtr: number): number;
912
+ ghostty_terminal_set(terminal: TerminalHandle, option: number, valuePtr: number): number;
913
+ ghostty_sys_set(option: number, valuePtr: number): number;
914
+ ghostty_alloc(allocatorPtr: number, len: number): number;
915
+ ghostty_free(allocatorPtr: number, ptr: number, len: number): void;
916
+ ghostty_terminal_mode_get(terminal: TerminalHandle, mode: number, outBoolPtr: number): number;
917
+ ghostty_terminal_mode_set(terminal: TerminalHandle, mode: number, value: boolean): number;
918
+ }
919
+
920
+ /**
921
+ * A terminal buffer (normal or alternate screen)
922
+ */
923
+ export declare interface IBuffer {
924
+ /** Buffer type: 'normal' or 'alternate' */
925
+ readonly type: 'normal' | 'alternate';
926
+ /** Cursor X position (0-indexed) */
927
+ readonly cursorX: number;
928
+ /** Cursor Y position (0-indexed, relative to viewport) */
929
+ readonly cursorY: number;
930
+ /** Viewport Y position (scroll offset, 0 = bottom of scrollback) */
931
+ readonly viewportY: number;
932
+ /** Base Y position (always 0 for normal buffer, may vary for alternate) */
933
+ readonly baseY: number;
934
+ /** Total buffer length (rows + scrollback for normal, just rows for alternate) */
935
+ readonly length: number;
936
+ /**
937
+ * Get a line from the buffer
938
+ * @param y Line index (0 = top of scrollback for normal buffer)
939
+ * @returns Line object or undefined if out of bounds
940
+ */
941
+ getLine(y: number): IBufferLine | undefined;
942
+ /**
943
+ * Get the null cell (used for empty/uninitialized cells)
944
+ */
945
+ getNullCell(): IBufferCell;
946
+ }
947
+
948
+ /**
949
+ * A single cell in the buffer
950
+ */
951
+ export declare interface IBufferCell {
952
+ /** Character(s) in this cell (may be empty, single char, or emoji) */
953
+ getChars(): string;
954
+ /** Unicode codepoint (0 for null cell) */
955
+ getCode(): number;
956
+ /** Character width (1 = normal, 2 = wide/emoji, 0 = combining) */
957
+ getWidth(): number;
958
+ /** Foreground color index (for palette colors) or -1 for RGB */
959
+ getFgColorMode(): number;
960
+ /** Background color index (for palette colors) or -1 for RGB */
961
+ getBgColorMode(): number;
962
+ /** Foreground RGB color (or 0 for default) */
963
+ getFgColor(): number;
964
+ /** Background RGB color (or 0 for default) */
965
+ getBgColor(): number;
966
+ /** Whether cell has bold style */
967
+ isBold(): number;
968
+ /** Whether cell has italic style */
969
+ isItalic(): number;
970
+ /** Whether cell has underline style */
971
+ isUnderline(): number;
972
+ /** Whether cell has strikethrough style */
973
+ isStrikethrough(): number;
974
+ /** Whether cell has blink style */
975
+ isBlink(): number;
976
+ /** Whether cell has inverse video style */
977
+ isInverse(): number;
978
+ /** Whether cell has invisible style */
979
+ isInvisible(): number;
980
+ /** Whether cell has faint/dim style */
981
+ isFaint(): number;
982
+ /** Get hyperlink ID for this cell (0 = no link) */
983
+ getHyperlinkId(): number;
984
+ /** Get the Unicode codepoint for this cell */
985
+ getCodepoint(): number;
986
+ /** Whether cell has dim/faint attribute (boolean version) */
987
+ isDim(): boolean;
988
+ }
989
+
990
+ /**
991
+ * Represents a coordinate in the terminal buffer
992
+ */
993
+ export declare interface IBufferCellPosition {
994
+ x: number;
995
+ y: number;
996
+ }
997
+
998
+ /**
999
+ * A single line in the buffer
1000
+ */
1001
+ export declare interface IBufferLine {
1002
+ /** Length of the line (in columns) */
1003
+ readonly length: number;
1004
+ /** Whether this line wraps to the next line */
1005
+ readonly isWrapped: boolean;
1006
+ /**
1007
+ * Get a cell from this line
1008
+ * @param x Column index (0-indexed)
1009
+ * @returns Cell object or undefined if out of bounds
1010
+ */
1011
+ getCell(x: number): IBufferCell | undefined;
1012
+ /**
1013
+ * Translate the line to a string
1014
+ * @param trimRight Whether to trim trailing whitespace (default: false)
1015
+ * @param startColumn Start column (default: 0)
1016
+ * @param endColumn End column (default: length)
1017
+ * @returns String representation of the line
1018
+ */
1019
+ translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
1020
+ }
1021
+
1022
+ /**
1023
+ * Minimal buffer line interface for URL detection
1024
+ */
1025
+ declare interface IBufferLineForUrlProvider {
1026
+ length: number;
1027
+ getCell(x: number): {
1028
+ getCodepoint(): number;
1029
+ } | undefined;
1030
+ }
1031
+
1032
+ /**
1033
+ * Top-level buffer API namespace
1034
+ * Provides access to active, normal, and alternate screen buffers
1035
+ */
1036
+ export declare interface IBufferNamespace {
1037
+ /** The currently active buffer (normal or alternate) */
1038
+ readonly active: IBuffer;
1039
+ /** The normal buffer (primary screen) */
1040
+ readonly normal: IBuffer;
1041
+ /** The alternate buffer (used by full-screen apps like vim) */
1042
+ readonly alternate: IBuffer;
1043
+ /** Event fired when buffer changes (normal ↔ alternate) */
1044
+ readonly onBufferChange: IEvent<IBuffer>;
1045
+ }
1046
+
1047
+ /**
1048
+ * Buffer range for selection coordinates
1049
+ */
1050
+ export declare interface IBufferRange {
1051
+ start: {
1052
+ x: number;
1053
+ y: number;
1054
+ };
1055
+ end: {
1056
+ x: number;
1057
+ y: number;
1058
+ };
1059
+ }
1060
+
1061
+ /**
1062
+ * Represents a range in the terminal buffer
1063
+ * Can span multiple lines for wrapped links
1064
+ */
1065
+ declare interface IBufferRange_2 {
1066
+ start: IBufferCellPosition;
1067
+ end: IBufferCellPosition;
1068
+ }
1069
+
1070
+ export declare interface IDisposable {
1071
+ dispose(): void;
1072
+ }
1073
+
1074
+ export declare type IEvent<T> = (listener: (arg: T) => void) => IDisposable;
1075
+
1076
+ export declare interface IImagePasteData {
1077
+ name: string;
1078
+ dataBase64: string;
1079
+ }
1080
+
1081
+ /**
1082
+ * Keyboard event with key and DOM event
1083
+ */
1084
+ export declare interface IKeyEvent {
1085
+ key: string;
1086
+ domEvent: KeyboardEvent;
1087
+ }
1088
+
1089
+ /**
1090
+ * Represents a detected link in the terminal
1091
+ */
1092
+ export declare interface ILink {
1093
+ /** The URL or text of the link */
1094
+ text: string;
1095
+ /** The range of the link in the buffer (may span multiple lines) */
1096
+ range: IBufferRange_2;
1097
+ /** Called when the link is activated (clicked with modifier) */
1098
+ activate(event: MouseEvent): void;
1099
+ /** Optional: called when mouse enters/leaves the link */
1100
+ hover?(isHovered: boolean): void;
1101
+ /** Optional: called to clean up resources */
1102
+ dispose?(): void;
1103
+ }
1104
+
1105
+ /**
1106
+ * Provides link detection for a specific type of link
1107
+ * Examples: OSC 8 hyperlinks, URL regex detection
1108
+ */
1109
+ export declare interface ILinkProvider {
1110
+ /**
1111
+ * Provide links for a given row
1112
+ * @param y Absolute row in buffer (0-based)
1113
+ * @param callback Called with detected links (or undefined if none)
1114
+ */
1115
+ provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void;
1116
+ /** Optional: called when terminal is disposed */
1117
+ dispose?(): void;
1118
+ }
1119
+
1120
+ export declare class ImagePasteAddon implements ITerminalAddon {
1121
+ private _terminal?;
1122
+ private _pasteListener;
1123
+ private _emitter;
1124
+ /**
1125
+ * Event fired when an image is pasted from the clipboard.
1126
+ */
1127
+ readonly onImagePaste: IEvent<IImagePasteData>;
1128
+ /**
1129
+ * Activate the addon (called by Terminal.loadAddon)
1130
+ */
1131
+ activate(terminal: ITerminalCore): void;
1132
+ /**
1133
+ * Dispose the addon and clean up resources
1134
+ */
1135
+ dispose(): void;
1136
+ private _attachListener;
1137
+ private _detachListener;
1138
+ }
1139
+
1140
+ /**
1141
+ * Initialize the ghostty-web library by loading the WASM module.
1142
+ * Must be called before creating any Terminal instances.
1143
+ *
1144
+ * This creates a shared WASM instance that all Terminal instances will use.
1145
+ * For test isolation, pass a Ghostty instance directly to Terminal constructor.
1146
+ *
1147
+ * @example
1148
+ * ```typescript
1149
+ * import { init, Terminal } from 'ghostty-web';
1150
+ *
1151
+ * await init();
1152
+ * const term = new Terminal();
1153
+ * term.open(document.getElementById('terminal'));
1154
+ * ```
1155
+ */
1156
+ export declare function init(): Promise<void>;
1157
+
1158
+ export declare class InputHandler {
1159
+ private encoder;
1160
+ private container;
1161
+ private inputElement?;
1162
+ private onDataCallback;
1163
+ private onBellCallback;
1164
+ private onKeyCallback?;
1165
+ private customKeyEventHandler?;
1166
+ private getModeCallback?;
1167
+ private onCopyCallback?;
1168
+ private mouseConfig?;
1169
+ private keydownListener;
1170
+ private keypressListener;
1171
+ private pasteListener;
1172
+ private beforeInputListener;
1173
+ private compositionStartListener;
1174
+ private compositionUpdateListener;
1175
+ private compositionEndListener;
1176
+ private mousedownListener;
1177
+ private mouseupListener;
1178
+ private mousemoveListener;
1179
+ private wheelListener;
1180
+ private isComposing;
1181
+ private compositionJustEnded;
1182
+ private pendingKeyAfterComposition;
1183
+ private isDisposed;
1184
+ private mouseButtonsPressed;
1185
+ private lastKeyDownData;
1186
+ private lastKeyDownTime;
1187
+ private lastPasteData;
1188
+ private lastPasteTime;
1189
+ private lastPasteSource;
1190
+ private lastCompositionData;
1191
+ private lastCompositionTime;
1192
+ private lastBeforeInputData;
1193
+ private lastBeforeInputTime;
1194
+ private static readonly BEFORE_INPUT_IGNORE_MS;
1195
+ private syncedEncoderOptions;
1196
+ private decoder;
1197
+ /**
1198
+ * Create a new InputHandler
1199
+ * @param ghostty - Ghostty instance (for creating KeyEncoder)
1200
+ * @param container - DOM element to attach listeners to
1201
+ * @param onData - Callback for terminal data (escape sequences to send to PTY)
1202
+ * @param onBell - Callback for bell/beep event
1203
+ * @param onKey - Optional callback for raw key events
1204
+ * @param customKeyEventHandler - Optional custom key event handler
1205
+ * @param getMode - Optional callback to query terminal mode state (for application cursor mode)
1206
+ * @param onCopy - Optional callback to handle copy (Cmd+C/Ctrl+C with selection)
1207
+ * @param inputElement - Optional input element for beforeinput events
1208
+ * @param mouseConfig - Optional mouse tracking configuration
1209
+ */
1210
+ constructor(ghostty: Ghostty, container: HTMLElement, onData: (data: string) => void, onBell: () => void, onKey?: (keyEvent: IKeyEvent) => void, customKeyEventHandler?: (event: KeyboardEvent) => boolean, getMode?: (mode: number) => boolean, onCopy?: () => boolean, inputElement?: HTMLElement, mouseConfig?: MouseTrackingConfig);
1211
+ /**
1212
+ * Set custom key event handler (for runtime updates)
1213
+ */
1214
+ setCustomKeyEventHandler(handler: (event: KeyboardEvent) => boolean): void;
1215
+ /**
1216
+ * Attach keyboard event listeners to container
1217
+ */
1218
+ private attach;
1219
+ /**
1220
+ * Map KeyboardEvent.code to USB HID Key enum value
1221
+ * @param code - KeyboardEvent.code value
1222
+ * @returns Key enum value or null if unmapped
1223
+ */
1224
+ private mapKeyCode;
1225
+ /**
1226
+ * Push an encoder option value to WASM only if it differs from the last
1227
+ * value we pushed. Terminal modes rarely change between keystrokes, so
1228
+ * this saves two WASM round-trips per keystroke in the steady state.
1229
+ */
1230
+ private syncEncoderOption;
1231
+ /**
1232
+ * Extract modifier flags from KeyboardEvent
1233
+ * @param event - KeyboardEvent
1234
+ * @returns Mods flags
1235
+ */
1236
+ private extractModifiers;
1237
+ /**
1238
+ * Handle keydown event
1239
+ * @param event - KeyboardEvent
1240
+ */
1241
+ private handleKeyDown;
1242
+ /**
1243
+ * Handle paste event from clipboard
1244
+ * @param event - ClipboardEvent
1245
+ */
1246
+ private handlePaste;
1247
+ /**
1248
+ * Handle beforeinput event (mobile/IME input)
1249
+ * @param event - InputEvent
1250
+ */
1251
+ private handleBeforeInput;
1252
+ /**
1253
+ * Handle compositionstart event
1254
+ */
1255
+ private handleCompositionStart;
1256
+ /**
1257
+ * Handle compositionupdate event
1258
+ */
1259
+ private handleCompositionUpdate;
1260
+ /**
1261
+ * Handle compositionend event
1262
+ */
1263
+ private handleCompositionEnd;
1264
+ /**
1265
+ * Process the pending key that was queued during composition
1266
+ */
1267
+ private processPendingKeyAfterComposition;
1268
+ /**
1269
+ * Cleanup text nodes in container after composition
1270
+ */
1271
+ private cleanupCompositionTextNodes;
1272
+ /**
1273
+ * Convert pixel coordinates to terminal cell coordinates
1274
+ */
1275
+ private pixelToCell;
1276
+ /**
1277
+ * Get modifier flags for mouse event
1278
+ */
1279
+ private getMouseModifiers;
1280
+ /**
1281
+ * Encode mouse event as SGR sequence
1282
+ * SGR format: \x1b[<Btn;Col;RowM (press/motion) or \x1b[<Btn;Col;Rowm (release)
1283
+ */
1284
+ private encodeMouseSGR;
1285
+ /**
1286
+ * Encode mouse event as X10/normal sequence (legacy format)
1287
+ * Format: \x1b[M<Btn+32><Col+32><Row+32>
1288
+ */
1289
+ private encodeMouseX10;
1290
+ /**
1291
+ * Send mouse event to terminal
1292
+ */
1293
+ private sendMouseEvent;
1294
+ /**
1295
+ * Handle mousedown event
1296
+ */
1297
+ private handleMouseDown;
1298
+ /**
1299
+ * Handle mouseup event
1300
+ */
1301
+ private handleMouseUp;
1302
+ /**
1303
+ * Handle mousemove event
1304
+ */
1305
+ private handleMouseMove;
1306
+ /**
1307
+ * Handle wheel event (scroll)
1308
+ */
1309
+ private handleWheel;
1310
+ /**
1311
+ * Send a wheel event as a mouse tracking sequence.
1312
+ * Public so that Terminal can forward wheel events when mouse tracking is
1313
+ * active (the Terminal-level capture handler stops propagation to prevent
1314
+ * browser scrolling, so this method allows explicit forwarding).
1315
+ */
1316
+ handleWheelEvent(event: WheelEvent): void;
1317
+ /**
1318
+ * Encode and send a wheel event as a mouse tracking escape sequence.
1319
+ * Button 64 = scroll up, button 65 = scroll down, with cell coordinates.
1320
+ */
1321
+ private sendWheelMouseEvent;
1322
+ /**
1323
+ * Emit paste data with bracketed paste support
1324
+ */
1325
+ private emitPasteData;
1326
+ /**
1327
+ * Record keydown data for beforeinput de-duplication
1328
+ */
1329
+ private recordKeyDownData;
1330
+ /**
1331
+ * Record paste data for beforeinput de-duplication
1332
+ */
1333
+ private recordPasteData;
1334
+ /**
1335
+ * Check if beforeinput should be ignored due to a recent keydown
1336
+ */
1337
+ private shouldIgnoreBeforeInput;
1338
+ /**
1339
+ * Check if beforeinput text should be ignored due to a recent composition end
1340
+ */
1341
+ private shouldIgnoreBeforeInputFromComposition;
1342
+ /**
1343
+ * Check if composition end should be ignored due to a recent beforeinput text
1344
+ */
1345
+ private shouldIgnoreCompositionEnd;
1346
+ /**
1347
+ * Record beforeinput text for composition de-duplication
1348
+ */
1349
+ private recordBeforeInputData;
1350
+ /**
1351
+ * Record composition end data for beforeinput de-duplication
1352
+ */
1353
+ private recordCompositionData;
1354
+ /**
1355
+ * Check if paste should be ignored due to a recent paste event from another source
1356
+ */
1357
+ private shouldIgnorePasteEvent;
1358
+ /**
1359
+ * Get current time in milliseconds
1360
+ */
1361
+ private getNow;
1362
+ /**
1363
+ * Dispose the InputHandler and remove event listeners
1364
+ */
1365
+ dispose(): void;
1366
+ /**
1367
+ * Check if handler is disposed
1368
+ */
1369
+ isActive(): boolean;
1370
+ }
1371
+
1372
+ export declare interface IRenderable {
1373
+ getLine(y: number): GhosttyCell[] | null;
1374
+ getCursor(): {
1375
+ x: number;
1376
+ y: number;
1377
+ visible: boolean;
1378
+ style?: 'block' | 'underline' | 'bar';
1379
+ };
1380
+ getDimensions(): {
1381
+ cols: number;
1382
+ rows: number;
1383
+ };
1384
+ isRowDirty(y: number): boolean;
1385
+ /** Returns true if a full redraw is needed (e.g., screen change) */
1386
+ needsFullRedraw?(): boolean;
1387
+ clearDirty(): void;
1388
+ /**
1389
+ * Get the full grapheme string for a cell at (row, col).
1390
+ * For cells with grapheme_len > 0, this returns all codepoints combined.
1391
+ * For simple cells, returns the single character.
1392
+ */
1393
+ getGraphemeString?(row: number, col: number): string;
1394
+ getKittyGraphics?(): number | null;
1395
+ iterPlacements?(graphics: number, onlyVisible?: boolean): Iterable<KittyPlacementInfo>;
1396
+ getKittyImagePixels?(graphics: number, imageId: number): KittyImagePixels | null;
1397
+ /**
1398
+ * Returns the full codepoint sequence for the cell at (row, col) in
1399
+ * the active screen — the base codepoint followed by any combining
1400
+ * marks. Used to decode unicode-placeholder cells (U+10EEEE plus
1401
+ * combining diacritics that encode row/column slice positions).
1402
+ */
1403
+ getGrapheme?(row: number, col: number): number[] | null;
1404
+ }
1405
+
1406
+ declare interface IScrollbackProvider {
1407
+ getScrollbackLine(offset: number): GhosttyCell[] | null;
1408
+ getScrollbackLength(): number;
1409
+ }
1410
+
1411
+ export declare interface ITerminalAddon {
1412
+ activate(terminal: ITerminalCore): void;
1413
+ dispose(): void;
1414
+ }
1415
+
1416
+ export declare interface ITerminalCore {
1417
+ cols: number;
1418
+ rows: number;
1419
+ element?: HTMLElement;
1420
+ textarea?: HTMLTextAreaElement;
1421
+ }
1422
+
1423
+ export declare interface ITerminalDimensions {
1424
+ cols: number;
1425
+ rows: number;
1426
+ }
1427
+
1428
+ /**
1429
+ * Minimal terminal interface required by LinkDetector
1430
+ * Keeps coupling low and testing easy
1431
+ */
1432
+ declare interface ITerminalForLinkDetector {
1433
+ buffer: {
1434
+ active: {
1435
+ getLine(y: number): {
1436
+ length: number;
1437
+ getCell(x: number): {
1438
+ getHyperlinkId(): number;
1439
+ } | undefined;
1440
+ } | undefined;
1441
+ };
1442
+ };
1443
+ }
1444
+
1445
+ /**
1446
+ * Minimal terminal interface required by OSC8LinkProvider
1447
+ */
1448
+ declare interface ITerminalForOSC8Provider {
1449
+ buffer: {
1450
+ active: {
1451
+ length: number;
1452
+ getLine(y: number): {
1453
+ length: number;
1454
+ getCell(x: number): {
1455
+ getHyperlinkId(): number;
1456
+ } | undefined;
1457
+ } | undefined;
1458
+ };
1459
+ };
1460
+ wasmTerm?: {
1461
+ getHyperlinkUri(row: number, col: number): string | null;
1462
+ getScrollbackHyperlinkUri(offset: number, col: number): string | null;
1463
+ getScrollbackLength(): number;
1464
+ };
1465
+ }
1466
+
1467
+ /**
1468
+ * Minimal terminal interface required by UrlRegexProvider
1469
+ */
1470
+ declare interface ITerminalForUrlProvider {
1471
+ buffer: {
1472
+ active: {
1473
+ getLine(y: number): IBufferLineForUrlProvider | undefined;
1474
+ };
1475
+ };
1476
+ }
1477
+
1478
+ export declare interface ITerminalOptions {
1479
+ cols?: number;
1480
+ rows?: number;
1481
+ cursorBlink?: boolean;
1482
+ cursorStyle?: 'block' | 'underline' | 'bar';
1483
+ theme?: ITheme;
1484
+ scrollback?: number;
1485
+ fontSize?: number;
1486
+ fontFamily?: string;
1487
+ allowTransparency?: boolean;
1488
+ convertEol?: boolean;
1489
+ disableStdin?: boolean;
1490
+ focusOnOpen?: boolean;
1491
+ smoothScrollDuration?: number;
1492
+ /**
1493
+ * When true, the viewport stays locked on the same scrollback content as
1494
+ * new output arrives — instead of auto-scrolling to the bottom. Mirrors
1495
+ * the behaviour of modern terminals (kitty, alacritty). Default: false
1496
+ * (preserves the xterm.js-style auto-scroll behaviour for back-compat).
1497
+ */
1498
+ preserveScrollOnWrite?: boolean;
1499
+ emitTerminalResponses?: boolean;
1500
+ ghostty?: Ghostty;
1501
+ }
1502
+
1503
+ export declare interface ITheme {
1504
+ foreground?: string;
1505
+ background?: string;
1506
+ cursor?: string;
1507
+ cursorAccent?: string;
1508
+ selectionBackground?: string;
1509
+ selectionForeground?: string;
1510
+ black?: string;
1511
+ red?: string;
1512
+ green?: string;
1513
+ yellow?: string;
1514
+ blue?: string;
1515
+ magenta?: string;
1516
+ cyan?: string;
1517
+ white?: string;
1518
+ brightBlack?: string;
1519
+ brightRed?: string;
1520
+ brightGreen?: string;
1521
+ brightYellow?: string;
1522
+ brightBlue?: string;
1523
+ brightMagenta?: string;
1524
+ brightCyan?: string;
1525
+ brightWhite?: string;
1526
+ }
1527
+
1528
+ /**
1529
+ * Unicode version provider (xterm.js compatibility)
1530
+ */
1531
+ export declare interface IUnicodeVersionProvider {
1532
+ readonly activeVersion: string;
1533
+ }
1534
+
1535
+ /**
1536
+ * Physical key codes matching Ghostty's internal Key enum.
1537
+ * These values are used by Ghostty's key encoder to produce correct escape sequences.
1538
+ * Reference: ghostty/src/input/key.zig
1539
+ */
1540
+ export declare enum Key {
1541
+ UNIDENTIFIED = 0,
1542
+ GRAVE = 1,// ` and ~
1543
+ BACKSLASH = 2,// \ and |
1544
+ BRACKET_LEFT = 3,// [ and {
1545
+ BRACKET_RIGHT = 4,// ] and }
1546
+ COMMA = 5,// , and <
1547
+ ZERO = 6,
1548
+ ONE = 7,
1549
+ TWO = 8,
1550
+ THREE = 9,
1551
+ FOUR = 10,
1552
+ FIVE = 11,
1553
+ SIX = 12,
1554
+ SEVEN = 13,
1555
+ EIGHT = 14,
1556
+ NINE = 15,
1557
+ EQUAL = 16,// = and +
1558
+ INTL_BACKSLASH = 17,
1559
+ INTL_RO = 18,
1560
+ INTL_YEN = 19,
1561
+ A = 20,
1562
+ B = 21,
1563
+ C = 22,
1564
+ D = 23,
1565
+ E = 24,
1566
+ F = 25,
1567
+ G = 26,
1568
+ H = 27,
1569
+ I = 28,
1570
+ J = 29,
1571
+ K = 30,
1572
+ L = 31,
1573
+ M = 32,
1574
+ N = 33,
1575
+ O = 34,
1576
+ P = 35,
1577
+ Q = 36,
1578
+ R = 37,
1579
+ S = 38,
1580
+ T = 39,
1581
+ U = 40,
1582
+ V = 41,
1583
+ W = 42,
1584
+ X = 43,
1585
+ Y = 44,
1586
+ Z = 45,
1587
+ MINUS = 46,// - and _
1588
+ PERIOD = 47,// . and >
1589
+ QUOTE = 48,// ' and "
1590
+ SEMICOLON = 49,// ; and :
1591
+ SLASH = 50,// / and ?
1592
+ ALT_LEFT = 51,
1593
+ ALT_RIGHT = 52,
1594
+ BACKSPACE = 53,
1595
+ CAPS_LOCK = 54,
1596
+ CONTEXT_MENU = 55,
1597
+ CONTROL_LEFT = 56,
1598
+ CONTROL_RIGHT = 57,
1599
+ ENTER = 58,
1600
+ META_LEFT = 59,
1601
+ META_RIGHT = 60,
1602
+ SHIFT_LEFT = 61,
1603
+ SHIFT_RIGHT = 62,
1604
+ SPACE = 63,
1605
+ TAB = 64,
1606
+ CONVERT = 65,
1607
+ KANA_MODE = 66,
1608
+ NON_CONVERT = 67,
1609
+ DELETE = 68,
1610
+ END = 69,
1611
+ HELP = 70,
1612
+ HOME = 71,
1613
+ INSERT = 72,
1614
+ PAGE_DOWN = 73,
1615
+ PAGE_UP = 74,
1616
+ DOWN = 75,
1617
+ LEFT = 76,
1618
+ RIGHT = 77,
1619
+ UP = 78,
1620
+ NUM_LOCK = 79,
1621
+ KP_0 = 80,
1622
+ KP_1 = 81,
1623
+ KP_2 = 82,
1624
+ KP_3 = 83,
1625
+ KP_4 = 84,
1626
+ KP_5 = 85,
1627
+ KP_6 = 86,
1628
+ KP_7 = 87,
1629
+ KP_8 = 88,
1630
+ KP_9 = 89,
1631
+ KP_PLUS = 90,// Keypad +
1632
+ KP_BACKSPACE = 91,
1633
+ KP_CLEAR = 92,
1634
+ KP_CLEAR_ENTRY = 93,
1635
+ KP_COMMA = 94,
1636
+ KP_PERIOD = 95,// Keypad .
1637
+ KP_DIVIDE = 96,// Keypad /
1638
+ KP_ENTER = 97,// Keypad Enter
1639
+ KP_EQUAL = 98,
1640
+ KP_MEMORY_ADD = 99,
1641
+ KP_MEMORY_CLEAR = 100,
1642
+ KP_MEMORY_RECALL = 101,
1643
+ KP_MEMORY_STORE = 102,
1644
+ KP_MEMORY_SUBTRACT = 103,
1645
+ KP_MULTIPLY = 104,// Keypad *
1646
+ KP_PAREN_LEFT = 105,
1647
+ KP_PAREN_RIGHT = 106,
1648
+ KP_MINUS = 107,// Keypad -
1649
+ KP_SEPARATOR = 108,
1650
+ NUMPAD_UP = 109,
1651
+ NUMPAD_DOWN = 110,
1652
+ NUMPAD_RIGHT = 111,
1653
+ NUMPAD_LEFT = 112,
1654
+ NUMPAD_BEGIN = 113,
1655
+ NUMPAD_HOME = 114,
1656
+ NUMPAD_END = 115,
1657
+ NUMPAD_INSERT = 116,
1658
+ NUMPAD_DELETE = 117,
1659
+ NUMPAD_PAGE_UP = 118,
1660
+ NUMPAD_PAGE_DOWN = 119,
1661
+ ESCAPE = 120,
1662
+ F1 = 121,
1663
+ F2 = 122,
1664
+ F3 = 123,
1665
+ F4 = 124,
1666
+ F5 = 125,
1667
+ F6 = 126,
1668
+ F7 = 127,
1669
+ F8 = 128,
1670
+ F9 = 129,
1671
+ F10 = 130,
1672
+ F11 = 131,
1673
+ F12 = 132,
1674
+ F13 = 133,
1675
+ F14 = 134,
1676
+ F15 = 135,
1677
+ F16 = 136,
1678
+ F17 = 137,
1679
+ F18 = 138,
1680
+ F19 = 139,
1681
+ F20 = 140,
1682
+ F21 = 141,
1683
+ F22 = 142,
1684
+ F23 = 143,
1685
+ F24 = 144,
1686
+ F25 = 145,
1687
+ FN_LOCK = 146,
1688
+ PRINT_SCREEN = 147,
1689
+ SCROLL_LOCK = 148,
1690
+ PAUSE = 149,
1691
+ BROWSER_BACK = 150,
1692
+ BROWSER_FAVORITES = 151,
1693
+ BROWSER_FORWARD = 152,
1694
+ BROWSER_HOME = 153,
1695
+ BROWSER_REFRESH = 154,
1696
+ BROWSER_SEARCH = 155,
1697
+ BROWSER_STOP = 156,
1698
+ EJECT = 157,
1699
+ LAUNCH_APP_1 = 158,
1700
+ LAUNCH_APP_2 = 159,
1701
+ LAUNCH_MAIL = 160,
1702
+ MEDIA_PLAY_PAUSE = 161,
1703
+ MEDIA_SELECT = 162,
1704
+ MEDIA_STOP = 163,
1705
+ MEDIA_TRACK_NEXT = 164,
1706
+ MEDIA_TRACK_PREVIOUS = 165,
1707
+ POWER = 166,
1708
+ SLEEP = 167,
1709
+ AUDIO_VOLUME_DOWN = 168,
1710
+ AUDIO_VOLUME_MUTE = 169,
1711
+ AUDIO_VOLUME_UP = 170,
1712
+ WAKE_UP = 171,
1713
+ COPY = 172,
1714
+ CUT = 173,
1715
+ PASTE = 174
1716
+ }
1717
+
1718
+ /**
1719
+ * Key action
1720
+ */
1721
+ export declare enum KeyAction {
1722
+ RELEASE = 0,
1723
+ PRESS = 1,
1724
+ REPEAT = 2
1725
+ }
1726
+
1727
+ /**
1728
+ * Key Encoder - converts keyboard events into terminal escape sequences
1729
+ */
1730
+ export declare class KeyEncoder {
1731
+ private exports;
1732
+ private encoder;
1733
+ constructor(exports: GhosttyWasmExports);
1734
+ setOption(option: KeyEncoderOption, value: boolean | number): void;
1735
+ setKittyFlags(flags: KittyKeyFlags): void;
1736
+ encode(event: KeyEvent): Uint8Array;
1737
+ dispose(): void;
1738
+ }
1739
+
1740
+ /**
1741
+ * Key encoder options
1742
+ */
1743
+ export declare enum KeyEncoderOption {
1744
+ CURSOR_KEY_APPLICATION = 0,// DEC mode 1
1745
+ KEYPAD_KEY_APPLICATION = 1,// DEC mode 66
1746
+ IGNORE_KEYPAD_WITH_NUMLOCK = 2,// DEC mode 1035
1747
+ ALT_ESC_PREFIX = 3,// DEC mode 1036
1748
+ MODIFY_OTHER_KEYS_STATE_2 = 4,// xterm modifyOtherKeys
1749
+ KITTY_KEYBOARD_FLAGS = 5
1750
+ }
1751
+
1752
+ /**
1753
+ * Key event structure
1754
+ */
1755
+ export declare interface KeyEvent {
1756
+ action: KeyAction;
1757
+ key: Key;
1758
+ mods: Mods;
1759
+ consumedMods?: Mods;
1760
+ composing?: boolean;
1761
+ utf8?: string;
1762
+ unshiftedCodepoint?: number;
1763
+ }
1764
+
1765
+ /**
1766
+ * Pixel format of a Kitty graphics image. Mirrors GhosttyKittyImageFormat.
1767
+ * RGB: 24-bit, 3 bytes/px
1768
+ * RGBA: 32-bit, 4 bytes/px (the canvas-friendly path)
1769
+ * PNG: compressed; needs a JS-side decoder hooked up via
1770
+ * ghostty_sys_set(DECODE_PNG, fn)
1771
+ * GRAY_ALPHA: 16-bit, 2 bytes/px
1772
+ * GRAY: 8-bit, 1 byte/px
1773
+ */
1774
+ declare enum KittyImageFormat {
1775
+ RGB = 0,
1776
+ RGBA = 1,
1777
+ PNG = 2,
1778
+ GRAY_ALPHA = 3,
1779
+ GRAY = 4
1780
+ }
1781
+
1782
+ /**
1783
+ * Image bytes + metadata returned by GhosttyTerminal.getKittyImageRgba.
1784
+ * `data` is a *view* into WASM memory and is invalidated by the next
1785
+ * mutating terminal call — copy out before vt_write if you need to retain.
1786
+ */
1787
+ declare interface KittyImagePixels {
1788
+ width: number;
1789
+ height: number;
1790
+ format: KittyImageFormat;
1791
+ /** Borrowed view into WASM memory; copy before vt_write to retain. */
1792
+ data: Uint8Array;
1793
+ }
1794
+
1795
+ /**
1796
+ * Kitty keyboard protocol flags
1797
+ * From include/ghostty/vt/key/encoder.h
1798
+ */
1799
+ declare enum KittyKeyFlags {
1800
+ DISABLED = 0,
1801
+ DISAMBIGUATE = 1,// Disambiguate escape codes
1802
+ REPORT_EVENTS = 2,// Report press and release
1803
+ REPORT_ALTERNATES = 4,// Report alternate key codes
1804
+ REPORT_ALL = 8,// Report all events
1805
+ REPORT_ASSOCIATED = 16,// Report associated text
1806
+ ALL = 31
1807
+ }
1808
+
1809
+ /**
1810
+ * Parsed GhosttyKittyGraphicsPlacementRenderInfo — everything the renderer
1811
+ * needs about a single placement to composite it on the canvas.
1812
+ *
1813
+ * Wire layout on wasm32 (48 bytes, extern struct, 4-byte aligned):
1814
+ * size: u32 @ 0 (sized-struct discriminator; we just write 48)
1815
+ * pixel_width: u32 @ 4
1816
+ * pixel_height: u32 @ 8
1817
+ * grid_cols: u32 @ 12
1818
+ * grid_rows: u32 @ 16
1819
+ * viewport_col: i32 @ 20
1820
+ * viewport_row: i32 @ 24
1821
+ * viewport_visible: bool @ 28 (1 byte + 3 bytes padding to next u32)
1822
+ * source_x: u32 @ 32
1823
+ * source_y: u32 @ 36
1824
+ * source_width: u32 @ 40
1825
+ * source_height: u32 @ 44
1826
+ */
1827
+ declare interface KittyPlacementInfo {
1828
+ imageId: number;
1829
+ /** Destination size on the canvas, in pixels. */
1830
+ pixelWidth: number;
1831
+ pixelHeight: number;
1832
+ /** Destination size on the grid, in cells. */
1833
+ gridCols: number;
1834
+ gridRows: number;
1835
+ /** Top-left in viewport-relative cells. Negative when scrolled partway off the top. */
1836
+ viewportCol: number;
1837
+ viewportRow: number;
1838
+ /** Whether any part of the placement intersects the visible viewport. */
1839
+ viewportVisible: boolean;
1840
+ /** Source rect within the image, in pixels (already clamped to image bounds). */
1841
+ sourceX: number;
1842
+ sourceY: number;
1843
+ sourceWidth: number;
1844
+ sourceHeight: number;
1845
+ /**
1846
+ * Virtual placements have no fixed viewport position; their image is
1847
+ * drawn into U+10EEEE placeholder cells written to the grid by the
1848
+ * application. The renderer picks them up by image_id rather than
1849
+ * iterating through them for direct compositing.
1850
+ */
1851
+ isVirtual: boolean;
1852
+ }
1853
+
1854
+ /**
1855
+ * Manages link detection across multiple providers with intelligent caching
1856
+ */
1857
+ export declare class LinkDetector {
1858
+ private terminal;
1859
+ private providers;
1860
+ private linkCache;
1861
+ private scannedRows;
1862
+ constructor(terminal: ITerminalForLinkDetector);
1863
+ /**
1864
+ * Register a link provider
1865
+ */
1866
+ registerProvider(provider: ILinkProvider): void;
1867
+ /**
1868
+ * Get link at the specified buffer position
1869
+ * @param col Column (0-based)
1870
+ * @param row Absolute row in buffer (0-based)
1871
+ * @returns Link at position, or undefined if none
1872
+ */
1873
+ getLinkAt(col: number, row: number): Promise<ILink | undefined>;
1874
+ /**
1875
+ * Scan a row for links using all registered providers
1876
+ */
1877
+ private scanRow;
1878
+ /**
1879
+ * Cache a link for fast lookup
1880
+ *
1881
+ * Note: We cache by position range, not hyperlink_id, because the WASM
1882
+ * returns hyperlink_id as a boolean (0 or 1), not a unique identifier.
1883
+ * The actual unique identifier is the URI which is retrieved separately.
1884
+ */
1885
+ private cacheLink;
1886
+ /**
1887
+ * Check if a position is within a link's range
1888
+ */
1889
+ private isPositionInLink;
1890
+ /**
1891
+ * Invalidate cache when terminal content changes
1892
+ * Should be called on terminal write, resize, or clear
1893
+ */
1894
+ invalidateCache(): void;
1895
+ /**
1896
+ * Invalidate cache for specific rows
1897
+ * Used when only part of the terminal changed
1898
+ */
1899
+ invalidateRows(startRow: number, endRow: number): void;
1900
+ /**
1901
+ * Dispose and cleanup
1902
+ */
1903
+ dispose(): void;
1904
+ }
1905
+
1906
+ /**
1907
+ * Modifier keys
1908
+ */
1909
+ export declare enum Mods {
1910
+ NONE = 0,
1911
+ SHIFT = 1,
1912
+ CTRL = 2,
1913
+ ALT = 4,
1914
+ SUPER = 8,// Windows/Command key
1915
+ CAPSLOCK = 16,
1916
+ NUMLOCK = 32
1917
+ }
1918
+
1919
+ /**
1920
+ * InputHandler class
1921
+ * Attaches keyboard event listeners to a container and converts
1922
+ * keyboard events to terminal input data
1923
+ */
1924
+ /**
1925
+ * Mouse tracking configuration
1926
+ */
1927
+ declare interface MouseTrackingConfig {
1928
+ /** Check if any mouse tracking mode is enabled */
1929
+ hasMouseTracking: () => boolean;
1930
+ /** Check if SGR extended mouse mode is enabled (mode 1006) */
1931
+ hasSgrMouseMode: () => boolean;
1932
+ /** Get cell dimensions for pixel to cell conversion */
1933
+ getCellDimensions: () => {
1934
+ width: number;
1935
+ height: number;
1936
+ };
1937
+ /** Get canvas/container offset for accurate position calculation */
1938
+ getCanvasOffset: () => {
1939
+ left: number;
1940
+ top: number;
1941
+ };
1942
+ }
1943
+
1944
+ /**
1945
+ * OSC 8 Hyperlink Provider
1946
+ *
1947
+ * Detects OSC 8 hyperlinks by scanning for hyperlink_id in cells.
1948
+ * Automatically handles multi-line links since Ghostty WASM preserves
1949
+ * hyperlink_id across wrapped lines.
1950
+ */
1951
+ export declare class OSC8LinkProvider implements ILinkProvider {
1952
+ private terminal;
1953
+ constructor(terminal: ITerminalForOSC8Provider);
1954
+ /**
1955
+ * Provide all OSC 8 links on the given row
1956
+ * Note: This may return links that span multiple rows
1957
+ */
1958
+ provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void;
1959
+ /**
1960
+ * Find the full extent of a link by scanning for contiguous cells
1961
+ * with the same hyperlink_id. Handles multi-line links.
1962
+ */
1963
+ private findLinkRange;
1964
+ dispose(): void;
1965
+ }
1966
+
1967
+ export declare interface RendererOptions {
1968
+ fontSize?: number;
1969
+ fontFamily?: string;
1970
+ cursorStyle?: 'block' | 'underline' | 'bar';
1971
+ cursorBlink?: boolean;
1972
+ theme?: ITheme;
1973
+ devicePixelRatio?: number;
1974
+ }
1975
+
1976
+ /**
1977
+ * Colors from RenderState (12 bytes packed)
1978
+ */
1979
+ declare interface RenderStateColors {
1980
+ background: RGB;
1981
+ foreground: RGB;
1982
+ cursor: RGB | null;
1983
+ }
1984
+
1985
+ /**
1986
+ * Cursor state from RenderState (8 bytes packed)
1987
+ * Layout: x(u16) + y(u16) + viewport_x(i16) + viewport_y(i16) + visible(bool) + blinking(bool) + style(u8) + _pad(u8)
1988
+ */
1989
+ declare interface RenderStateCursor {
1990
+ x: number;
1991
+ y: number;
1992
+ viewportX: number;
1993
+ viewportY: number;
1994
+ visible: boolean;
1995
+ blinking: boolean;
1996
+ style: 'block' | 'underline' | 'bar';
1997
+ }
1998
+
1999
+ /**
2000
+ * RGB color
2001
+ */
2002
+ export declare interface RGB {
2003
+ r: number;
2004
+ g: number;
2005
+ b: number;
2006
+ }
2007
+
2008
+ export declare interface SelectionCoordinates {
2009
+ startCol: number;
2010
+ startRow: number;
2011
+ endCol: number;
2012
+ endRow: number;
2013
+ }
2014
+
2015
+ export declare class SelectionManager {
2016
+ private terminal;
2017
+ private renderer;
2018
+ private wasmTerm;
2019
+ private textarea;
2020
+ private selectionStart;
2021
+ private selectionEnd;
2022
+ private isSelecting;
2023
+ private mouseDownX;
2024
+ private mouseDownY;
2025
+ private dragThresholdMet;
2026
+ private mouseDownTarget;
2027
+ private dirtySelectionRows;
2028
+ private selectionChangedEmitter;
2029
+ private boundMouseUpHandler;
2030
+ private boundContextMenuHandler;
2031
+ private boundClickHandler;
2032
+ private boundDocumentMouseMoveHandler;
2033
+ private autoScrollInterval;
2034
+ private autoScrollDirection;
2035
+ private static readonly AUTO_SCROLL_EDGE_SIZE;
2036
+ /**
2037
+ * Get current viewport Y position (how many lines scrolled into history)
2038
+ */
2039
+ private getViewportY;
2040
+ /**
2041
+ * Convert viewport row to absolute buffer row
2042
+ * Absolute row is an index into combined buffer: scrollback (0 to len-1) + screen (len to len+rows-1)
2043
+ */
2044
+ private viewportRowToAbsolute;
2045
+ /**
2046
+ * Convert absolute buffer row to viewport row (may be outside visible range)
2047
+ */
2048
+ private absoluteRowToViewport;
2049
+ private static readonly AUTO_SCROLL_SPEED;
2050
+ private static readonly AUTO_SCROLL_INTERVAL;
2051
+ constructor(terminal: Terminal, renderer: CanvasRenderer, wasmTerm: GhosttyTerminal, textarea: HTMLTextAreaElement);
2052
+ /**
2053
+ * Get the selected text as a string
2054
+ */
2055
+ getSelection(): string;
2056
+ /**
2057
+ * Check if there's an active selection
2058
+ */
2059
+ hasSelection(): boolean;
2060
+ /**
2061
+ * Copy the current selection to clipboard
2062
+ * @returns true if there was text to copy, false otherwise
2063
+ */
2064
+ copySelection(): boolean;
2065
+ /**
2066
+ * Clear the selection
2067
+ */
2068
+ clearSelection(): void;
2069
+ /**
2070
+ * Select all text in the terminal
2071
+ */
2072
+ selectAll(): void;
2073
+ /**
2074
+ * Select text at specific column and row with length
2075
+ * xterm.js compatible API
2076
+ */
2077
+ select(column: number, row: number, length: number): void;
2078
+ /**
2079
+ * Select entire lines from start to end
2080
+ * xterm.js compatible API
2081
+ */
2082
+ selectLines(start: number, end: number): void;
2083
+ /**
2084
+ * Get selection position as buffer range
2085
+ * xterm.js compatible API
2086
+ */
2087
+ getSelectionPosition(): {
2088
+ start: {
2089
+ x: number;
2090
+ y: number;
2091
+ };
2092
+ end: {
2093
+ x: number;
2094
+ y: number;
2095
+ };
2096
+ } | undefined;
2097
+ /**
2098
+ * Deselect all text
2099
+ * xterm.js compatible API
2100
+ */
2101
+ deselect(): void;
2102
+ /**
2103
+ * Focus the terminal (make it receive keyboard input)
2104
+ */
2105
+ focus(): void;
2106
+ /**
2107
+ * Get current selection coordinates (for rendering)
2108
+ */
2109
+ getSelectionCoords(): SelectionCoordinates | null;
2110
+ /**
2111
+ * Get dirty selection rows that need redraw (for clearing old highlight)
2112
+ */
2113
+ getDirtySelectionRows(): Set<number>;
2114
+ /**
2115
+ * Clear the dirty selection rows tracking (after redraw)
2116
+ */
2117
+ clearDirtySelectionRows(): void;
2118
+ /**
2119
+ * Get selection change event accessor
2120
+ */
2121
+ get onSelectionChange(): IEvent<void>;
2122
+ /**
2123
+ * Cleanup resources
2124
+ */
2125
+ dispose(): void;
2126
+ /**
2127
+ * Attach mouse event listeners to canvas
2128
+ */
2129
+ private attachEventListeners;
2130
+ /**
2131
+ * Mark current selection rows as dirty for redraw
2132
+ */
2133
+ private markCurrentSelectionDirty;
2134
+ /**
2135
+ * Update auto-scroll based on mouse Y position within canvas
2136
+ */
2137
+ private updateAutoScroll;
2138
+ /**
2139
+ * Start auto-scrolling in the given direction
2140
+ */
2141
+ private startAutoScroll;
2142
+ /**
2143
+ * Stop auto-scrolling
2144
+ */
2145
+ private stopAutoScroll;
2146
+ /**
2147
+ * Convert pixel coordinates to terminal cell coordinates
2148
+ */
2149
+ private pixelToCell;
2150
+ /**
2151
+ * Normalize selection coordinates (handle backward selection)
2152
+ * Returns coordinates in VIEWPORT space for rendering, clamped to visible area
2153
+ */
2154
+ private normalizeSelection;
2155
+ /**
2156
+ * Get word boundaries at a cell position
2157
+ */
2158
+ private getWordAtCell;
2159
+ /**
2160
+ * Copy text to clipboard
2161
+ *
2162
+ * Strategy (modern APIs first):
2163
+ * 1. Try ClipboardItem API (works in Safari and modern browsers)
2164
+ * - Safari requires the ClipboardItem to be created synchronously within user gesture
2165
+ * 2. Try navigator.clipboard.writeText (modern async API, may fail in Safari)
2166
+ * 3. Fall back to execCommand (legacy, for older browsers)
2167
+ */
2168
+ private copyToClipboard;
2169
+ /**
2170
+ * Copy using navigator.clipboard.writeText
2171
+ */
2172
+ private copyWithWriteText;
2173
+ /**
2174
+ * Copy using legacy execCommand (fallback for older browsers)
2175
+ */
2176
+ private copyWithExecCommand;
2177
+ /**
2178
+ * Request a render update (triggers selection overlay redraw)
2179
+ */
2180
+ private requestRender;
2181
+ }
2182
+
2183
+ export declare class Terminal extends TerminalCore {
2184
+ readonly unicode: IUnicodeVersionProvider;
2185
+ element?: HTMLElement;
2186
+ textarea?: HTMLTextAreaElement;
2187
+ renderer?: CanvasRenderer;
2188
+ private inputHandler?;
2189
+ private selectionManager?;
2190
+ private canvas?;
2191
+ private linkDetector?;
2192
+ private currentHoveredLink?;
2193
+ private mouseMoveThrottleTimeout?;
2194
+ private pendingMouseMove?;
2195
+ private selectionChangeEmitter;
2196
+ private keyEmitter;
2197
+ private renderEmitter;
2198
+ private mouseCursorChangeEmitter;
2199
+ readonly onSelectionChange: IEvent<void>;
2200
+ readonly onKey: IEvent<IKeyEvent>;
2201
+ readonly onRender: IEvent<{
2202
+ start: number;
2203
+ end: number;
2204
+ }>;
2205
+ /** Fires when the application changes the mouse cursor via OSC 22.
2206
+ * The value is a CSS cursor name (e.g. "default", "crosshair", "wait"). */
2207
+ readonly onMouseCursorChange: IEvent<string>;
2208
+ private isOpen;
2209
+ private animationFrameId?;
2210
+ private writeQueue;
2211
+ private awaitingEcho;
2212
+ private syncOutputStartTime;
2213
+ private static readonly SYNC_OUTPUT_TIMEOUT_MS;
2214
+ private currentTheme;
2215
+ private customKeyEventHandler?;
2216
+ get viewportY(): number;
2217
+ set viewportY(v: number);
2218
+ private targetViewportY;
2219
+ private scrollAnimationStartTime?;
2220
+ private scrollAnimationStartY?;
2221
+ private scrollAnimationFrame?;
2222
+ private customWheelEventHandler?;
2223
+ private isDraggingScrollbar;
2224
+ private scrollbarDragStart;
2225
+ private scrollbarDragStartViewportY;
2226
+ private scrollbarVisible;
2227
+ private scrollbarOpacity;
2228
+ private scrollbarHideTimeout?;
2229
+ private readonly SCROLLBAR_HIDE_DELAY_MS;
2230
+ private readonly SCROLLBAR_FADE_DURATION_MS;
2231
+ private bootstrapCells;
2232
+ private bootstrapDirty;
2233
+ private bootstrapBuffer;
2234
+ constructor(options?: ITerminalOptions);
2235
+ protected handleOptionChange(key: string, newValue: any, oldValue: any): void;
2236
+ private handleFontChange;
2237
+ private buildThemeColorsConfig;
2238
+ open(parent: HTMLElement): void;
2239
+ write(data: string | Uint8Array, callback?: () => void): void;
2240
+ private stripUnimplementedTitleSequences;
2241
+ private writeInternal;
2242
+ writeln(data: string | Uint8Array, callback?: () => void): void;
2243
+ paste(data: string): void;
2244
+ input(data: string, wasUserInput?: boolean): void;
2245
+ resize(cols: number, rows: number): void;
2246
+ reset(): void;
2247
+ clear(): void;
2248
+ focus(): void;
2249
+ blur(): void;
2250
+ loadAddon(addon: ITerminalAddon): void;
2251
+ getMode(mode: number, isAnsi?: boolean): boolean;
2252
+ hasBracketedPaste(): boolean;
2253
+ hasFocusEvents(): boolean;
2254
+ hasMouseTracking(): boolean;
2255
+ getSelection(): string;
2256
+ hasSelection(): boolean;
2257
+ clearSelection(): void;
2258
+ copySelection(): boolean;
2259
+ selectAll(): void;
2260
+ select(column: number, row: number, length: number): void;
2261
+ selectLines(start: number, end: number): void;
2262
+ getSelectionPosition(): IBufferRange | undefined;
2263
+ attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
2264
+ attachCustomWheelEventHandler(customWheelEventHandler?: (event: WheelEvent) => boolean): void;
2265
+ registerLinkProvider(provider: ILinkProvider): void;
2266
+ scrollLines(amount: number): void;
2267
+ scrollPages(amount: number): void;
2268
+ scrollToTop(): void;
2269
+ scrollToBottom(): void;
2270
+ scrollToLine(line: number): void;
2271
+ dispose(): void;
2272
+ protected processTerminalResponses(): void;
2273
+ private updateWasmPixelSize;
2274
+ private cancelRenderLoop;
2275
+ private flushWriteQueue;
2276
+ private requestRender;
2277
+ private renderTick;
2278
+ private syncTextareaToCursor;
2279
+ private lastOsc22Cursor;
2280
+ /**
2281
+ * Intercept OSC 22 mouse-cursor-shape sequences emitted by the PTY.
2282
+ * Updates the canvas CSS cursor and fires onMouseCursorChange.
2283
+ *
2284
+ * Format: ESC ] 22 ; <w3c-cursor-name> BEL|ST
2285
+ *
2286
+ * Ghostty's MouseShape names map 1-to-1 to W3C CSS cursor values after
2287
+ * replacing underscores with hyphens (e.g. "context_menu" → "context-menu").
2288
+ */
2289
+ private interceptOsc22;
2290
+ private armBootstrapBlank;
2291
+ private disarmBootstrapBlank;
2292
+ private cleanupComponents;
2293
+ private assertOpen;
2294
+ private smoothScrollTo;
2295
+ private animateScroll;
2296
+ private showScrollbar;
2297
+ private hideScrollbar;
2298
+ private fadeInScrollbar;
2299
+ private fadeOutScrollbar;
2300
+ private handleMouseMove;
2301
+ private processMouseMove;
2302
+ private handleMouseLeave;
2303
+ private handleClick;
2304
+ private handleWheel;
2305
+ private handleMouseDown;
2306
+ private handleMouseUp;
2307
+ private processScrollbarDrag;
2308
+ }
2309
+
2310
+ export declare class TerminalCore implements IDisposable {
2311
+ cols: number;
2312
+ rows: number;
2313
+ readonly buffer: IBufferNamespace;
2314
+ readonly options: Required<ITerminalOptions>;
2315
+ protected ghostty: Ghostty;
2316
+ wasmTerm?: GhosttyTerminal;
2317
+ protected dataEmitter: EventEmitter<string>;
2318
+ protected resizeEmitter: EventEmitter<{
2319
+ cols: number;
2320
+ rows: number;
2321
+ }>;
2322
+ protected bellEmitter: EventEmitter<void>;
2323
+ protected titleChangeEmitter: EventEmitter<string>;
2324
+ protected scrollEmitter: EventEmitter<number>;
2325
+ protected cursorMoveEmitter: EventEmitter<void>;
2326
+ protected lineFeedEmitter: EventEmitter<void>;
2327
+ protected writeParsedEmitter: EventEmitter<void>;
2328
+ protected binaryEmitter: EventEmitter<string>;
2329
+ protected promptStartEmitter: EventEmitter<void>;
2330
+ protected commandStartEmitter: EventEmitter<void>;
2331
+ protected commandEndEmitter: EventEmitter<{
2332
+ exitCode: number | undefined;
2333
+ }>;
2334
+ readonly onData: IEvent<string>;
2335
+ readonly onResize: IEvent<{
2336
+ cols: number;
2337
+ rows: number;
2338
+ }>;
2339
+ readonly onBell: IEvent<void>;
2340
+ readonly onTitleChange: IEvent<string>;
2341
+ readonly onScroll: IEvent<number>;
2342
+ readonly onCursorMove: IEvent<void>;
2343
+ readonly onLineFeed: IEvent<void>;
2344
+ readonly onWriteParsed: IEvent<void>;
2345
+ readonly onBinary: IEvent<string>;
2346
+ /** Fires when OSC 133 A is received (shell prompt is about to be drawn). */
2347
+ readonly onPromptStart: IEvent<void>;
2348
+ /** Fires when OSC 133 C is received (user hit Enter — command is running). */
2349
+ readonly onCommandStart: IEvent<void>;
2350
+ /** Fires when OSC 133 D is received (command finished). exitCode is undefined if not reported. */
2351
+ readonly onCommandEnd: IEvent<{
2352
+ exitCode: number | undefined;
2353
+ }>;
2354
+ protected isDisposed: boolean;
2355
+ protected addons: ITerminalAddon[];
2356
+ protected currentTitle: string;
2357
+ protected lastCursorY: number;
2358
+ protected lastCursorX: number;
2359
+ protected _viewportY: number;
2360
+ protected _markers: any[];
2361
+ constructor(ghostty: Ghostty, options?: ITerminalOptions);
2362
+ get markers(): ReadonlyArray<any>;
2363
+ protected handleOptionChange(key: string, _newValue: any, _oldValue: any): void;
2364
+ write(data: string | Uint8Array, callback?: () => void): void;
2365
+ writeln(data: string | Uint8Array, callback?: () => void): void;
2366
+ input(data: string, wasUserInput?: boolean): void;
2367
+ resize(cols: number, rows: number): void;
2368
+ reset(): void;
2369
+ clear(): void;
2370
+ dispose(): void;
2371
+ scrollLines(amount: number): void;
2372
+ scrollPages(pageCount: number): void;
2373
+ scrollToTop(): void;
2374
+ scrollToBottom(): void;
2375
+ scrollToLine(line: number): void;
2376
+ registerMarker(_cursorYOffset?: number): any | undefined;
2377
+ loadAddon(addon: ITerminalAddon): void;
2378
+ getViewportY(): number;
2379
+ getScrollbackLength(): number;
2380
+ getScrollbackLine(offset: number): GhosttyCell[] | null;
2381
+ getMode(mode: number, isAnsi?: boolean): boolean;
2382
+ hasBracketedPaste(): boolean;
2383
+ hasFocusEvents(): boolean;
2384
+ hasMouseTracking(): boolean;
2385
+ protected parseColorToHex(color?: string): number;
2386
+ protected buildWasmConfig(): GhosttyTerminalConfig | undefined;
2387
+ protected processTerminalResponses(): void;
2388
+ /**
2389
+ * Intercept OSC 133 shell-integration markers in outgoing PTY data.
2390
+ *
2391
+ * A = prompt start B = input start (ignored here, fires with A)
2392
+ * C = command start D = command end (optionally with exit code)
2393
+ *
2394
+ * Sequences span a single write in practice; partial-write edge cases
2395
+ * are not handled — the common case is one atomic write per marker.
2396
+ */
2397
+ protected checkForShellIntegration(data: string): void;
2398
+ protected checkForTitleChange(data: string): void;
2399
+ protected checkCursorMove(): void;
2400
+ }
2401
+
2402
+ /**
2403
+ * Opaque terminal pointer (WASM memory address)
2404
+ */
2405
+ export declare type TerminalHandle = number;
2406
+
2407
+ /**
2408
+ * URL Regex Provider
2409
+ *
2410
+ * Detects plain text URLs on a single line using regex.
2411
+ * Does not support multi-line URLs or file paths.
2412
+ *
2413
+ * Supported protocols:
2414
+ * - https://, http://
2415
+ * - mailto:
2416
+ * - ftp://, ssh://, git://
2417
+ * - tel:, magnet:
2418
+ * - gemini://, gopher://, news:
2419
+ */
2420
+ export declare class UrlRegexProvider implements ILinkProvider {
2421
+ private terminal;
2422
+ /**
2423
+ * URL regex pattern
2424
+ * Matches common protocols followed by valid URL characters
2425
+ * Excludes file paths (no ./ or ../ or bare /)
2426
+ */
2427
+ private static readonly URL_REGEX;
2428
+ /**
2429
+ * Characters to strip from end of URLs
2430
+ * Common punctuation that's unlikely to be part of the URL
2431
+ */
2432
+ private static readonly TRAILING_PUNCTUATION;
2433
+ constructor(terminal: ITerminalForUrlProvider);
2434
+ /**
2435
+ * Provide all regex-detected URLs on the given row
2436
+ */
2437
+ provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void;
2438
+ /**
2439
+ * Convert a buffer line to plain text string
2440
+ */
2441
+ private lineToText;
2442
+ dispose(): void;
2443
+ }
2444
+
2445
+ export { }