@seflless/ghosttown 1.0.1 → 1.0.3

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,1944 @@
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 lastViewportY;
16
+ private currentBuffer;
17
+ private selectionManager?;
18
+ private currentSelectionCoords;
19
+ private hoveredHyperlinkId;
20
+ private previousHoveredHyperlinkId;
21
+ private hoveredLinkRange;
22
+ private previousHoveredLinkRange;
23
+ constructor(canvas: HTMLCanvasElement, options?: RendererOptions);
24
+ private measureFont;
25
+ /**
26
+ * Remeasure font metrics (call after font loads or changes)
27
+ */
28
+ remeasureFont(): void;
29
+ private rgbToCSS;
30
+ /**
31
+ * Resize canvas to fit terminal dimensions
32
+ */
33
+ resize(cols: number, rows: number): void;
34
+ /**
35
+ * Render the terminal buffer to canvas
36
+ */
37
+ render(buffer: IRenderable, forceAll?: boolean, viewportY?: number, scrollbackProvider?: IScrollbackProvider, scrollbarOpacity?: number): void;
38
+ /**
39
+ * Render a single line using two-pass approach:
40
+ * 1. First pass: Draw all cell backgrounds
41
+ * 2. Second pass: Draw all cell text and decorations
42
+ *
43
+ * This two-pass approach is necessary for proper rendering of complex scripts
44
+ * like Devanagari where diacritics (like vowel sign ि) can extend LEFT of the
45
+ * base character into the previous cell's visual area. If we draw backgrounds
46
+ * and text in a single pass (cell by cell), the background of cell N would
47
+ * cover any left-extending portions of graphemes from cell N-1.
48
+ */
49
+ private renderLine;
50
+ /**
51
+ * Render a cell's background only (Pass 1 of two-pass rendering)
52
+ * Selection highlighting is integrated here to avoid z-order issues with
53
+ * complex glyphs (like Devanagari) that extend outside their cell bounds.
54
+ */
55
+ private renderCellBackground;
56
+ /**
57
+ * Render a cell's text and decorations (Pass 2 of two-pass rendering)
58
+ * Selection foreground color is applied here to match the selection background.
59
+ */
60
+ private renderCellText;
61
+ /**
62
+ * Render cursor
63
+ */
64
+ private renderCursor;
65
+ private startCursorBlink;
66
+ private stopCursorBlink;
67
+ /**
68
+ * Update theme colors
69
+ */
70
+ setTheme(theme: ITheme): void;
71
+ /**
72
+ * Update font size
73
+ */
74
+ setFontSize(size: number): void;
75
+ /**
76
+ * Update font family
77
+ */
78
+ setFontFamily(family: string): void;
79
+ /**
80
+ * Update cursor style
81
+ */
82
+ setCursorStyle(style: 'block' | 'underline' | 'bar'): void;
83
+ /**
84
+ * Enable/disable cursor blinking
85
+ */
86
+ setCursorBlink(enabled: boolean): void;
87
+ /**
88
+ * Get current font metrics
89
+ */
90
+ /**
91
+ * Render scrollbar (Phase 2)
92
+ * Shows scroll position and allows click/drag interaction
93
+ * @param opacity Opacity level (0-1) for fade in/out effect
94
+ */
95
+ private renderScrollbar;
96
+ getMetrics(): FontMetrics;
97
+ /**
98
+ * Get canvas element (needed by SelectionManager)
99
+ */
100
+ getCanvas(): HTMLCanvasElement;
101
+ /**
102
+ * Set selection manager (for rendering selection)
103
+ */
104
+ setSelectionManager(manager: SelectionManager): void;
105
+ /**
106
+ * Check if a cell at (x, y) is within the current selection.
107
+ * Uses cached selection coordinates for performance.
108
+ */
109
+ private isInSelection;
110
+ /**
111
+ * Set the currently hovered hyperlink ID for rendering underlines
112
+ */
113
+ setHoveredHyperlinkId(hyperlinkId: number): void;
114
+ /**
115
+ * Set the currently hovered link range for rendering underlines (for regex-detected URLs)
116
+ * Pass null to clear the hover state
117
+ */
118
+ setHoveredLinkRange(range: {
119
+ startX: number;
120
+ startY: number;
121
+ endX: number;
122
+ endY: number;
123
+ } | null): void;
124
+ /**
125
+ * Get character cell width (for coordinate conversion)
126
+ */
127
+ get charWidth(): number;
128
+ /**
129
+ * Get character cell height (for coordinate conversion)
130
+ */
131
+ get charHeight(): number;
132
+ /**
133
+ * Clear entire canvas
134
+ */
135
+ clear(): void;
136
+ /**
137
+ * Cleanup resources
138
+ */
139
+ dispose(): void;
140
+ }
141
+
142
+ /**
143
+ * Cell style flags (bitfield)
144
+ */
145
+ export declare enum CellFlags {
146
+ BOLD = 1,
147
+ ITALIC = 2,
148
+ UNDERLINE = 4,
149
+ STRIKETHROUGH = 8,
150
+ INVERSE = 16,
151
+ INVISIBLE = 32,
152
+ BLINK = 64,
153
+ FAINT = 128
154
+ }
155
+
156
+ /**
157
+ * Cursor position and visibility
158
+ */
159
+ export declare interface Cursor {
160
+ x: number;
161
+ y: number;
162
+ visible: boolean;
163
+ }
164
+
165
+ /**
166
+ * Dirty state from RenderState
167
+ */
168
+ declare enum DirtyState {
169
+ NONE = 0,
170
+ PARTIAL = 1,
171
+ FULL = 2
172
+ }
173
+
174
+ export declare class EventEmitter<T> {
175
+ private listeners;
176
+ fire(arg: T): void;
177
+ event: IEvent<T>;
178
+ dispose(): void;
179
+ }
180
+
181
+ export declare class FitAddon implements ITerminalAddon {
182
+ private _terminal?;
183
+ private _resizeObserver?;
184
+ private _resizeDebounceTimer?;
185
+ private _lastCols?;
186
+ private _lastRows?;
187
+ private _isResizing;
188
+ /**
189
+ * Activate the addon (called by Terminal.loadAddon)
190
+ */
191
+ activate(terminal: ITerminalCore): void;
192
+ /**
193
+ * Dispose the addon and clean up resources
194
+ */
195
+ dispose(): void;
196
+ /**
197
+ * Fit the terminal to its container
198
+ *
199
+ * Calculates optimal dimensions and resizes the terminal.
200
+ * Does nothing if dimensions cannot be calculated or haven't changed.
201
+ */
202
+ fit(): void;
203
+ /**
204
+ * Propose dimensions to fit the terminal to its container
205
+ *
206
+ * Calculates cols and rows based on:
207
+ * - Terminal container element dimensions (clientWidth/Height)
208
+ * - Terminal element padding
209
+ * - Font metrics (character cell size)
210
+ * - Scrollbar width reservation
211
+ *
212
+ * @returns Proposed dimensions or undefined if cannot calculate
213
+ */
214
+ proposeDimensions(): ITerminalDimensions | undefined;
215
+ /**
216
+ * Observe the terminal's container for resize events
217
+ *
218
+ * Sets up a ResizeObserver to automatically call fit() when the
219
+ * container size changes. Resize events are debounced to avoid
220
+ * excessive calls during window drag operations.
221
+ *
222
+ * Call dispose() to stop observing.
223
+ */
224
+ observeResize(): void;
225
+ }
226
+
227
+ export declare interface FontMetrics {
228
+ width: number;
229
+ height: number;
230
+ baseline: number;
231
+ }
232
+
233
+ /* Excluded from this release type: getGhostty */
234
+
235
+ /**
236
+ * Main Ghostty WASM wrapper class
237
+ */
238
+ export declare class Ghostty {
239
+ private exports;
240
+ private memory;
241
+ constructor(wasmInstance: WebAssembly.Instance);
242
+ createKeyEncoder(): KeyEncoder;
243
+ createTerminal(cols?: number, rows?: number, config?: GhosttyTerminalConfig): GhosttyTerminal;
244
+ static load(wasmPath?: string): Promise<Ghostty>;
245
+ private static loadFromPath;
246
+ }
247
+
248
+ /**
249
+ * Cell structure matching ghostty_cell_t in C (16 bytes)
250
+ */
251
+ export declare interface GhosttyCell {
252
+ codepoint: number;
253
+ fg_r: number;
254
+ fg_g: number;
255
+ fg_b: number;
256
+ bg_r: number;
257
+ bg_g: number;
258
+ bg_b: number;
259
+ flags: number;
260
+ width: number;
261
+ hyperlink_id: number;
262
+ grapheme_len: number;
263
+ }
264
+
265
+ /**
266
+ * GhosttyTerminal - High-performance terminal emulator
267
+ *
268
+ * Uses Ghostty's native RenderState for optimal performance:
269
+ * - ONE call to update all state (renderStateUpdate)
270
+ * - ONE call to get all cells (getViewport)
271
+ * - No per-row WASM boundary crossings!
272
+ */
273
+ export declare class GhosttyTerminal {
274
+ private exports;
275
+ private memory;
276
+ private handle;
277
+ private _cols;
278
+ private _rows;
279
+ /** Size of GhosttyCell in WASM (16 bytes) */
280
+ private static readonly CELL_SIZE;
281
+ /** Reusable buffer for viewport operations */
282
+ private viewportBufferPtr;
283
+ private viewportBufferSize;
284
+ /** Cell pool for zero-allocation rendering */
285
+ private cellPool;
286
+ constructor(exports: GhosttyWasmExports, memory: WebAssembly.Memory, cols?: number, rows?: number, config?: GhosttyTerminalConfig);
287
+ get cols(): number;
288
+ get rows(): number;
289
+ write(data: string | Uint8Array): void;
290
+ resize(cols: number, rows: number): void;
291
+ free(): void;
292
+ /**
293
+ * Update render state from terminal.
294
+ *
295
+ * This syncs the RenderState with the current Terminal state.
296
+ * The dirty state (full/partial/none) is stored in the WASM RenderState
297
+ * and can be queried via isRowDirty(). When dirty==full, isRowDirty()
298
+ * returns true for ALL rows.
299
+ *
300
+ * The WASM layer automatically detects screen switches (normal <-> alternate)
301
+ * and returns FULL dirty state when switching screens (e.g., vim exit).
302
+ *
303
+ * Safe to call multiple times - dirty state persists until markClean().
304
+ */
305
+ update(): DirtyState;
306
+ /**
307
+ * Get cursor state from render state.
308
+ * Ensures render state is fresh by calling update().
309
+ */
310
+ getCursor(): RenderStateCursor;
311
+ /**
312
+ * Get default colors from render state
313
+ */
314
+ getColors(): RenderStateColors;
315
+ /**
316
+ * Check if a specific row is dirty
317
+ */
318
+ isRowDirty(y: number): boolean;
319
+ /**
320
+ * Mark render state as clean (call after rendering)
321
+ */
322
+ markClean(): void;
323
+ /**
324
+ * Get ALL viewport cells in ONE WASM call - the key performance optimization!
325
+ * Returns a reusable cell array (zero allocation after warmup).
326
+ */
327
+ getViewport(): GhosttyCell[];
328
+ /**
329
+ * Get line - for compatibility, extracts from viewport.
330
+ * Ensures render state is fresh by calling update().
331
+ * Returns a COPY of the cells to avoid pool reference issues.
332
+ */
333
+ getLine(y: number): GhosttyCell[] | null;
334
+ /** For compatibility with old API */
335
+ isDirty(): boolean;
336
+ /**
337
+ * Check if a full redraw is needed (screen change, resize, etc.)
338
+ * Note: This calls update() to ensure fresh state. Safe to call multiple times.
339
+ */
340
+ needsFullRedraw(): boolean;
341
+ /** Mark render state as clean after rendering */
342
+ clearDirty(): void;
343
+ isAlternateScreen(): boolean;
344
+ hasBracketedPaste(): boolean;
345
+ hasFocusEvents(): boolean;
346
+ hasMouseTracking(): boolean;
347
+ /** Get dimensions - for compatibility */
348
+ getDimensions(): {
349
+ cols: number;
350
+ rows: number;
351
+ };
352
+ /** Get number of scrollback lines (history, not including active screen) */
353
+ getScrollbackLength(): number;
354
+ /**
355
+ * Get a line from the scrollback buffer.
356
+ * Ensures render state is fresh by calling update().
357
+ * @param offset 0 = oldest line, (length-1) = most recent scrollback line
358
+ */
359
+ getScrollbackLine(offset: number): GhosttyCell[] | null;
360
+ /** Check if a row in the active screen is wrapped (soft-wrapped to next line) */
361
+ isRowWrapped(row: number): boolean;
362
+ /** Hyperlink URI not yet exposed in simplified API */
363
+ getHyperlinkUri(_id: number): string | null;
364
+ /**
365
+ * Check if there are pending responses from the terminal.
366
+ * Responses are generated by escape sequences like DSR (Device Status Report).
367
+ */
368
+ hasResponse(): boolean;
369
+ /**
370
+ * Read pending responses from the terminal.
371
+ * Returns the response string, or null if no responses pending.
372
+ *
373
+ * Responses are generated by escape sequences that require replies:
374
+ * - DSR 6 (cursor position): Returns \x1b[row;colR
375
+ * - DSR 5 (operating status): Returns \x1b[0n
376
+ */
377
+ readResponse(): string | null;
378
+ /**
379
+ * Query arbitrary terminal mode by number
380
+ * @param mode Mode number (e.g., 25 for cursor visibility, 2004 for bracketed paste)
381
+ * @param isAnsi True for ANSI modes, false for DEC modes (default: false)
382
+ */
383
+ getMode(mode: number, isAnsi?: boolean): boolean;
384
+ private initCellPool;
385
+ private parseCellsIntoPool;
386
+ /** Small buffer for grapheme lookups (reused to avoid allocation) */
387
+ private graphemeBuffer;
388
+ private graphemeBufferPtr;
389
+ /**
390
+ * Get all codepoints for a grapheme cluster at the given position.
391
+ * For most cells this returns a single codepoint, but for complex scripts
392
+ * (Hindi, emoji with ZWJ, etc.) it returns multiple codepoints.
393
+ * @returns Array of codepoints, or null on error
394
+ */
395
+ getGrapheme(row: number, col: number): number[] | null;
396
+ /**
397
+ * Get a string representation of the grapheme at the given position.
398
+ * This properly handles complex scripts like Hindi, emoji with ZWJ, etc.
399
+ */
400
+ getGraphemeString(row: number, col: number): string;
401
+ /**
402
+ * Get all codepoints for a grapheme cluster in the scrollback buffer.
403
+ * @param offset Scrollback line offset (0 = oldest)
404
+ * @param col Column index
405
+ * @returns Array of codepoints, or null on error
406
+ */
407
+ getScrollbackGrapheme(offset: number, col: number): number[] | null;
408
+ /**
409
+ * Get a string representation of a grapheme in the scrollback buffer.
410
+ */
411
+ getScrollbackGraphemeString(offset: number, col: number): string;
412
+ private invalidateBuffers;
413
+ }
414
+
415
+ /**
416
+ * Terminal configuration (passed to ghostty_terminal_new_with_config)
417
+ * All color values use 0xRRGGBB format. A value of 0 means "use default".
418
+ */
419
+ declare interface GhosttyTerminalConfig {
420
+ scrollbackLimit?: number;
421
+ fgColor?: number;
422
+ bgColor?: number;
423
+ cursorColor?: number;
424
+ palette?: number[];
425
+ }
426
+
427
+ /**
428
+ * Interface for libghostty-vt WASM exports
429
+ */
430
+ declare interface GhosttyWasmExports extends WebAssembly.Exports {
431
+ memory: WebAssembly.Memory;
432
+ ghostty_wasm_alloc_opaque(): number;
433
+ ghostty_wasm_free_opaque(ptr: number): void;
434
+ ghostty_wasm_alloc_u8_array(len: number): number;
435
+ ghostty_wasm_free_u8_array(ptr: number, len: number): void;
436
+ ghostty_wasm_alloc_u16_array(len: number): number;
437
+ ghostty_wasm_free_u16_array(ptr: number, len: number): void;
438
+ ghostty_wasm_alloc_u8(): number;
439
+ ghostty_wasm_free_u8(ptr: number): void;
440
+ ghostty_wasm_alloc_usize(): number;
441
+ ghostty_wasm_free_usize(ptr: number): void;
442
+ ghostty_sgr_new(allocator: number, parserPtrPtr: number): number;
443
+ ghostty_sgr_free(parser: number): void;
444
+ ghostty_sgr_reset(parser: number): void;
445
+ ghostty_sgr_set_params(parser: number, paramsPtr: number, subsPtr: number, paramsLen: number): number;
446
+ ghostty_sgr_next(parser: number, attrPtr: number): boolean;
447
+ ghostty_sgr_attribute_tag(attrPtr: number): number;
448
+ ghostty_sgr_attribute_value(attrPtr: number, tagPtr: number): number;
449
+ ghostty_wasm_alloc_sgr_attribute(): number;
450
+ ghostty_wasm_free_sgr_attribute(ptr: number): void;
451
+ ghostty_key_encoder_new(allocator: number, encoderPtrPtr: number): number;
452
+ ghostty_key_encoder_free(encoder: number): void;
453
+ ghostty_key_encoder_setopt(encoder: number, option: number, valuePtr: number): number;
454
+ ghostty_key_encoder_encode(encoder: number, eventPtr: number, bufPtr: number, bufLen: number, writtenPtr: number): number;
455
+ ghostty_key_event_new(allocator: number, eventPtrPtr: number): number;
456
+ ghostty_key_event_free(event: number): void;
457
+ ghostty_key_event_set_action(event: number, action: number): void;
458
+ ghostty_key_event_set_key(event: number, key: number): void;
459
+ ghostty_key_event_set_mods(event: number, mods: number): void;
460
+ ghostty_key_event_set_utf8(event: number, ptr: number, len: number): void;
461
+ ghostty_terminal_new(cols: number, rows: number): TerminalHandle;
462
+ ghostty_terminal_new_with_config(cols: number, rows: number, configPtr: number): TerminalHandle;
463
+ ghostty_terminal_free(terminal: TerminalHandle): void;
464
+ ghostty_terminal_resize(terminal: TerminalHandle, cols: number, rows: number): void;
465
+ ghostty_terminal_write(terminal: TerminalHandle, dataPtr: number, dataLen: number): void;
466
+ ghostty_render_state_update(terminal: TerminalHandle): number;
467
+ ghostty_render_state_get_cols(terminal: TerminalHandle): number;
468
+ ghostty_render_state_get_rows(terminal: TerminalHandle): number;
469
+ ghostty_render_state_get_cursor_x(terminal: TerminalHandle): number;
470
+ ghostty_render_state_get_cursor_y(terminal: TerminalHandle): number;
471
+ ghostty_render_state_get_cursor_visible(terminal: TerminalHandle): boolean;
472
+ ghostty_render_state_get_bg_color(terminal: TerminalHandle): number;
473
+ ghostty_render_state_get_fg_color(terminal: TerminalHandle): number;
474
+ ghostty_render_state_is_row_dirty(terminal: TerminalHandle, row: number): boolean;
475
+ ghostty_render_state_mark_clean(terminal: TerminalHandle): void;
476
+ ghostty_render_state_get_viewport(terminal: TerminalHandle, bufPtr: number, bufLen: number): number;
477
+ ghostty_render_state_get_grapheme(terminal: TerminalHandle, row: number, col: number, bufPtr: number, bufLen: number): number;
478
+ ghostty_terminal_is_alternate_screen(terminal: TerminalHandle): boolean;
479
+ ghostty_terminal_has_mouse_tracking(terminal: TerminalHandle): number;
480
+ ghostty_terminal_get_mode(terminal: TerminalHandle, mode: number, isAnsi: boolean): number;
481
+ ghostty_terminal_get_scrollback_length(terminal: TerminalHandle): number;
482
+ ghostty_terminal_get_scrollback_line(terminal: TerminalHandle, offset: number, bufPtr: number, bufLen: number): number;
483
+ ghostty_terminal_get_scrollback_grapheme(terminal: TerminalHandle, offset: number, col: number, bufPtr: number, bufLen: number): number;
484
+ ghostty_terminal_is_row_wrapped(terminal: TerminalHandle, row: number): number;
485
+ ghostty_terminal_has_response(terminal: TerminalHandle): boolean;
486
+ ghostty_terminal_read_response(terminal: TerminalHandle, bufPtr: number, bufLen: number): number;
487
+ }
488
+
489
+ /**
490
+ * A terminal buffer (normal or alternate screen)
491
+ */
492
+ declare interface IBuffer {
493
+ /** Buffer type: 'normal' or 'alternate' */
494
+ readonly type: 'normal' | 'alternate';
495
+ /** Cursor X position (0-indexed) */
496
+ readonly cursorX: number;
497
+ /** Cursor Y position (0-indexed, relative to viewport) */
498
+ readonly cursorY: number;
499
+ /** Viewport Y position (scroll offset, 0 = bottom of scrollback) */
500
+ readonly viewportY: number;
501
+ /** Base Y position (always 0 for normal buffer, may vary for alternate) */
502
+ readonly baseY: number;
503
+ /** Total buffer length (rows + scrollback for normal, just rows for alternate) */
504
+ readonly length: number;
505
+ /**
506
+ * Get a line from the buffer
507
+ * @param y Line index (0 = top of scrollback for normal buffer)
508
+ * @returns Line object or undefined if out of bounds
509
+ */
510
+ getLine(y: number): IBufferLine | undefined;
511
+ /**
512
+ * Get the null cell (used for empty/uninitialized cells)
513
+ */
514
+ getNullCell(): IBufferCell;
515
+ }
516
+
517
+ /**
518
+ * A single cell in the buffer
519
+ */
520
+ declare interface IBufferCell {
521
+ /** Character(s) in this cell (may be empty, single char, or emoji) */
522
+ getChars(): string;
523
+ /** Unicode codepoint (0 for null cell) */
524
+ getCode(): number;
525
+ /** Character width (1 = normal, 2 = wide/emoji, 0 = combining) */
526
+ getWidth(): number;
527
+ /** Foreground color index (for palette colors) or -1 for RGB */
528
+ getFgColorMode(): number;
529
+ /** Background color index (for palette colors) or -1 for RGB */
530
+ getBgColorMode(): number;
531
+ /** Foreground RGB color (or 0 for default) */
532
+ getFgColor(): number;
533
+ /** Background RGB color (or 0 for default) */
534
+ getBgColor(): number;
535
+ /** Whether cell has bold style */
536
+ isBold(): number;
537
+ /** Whether cell has italic style */
538
+ isItalic(): number;
539
+ /** Whether cell has underline style */
540
+ isUnderline(): number;
541
+ /** Whether cell has strikethrough style */
542
+ isStrikethrough(): number;
543
+ /** Whether cell has blink style */
544
+ isBlink(): number;
545
+ /** Whether cell has inverse video style */
546
+ isInverse(): number;
547
+ /** Whether cell has invisible style */
548
+ isInvisible(): number;
549
+ /** Whether cell has faint/dim style */
550
+ isFaint(): number;
551
+ /** Get hyperlink ID for this cell (0 = no link) */
552
+ getHyperlinkId(): number;
553
+ /** Get the Unicode codepoint for this cell */
554
+ getCodepoint(): number;
555
+ /** Whether cell has dim/faint attribute (boolean version) */
556
+ isDim(): boolean;
557
+ }
558
+
559
+ /**
560
+ * Represents a coordinate in the terminal buffer
561
+ */
562
+ export declare interface IBufferCellPosition {
563
+ x: number;
564
+ y: number;
565
+ }
566
+
567
+ /**
568
+ * A single line in the buffer
569
+ */
570
+ declare interface IBufferLine {
571
+ /** Length of the line (in columns) */
572
+ readonly length: number;
573
+ /** Whether this line wraps to the next line */
574
+ readonly isWrapped: boolean;
575
+ /**
576
+ * Get a cell from this line
577
+ * @param x Column index (0-indexed)
578
+ * @returns Cell object or undefined if out of bounds
579
+ */
580
+ getCell(x: number): IBufferCell | undefined;
581
+ /**
582
+ * Translate the line to a string
583
+ * @param trimRight Whether to trim trailing whitespace (default: false)
584
+ * @param startColumn Start column (default: 0)
585
+ * @param endColumn End column (default: length)
586
+ * @returns String representation of the line
587
+ */
588
+ translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
589
+ }
590
+
591
+ /**
592
+ * Minimal buffer line interface for URL detection
593
+ */
594
+ declare interface IBufferLineForUrlProvider {
595
+ length: number;
596
+ getCell(x: number): {
597
+ getCodepoint(): number;
598
+ } | undefined;
599
+ }
600
+
601
+ /**
602
+ * Top-level buffer API namespace
603
+ * Provides access to active, normal, and alternate screen buffers
604
+ */
605
+ declare interface IBufferNamespace {
606
+ /** The currently active buffer (normal or alternate) */
607
+ readonly active: IBuffer;
608
+ /** The normal buffer (primary screen) */
609
+ readonly normal: IBuffer;
610
+ /** The alternate buffer (used by full-screen apps like vim) */
611
+ readonly alternate: IBuffer;
612
+ /** Event fired when buffer changes (normal ↔ alternate) */
613
+ readonly onBufferChange: IEvent<IBuffer>;
614
+ }
615
+
616
+ /**
617
+ * Buffer range for selection coordinates
618
+ */
619
+ export declare interface IBufferRange {
620
+ start: {
621
+ x: number;
622
+ y: number;
623
+ };
624
+ end: {
625
+ x: number;
626
+ y: number;
627
+ };
628
+ }
629
+
630
+ /**
631
+ * Represents a range in the terminal buffer
632
+ * Can span multiple lines for wrapped links
633
+ */
634
+ declare interface IBufferRange_2 {
635
+ start: IBufferCellPosition;
636
+ end: IBufferCellPosition;
637
+ }
638
+
639
+ export declare interface IDisposable {
640
+ dispose(): void;
641
+ }
642
+
643
+ export declare type IEvent<T> = (listener: (arg: T) => void) => IDisposable;
644
+
645
+ /**
646
+ * Keyboard event with key and DOM event
647
+ */
648
+ export declare interface IKeyEvent {
649
+ key: string;
650
+ domEvent: KeyboardEvent;
651
+ }
652
+
653
+ /**
654
+ * Represents a detected link in the terminal
655
+ */
656
+ export declare interface ILink {
657
+ /** The URL or text of the link */
658
+ text: string;
659
+ /** The range of the link in the buffer (may span multiple lines) */
660
+ range: IBufferRange_2;
661
+ /** Called when the link is activated (clicked with modifier) */
662
+ activate(event: MouseEvent): void;
663
+ /** Optional: called when mouse enters/leaves the link */
664
+ hover?(isHovered: boolean): void;
665
+ /** Optional: called to clean up resources */
666
+ dispose?(): void;
667
+ }
668
+
669
+ /**
670
+ * Provides link detection for a specific type of link
671
+ * Examples: OSC 8 hyperlinks, URL regex detection
672
+ */
673
+ export declare interface ILinkProvider {
674
+ /**
675
+ * Provide links for a given row
676
+ * @param y Absolute row in buffer (0-based)
677
+ * @param callback Called with detected links (or undefined if none)
678
+ */
679
+ provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void;
680
+ /** Optional: called when terminal is disposed */
681
+ dispose?(): void;
682
+ }
683
+
684
+ /**
685
+ * Initialize the ghostty-web library by loading the WASM module.
686
+ * Must be called before creating any Terminal instances.
687
+ *
688
+ * This creates a shared WASM instance that all Terminal instances will use.
689
+ * For test isolation, pass a Ghostty instance directly to Terminal constructor.
690
+ *
691
+ * @example
692
+ * ```typescript
693
+ * import { init, Terminal } from 'ghostty-web';
694
+ *
695
+ * await init();
696
+ * const term = new Terminal();
697
+ * term.open(document.getElementById('terminal'));
698
+ * ```
699
+ */
700
+ export declare function init(): Promise<void>;
701
+
702
+ /**
703
+ * InputHandler class
704
+ * Attaches keyboard event listeners to a container and converts
705
+ * keyboard events to terminal input data
706
+ */
707
+ export declare class InputHandler {
708
+ private encoder;
709
+ private container;
710
+ private inputElement?;
711
+ private onDataCallback;
712
+ private onBellCallback;
713
+ private onKeyCallback?;
714
+ private customKeyEventHandler?;
715
+ private getModeCallback?;
716
+ private onCopyCallback?;
717
+ private keydownListener;
718
+ private keypressListener;
719
+ private pasteListener;
720
+ private beforeInputListener;
721
+ private compositionStartListener;
722
+ private compositionUpdateListener;
723
+ private compositionEndListener;
724
+ private isComposing;
725
+ private isDisposed;
726
+ private lastKeyDownData;
727
+ private lastKeyDownTime;
728
+ private lastPasteData;
729
+ private lastPasteTime;
730
+ private lastPasteSource;
731
+ private lastCompositionData;
732
+ private lastCompositionTime;
733
+ private lastBeforeInputData;
734
+ private lastBeforeInputTime;
735
+ private static readonly BEFORE_INPUT_IGNORE_MS;
736
+ /**
737
+ * Create a new InputHandler
738
+ * @param ghostty - Ghostty instance (for creating KeyEncoder)
739
+ * @param container - DOM element to attach listeners to
740
+ * @param onData - Callback for terminal data (escape sequences to send to PTY)
741
+ * @param onBell - Callback for bell/beep event
742
+ * @param onKey - Optional callback for raw key events
743
+ * @param customKeyEventHandler - Optional custom key event handler
744
+ * @param getMode - Optional callback to query terminal mode state (for application cursor mode)
745
+ * @param onCopy - Optional callback to handle copy (Cmd+C/Ctrl+C with selection)
746
+ */
747
+ 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);
748
+ /**
749
+ * Set custom key event handler (for runtime updates)
750
+ */
751
+ setCustomKeyEventHandler(handler: (event: KeyboardEvent) => boolean): void;
752
+ /**
753
+ * Attach keyboard event listeners to container
754
+ */
755
+ private attach;
756
+ /**
757
+ * Map KeyboardEvent.code to USB HID Key enum value
758
+ * @param code - KeyboardEvent.code value
759
+ * @returns Key enum value or null if unmapped
760
+ */
761
+ private mapKeyCode;
762
+ /**
763
+ * Extract modifier flags from KeyboardEvent
764
+ * @param event - KeyboardEvent
765
+ * @returns Mods flags
766
+ */
767
+ private extractModifiers;
768
+ /**
769
+ * Check if this is a printable character with no special modifiers
770
+ * @param event - KeyboardEvent
771
+ * @returns true if printable character
772
+ */
773
+ private isPrintableCharacter;
774
+ /**
775
+ * Handle keydown event
776
+ * @param event - KeyboardEvent
777
+ */
778
+ private handleKeyDown;
779
+ /**
780
+ * Handle paste event from clipboard
781
+ * @param event - ClipboardEvent
782
+ */
783
+ private handlePaste;
784
+ /**
785
+ * Handle beforeinput event (mobile/IME input)
786
+ * @param event - InputEvent
787
+ */
788
+ private handleBeforeInput;
789
+ /**
790
+ * Handle compositionstart event
791
+ */
792
+ private handleCompositionStart;
793
+ /**
794
+ * Handle compositionupdate event
795
+ */
796
+ private handleCompositionUpdate;
797
+ /**
798
+ * Handle compositionend event
799
+ */
800
+ private handleCompositionEnd;
801
+ /**
802
+ * Cleanup text nodes in container after composition
803
+ */
804
+ private cleanupCompositionTextNodes;
805
+ /**
806
+ * Emit paste data with bracketed paste support
807
+ */
808
+ private emitPasteData;
809
+ /**
810
+ * Record keydown data for beforeinput de-duplication
811
+ */
812
+ private recordKeyDownData;
813
+ /**
814
+ * Record paste data for beforeinput de-duplication
815
+ */
816
+ private recordPasteData;
817
+ /**
818
+ * Check if beforeinput should be ignored due to a recent keydown
819
+ */
820
+ private shouldIgnoreBeforeInput;
821
+ /**
822
+ * Check if beforeinput text should be ignored due to a recent composition end
823
+ */
824
+ private shouldIgnoreBeforeInputFromComposition;
825
+ /**
826
+ * Check if composition end should be ignored due to a recent beforeinput text
827
+ */
828
+ private shouldIgnoreCompositionEnd;
829
+ /**
830
+ * Record beforeinput text for composition de-duplication
831
+ */
832
+ private recordBeforeInputData;
833
+ /**
834
+ * Record composition end data for beforeinput de-duplication
835
+ */
836
+ private recordCompositionData;
837
+ /**
838
+ * Check if paste should be ignored due to a recent paste event from another source
839
+ */
840
+ private shouldIgnorePasteEvent;
841
+ /**
842
+ * Get current time in milliseconds
843
+ */
844
+ private getNow;
845
+ /**
846
+ * Dispose the InputHandler and remove event listeners
847
+ */
848
+ dispose(): void;
849
+ /**
850
+ * Check if handler is disposed
851
+ */
852
+ isActive(): boolean;
853
+ }
854
+
855
+ export declare interface IRenderable {
856
+ getLine(y: number): GhosttyCell[] | null;
857
+ getCursor(): {
858
+ x: number;
859
+ y: number;
860
+ visible: boolean;
861
+ };
862
+ getDimensions(): {
863
+ cols: number;
864
+ rows: number;
865
+ };
866
+ isRowDirty(y: number): boolean;
867
+ /** Returns true if a full redraw is needed (e.g., screen change) */
868
+ needsFullRedraw?(): boolean;
869
+ clearDirty(): void;
870
+ /**
871
+ * Get the full grapheme string for a cell at (row, col).
872
+ * For cells with grapheme_len > 0, this returns all codepoints combined.
873
+ * For simple cells, returns the single character.
874
+ */
875
+ getGraphemeString?(row: number, col: number): string;
876
+ }
877
+
878
+ declare interface IScrollbackProvider {
879
+ getScrollbackLine(offset: number): GhosttyCell[] | null;
880
+ getScrollbackLength(): number;
881
+ }
882
+
883
+ export declare interface ITerminalAddon {
884
+ activate(terminal: ITerminalCore): void;
885
+ dispose(): void;
886
+ }
887
+
888
+ export declare interface ITerminalCore {
889
+ cols: number;
890
+ rows: number;
891
+ element?: HTMLElement;
892
+ textarea?: HTMLTextAreaElement;
893
+ }
894
+
895
+ export declare interface ITerminalDimensions {
896
+ cols: number;
897
+ rows: number;
898
+ }
899
+
900
+ /**
901
+ * Minimal terminal interface required by LinkDetector
902
+ * Keeps coupling low and testing easy
903
+ */
904
+ declare interface ITerminalForLinkDetector {
905
+ buffer: {
906
+ active: {
907
+ getLine(y: number): {
908
+ length: number;
909
+ getCell(x: number): {
910
+ getHyperlinkId(): number;
911
+ } | undefined;
912
+ } | undefined;
913
+ };
914
+ };
915
+ }
916
+
917
+ /**
918
+ * Minimal terminal interface required by OSC8LinkProvider
919
+ */
920
+ declare interface ITerminalForOSC8Provider {
921
+ buffer: {
922
+ active: {
923
+ length: number;
924
+ getLine(y: number): {
925
+ length: number;
926
+ getCell(x: number): {
927
+ getHyperlinkId(): number;
928
+ } | undefined;
929
+ } | undefined;
930
+ };
931
+ };
932
+ wasmTerm?: {
933
+ getHyperlinkUri(id: number): string | null;
934
+ };
935
+ }
936
+
937
+ /**
938
+ * Minimal terminal interface required by UrlRegexProvider
939
+ */
940
+ declare interface ITerminalForUrlProvider {
941
+ buffer: {
942
+ active: {
943
+ getLine(y: number): IBufferLineForUrlProvider | undefined;
944
+ };
945
+ };
946
+ }
947
+
948
+ export declare interface ITerminalOptions {
949
+ cols?: number;
950
+ rows?: number;
951
+ cursorBlink?: boolean;
952
+ cursorStyle?: 'block' | 'underline' | 'bar';
953
+ theme?: ITheme;
954
+ scrollback?: number;
955
+ fontSize?: number;
956
+ fontFamily?: string;
957
+ allowTransparency?: boolean;
958
+ convertEol?: boolean;
959
+ disableStdin?: boolean;
960
+ smoothScrollDuration?: number;
961
+ scrollbarVisible?: boolean;
962
+ ghostty?: Ghostty;
963
+ }
964
+
965
+ export declare interface ITheme {
966
+ foreground?: string;
967
+ background?: string;
968
+ cursor?: string;
969
+ cursorAccent?: string;
970
+ selectionBackground?: string;
971
+ selectionForeground?: string;
972
+ black?: string;
973
+ red?: string;
974
+ green?: string;
975
+ yellow?: string;
976
+ blue?: string;
977
+ magenta?: string;
978
+ cyan?: string;
979
+ white?: string;
980
+ brightBlack?: string;
981
+ brightRed?: string;
982
+ brightGreen?: string;
983
+ brightYellow?: string;
984
+ brightBlue?: string;
985
+ brightMagenta?: string;
986
+ brightCyan?: string;
987
+ brightWhite?: string;
988
+ }
989
+
990
+ /**
991
+ * Unicode version provider (xterm.js compatibility)
992
+ */
993
+ export declare interface IUnicodeVersionProvider {
994
+ readonly activeVersion: string;
995
+ }
996
+
997
+ /**
998
+ * Physical key codes matching Ghostty's internal Key enum.
999
+ * These values are used by Ghostty's key encoder to produce correct escape sequences.
1000
+ * Reference: ghostty/src/input/key.zig
1001
+ */
1002
+ export declare enum Key {
1003
+ UNIDENTIFIED = 0,
1004
+ GRAVE = 1,// ` and ~
1005
+ BACKSLASH = 2,// \ and |
1006
+ BRACKET_LEFT = 3,// [ and {
1007
+ BRACKET_RIGHT = 4,// ] and }
1008
+ COMMA = 5,// , and <
1009
+ ZERO = 6,
1010
+ ONE = 7,
1011
+ TWO = 8,
1012
+ THREE = 9,
1013
+ FOUR = 10,
1014
+ FIVE = 11,
1015
+ SIX = 12,
1016
+ SEVEN = 13,
1017
+ EIGHT = 14,
1018
+ NINE = 15,
1019
+ EQUAL = 16,// = and +
1020
+ INTL_BACKSLASH = 17,
1021
+ INTL_RO = 18,
1022
+ INTL_YEN = 19,
1023
+ A = 20,
1024
+ B = 21,
1025
+ C = 22,
1026
+ D = 23,
1027
+ E = 24,
1028
+ F = 25,
1029
+ G = 26,
1030
+ H = 27,
1031
+ I = 28,
1032
+ J = 29,
1033
+ K = 30,
1034
+ L = 31,
1035
+ M = 32,
1036
+ N = 33,
1037
+ O = 34,
1038
+ P = 35,
1039
+ Q = 36,
1040
+ R = 37,
1041
+ S = 38,
1042
+ T = 39,
1043
+ U = 40,
1044
+ V = 41,
1045
+ W = 42,
1046
+ X = 43,
1047
+ Y = 44,
1048
+ Z = 45,
1049
+ MINUS = 46,// - and _
1050
+ PERIOD = 47,// . and >
1051
+ QUOTE = 48,// ' and "
1052
+ SEMICOLON = 49,// ; and :
1053
+ SLASH = 50,// / and ?
1054
+ ALT_LEFT = 51,
1055
+ ALT_RIGHT = 52,
1056
+ BACKSPACE = 53,
1057
+ CAPS_LOCK = 54,
1058
+ CONTEXT_MENU = 55,
1059
+ CONTROL_LEFT = 56,
1060
+ CONTROL_RIGHT = 57,
1061
+ ENTER = 58,
1062
+ META_LEFT = 59,
1063
+ META_RIGHT = 60,
1064
+ SHIFT_LEFT = 61,
1065
+ SHIFT_RIGHT = 62,
1066
+ SPACE = 63,
1067
+ TAB = 64,
1068
+ CONVERT = 65,
1069
+ KANA_MODE = 66,
1070
+ NON_CONVERT = 67,
1071
+ DELETE = 68,
1072
+ END = 69,
1073
+ HELP = 70,
1074
+ HOME = 71,
1075
+ INSERT = 72,
1076
+ PAGE_DOWN = 73,
1077
+ PAGE_UP = 74,
1078
+ DOWN = 75,
1079
+ LEFT = 76,
1080
+ RIGHT = 77,
1081
+ UP = 78,
1082
+ NUM_LOCK = 79,
1083
+ KP_0 = 80,
1084
+ KP_1 = 81,
1085
+ KP_2 = 82,
1086
+ KP_3 = 83,
1087
+ KP_4 = 84,
1088
+ KP_5 = 85,
1089
+ KP_6 = 86,
1090
+ KP_7 = 87,
1091
+ KP_8 = 88,
1092
+ KP_9 = 89,
1093
+ KP_PLUS = 90,// Keypad +
1094
+ KP_BACKSPACE = 91,
1095
+ KP_CLEAR = 92,
1096
+ KP_CLEAR_ENTRY = 93,
1097
+ KP_COMMA = 94,
1098
+ KP_PERIOD = 95,// Keypad .
1099
+ KP_DIVIDE = 96,// Keypad /
1100
+ KP_ENTER = 97,// Keypad Enter
1101
+ KP_EQUAL = 98,
1102
+ KP_MEMORY_ADD = 99,
1103
+ KP_MEMORY_CLEAR = 100,
1104
+ KP_MEMORY_RECALL = 101,
1105
+ KP_MEMORY_STORE = 102,
1106
+ KP_MEMORY_SUBTRACT = 103,
1107
+ KP_MULTIPLY = 104,// Keypad *
1108
+ KP_PAREN_LEFT = 105,
1109
+ KP_PAREN_RIGHT = 106,
1110
+ KP_MINUS = 107,// Keypad -
1111
+ KP_SEPARATOR = 108,
1112
+ NUMPAD_UP = 109,
1113
+ NUMPAD_DOWN = 110,
1114
+ NUMPAD_RIGHT = 111,
1115
+ NUMPAD_LEFT = 112,
1116
+ NUMPAD_BEGIN = 113,
1117
+ NUMPAD_HOME = 114,
1118
+ NUMPAD_END = 115,
1119
+ NUMPAD_INSERT = 116,
1120
+ NUMPAD_DELETE = 117,
1121
+ NUMPAD_PAGE_UP = 118,
1122
+ NUMPAD_PAGE_DOWN = 119,
1123
+ ESCAPE = 120,
1124
+ F1 = 121,
1125
+ F2 = 122,
1126
+ F3 = 123,
1127
+ F4 = 124,
1128
+ F5 = 125,
1129
+ F6 = 126,
1130
+ F7 = 127,
1131
+ F8 = 128,
1132
+ F9 = 129,
1133
+ F10 = 130,
1134
+ F11 = 131,
1135
+ F12 = 132,
1136
+ F13 = 133,
1137
+ F14 = 134,
1138
+ F15 = 135,
1139
+ F16 = 136,
1140
+ F17 = 137,
1141
+ F18 = 138,
1142
+ F19 = 139,
1143
+ F20 = 140,
1144
+ F21 = 141,
1145
+ F22 = 142,
1146
+ F23 = 143,
1147
+ F24 = 144,
1148
+ F25 = 145,
1149
+ FN_LOCK = 146,
1150
+ PRINT_SCREEN = 147,
1151
+ SCROLL_LOCK = 148,
1152
+ PAUSE = 149,
1153
+ BROWSER_BACK = 150,
1154
+ BROWSER_FAVORITES = 151,
1155
+ BROWSER_FORWARD = 152,
1156
+ BROWSER_HOME = 153,
1157
+ BROWSER_REFRESH = 154,
1158
+ BROWSER_SEARCH = 155,
1159
+ BROWSER_STOP = 156,
1160
+ EJECT = 157,
1161
+ LAUNCH_APP_1 = 158,
1162
+ LAUNCH_APP_2 = 159,
1163
+ LAUNCH_MAIL = 160,
1164
+ MEDIA_PLAY_PAUSE = 161,
1165
+ MEDIA_SELECT = 162,
1166
+ MEDIA_STOP = 163,
1167
+ MEDIA_TRACK_NEXT = 164,
1168
+ MEDIA_TRACK_PREVIOUS = 165,
1169
+ POWER = 166,
1170
+ SLEEP = 167,
1171
+ AUDIO_VOLUME_DOWN = 168,
1172
+ AUDIO_VOLUME_MUTE = 169,
1173
+ AUDIO_VOLUME_UP = 170,
1174
+ WAKE_UP = 171,
1175
+ COPY = 172,
1176
+ CUT = 173,
1177
+ PASTE = 174
1178
+ }
1179
+
1180
+ /**
1181
+ * Key action
1182
+ */
1183
+ export declare enum KeyAction {
1184
+ RELEASE = 0,
1185
+ PRESS = 1,
1186
+ REPEAT = 2
1187
+ }
1188
+
1189
+ /**
1190
+ * Key Encoder - converts keyboard events into terminal escape sequences
1191
+ */
1192
+ export declare class KeyEncoder {
1193
+ private exports;
1194
+ private encoder;
1195
+ constructor(exports: GhosttyWasmExports);
1196
+ setOption(option: KeyEncoderOption, value: boolean | number): void;
1197
+ setKittyFlags(flags: KittyKeyFlags): void;
1198
+ encode(event: KeyEvent): Uint8Array;
1199
+ dispose(): void;
1200
+ }
1201
+
1202
+ /**
1203
+ * Key encoder options
1204
+ */
1205
+ export declare enum KeyEncoderOption {
1206
+ CURSOR_KEY_APPLICATION = 0,// DEC mode 1
1207
+ KEYPAD_KEY_APPLICATION = 1,// DEC mode 66
1208
+ IGNORE_KEYPAD_WITH_NUMLOCK = 2,// DEC mode 1035
1209
+ ALT_ESC_PREFIX = 3,// DEC mode 1036
1210
+ MODIFY_OTHER_KEYS_STATE_2 = 4,// xterm modifyOtherKeys
1211
+ KITTY_KEYBOARD_FLAGS = 5
1212
+ }
1213
+
1214
+ /**
1215
+ * Key event structure
1216
+ */
1217
+ export declare interface KeyEvent {
1218
+ action: KeyAction;
1219
+ key: Key;
1220
+ mods: Mods;
1221
+ consumedMods?: Mods;
1222
+ composing?: boolean;
1223
+ utf8?: string;
1224
+ unshiftedCodepoint?: number;
1225
+ }
1226
+
1227
+ /**
1228
+ * Kitty keyboard protocol flags
1229
+ * From include/ghostty/vt/key/encoder.h
1230
+ */
1231
+ declare enum KittyKeyFlags {
1232
+ DISABLED = 0,
1233
+ DISAMBIGUATE = 1,// Disambiguate escape codes
1234
+ REPORT_EVENTS = 2,// Report press and release
1235
+ REPORT_ALTERNATES = 4,// Report alternate key codes
1236
+ REPORT_ALL = 8,// Report all events
1237
+ REPORT_ASSOCIATED = 16,// Report associated text
1238
+ ALL = 31
1239
+ }
1240
+
1241
+ /**
1242
+ * Manages link detection across multiple providers with intelligent caching
1243
+ */
1244
+ export declare class LinkDetector {
1245
+ private terminal;
1246
+ private providers;
1247
+ private linkCache;
1248
+ private scannedRows;
1249
+ constructor(terminal: ITerminalForLinkDetector);
1250
+ /**
1251
+ * Register a link provider
1252
+ */
1253
+ registerProvider(provider: ILinkProvider): void;
1254
+ /**
1255
+ * Get link at the specified buffer position
1256
+ * @param col Column (0-based)
1257
+ * @param row Absolute row in buffer (0-based)
1258
+ * @returns Link at position, or undefined if none
1259
+ */
1260
+ getLinkAt(col: number, row: number): Promise<ILink | undefined>;
1261
+ /**
1262
+ * Scan a row for links using all registered providers
1263
+ */
1264
+ private scanRow;
1265
+ /**
1266
+ * Cache a link for fast lookup
1267
+ */
1268
+ private cacheLink;
1269
+ /**
1270
+ * Check if a position is within a link's range
1271
+ */
1272
+ private isPositionInLink;
1273
+ /**
1274
+ * Invalidate cache when terminal content changes
1275
+ * Should be called on terminal write, resize, or clear
1276
+ */
1277
+ invalidateCache(): void;
1278
+ /**
1279
+ * Invalidate cache for specific rows
1280
+ * Used when only part of the terminal changed
1281
+ */
1282
+ invalidateRows(startRow: number, endRow: number): void;
1283
+ /**
1284
+ * Dispose and cleanup
1285
+ */
1286
+ dispose(): void;
1287
+ }
1288
+
1289
+ /**
1290
+ * Modifier keys
1291
+ */
1292
+ export declare enum Mods {
1293
+ NONE = 0,
1294
+ SHIFT = 1,
1295
+ CTRL = 2,
1296
+ ALT = 4,
1297
+ SUPER = 8,// Windows/Command key
1298
+ CAPSLOCK = 16,
1299
+ NUMLOCK = 32
1300
+ }
1301
+
1302
+ /**
1303
+ * OSC 8 Hyperlink Provider
1304
+ *
1305
+ * Detects OSC 8 hyperlinks by scanning for hyperlink_id in cells.
1306
+ * Automatically handles multi-line links since Ghostty WASM preserves
1307
+ * hyperlink_id across wrapped lines.
1308
+ */
1309
+ export declare class OSC8LinkProvider implements ILinkProvider {
1310
+ private terminal;
1311
+ constructor(terminal: ITerminalForOSC8Provider);
1312
+ /**
1313
+ * Provide all OSC 8 links on the given row
1314
+ * Note: This may return links that span multiple rows
1315
+ */
1316
+ provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void;
1317
+ /**
1318
+ * Find the full extent of a link by scanning for contiguous cells
1319
+ * with the same hyperlink_id. Handles multi-line links.
1320
+ */
1321
+ private findLinkRange;
1322
+ dispose(): void;
1323
+ }
1324
+
1325
+ export declare interface RendererOptions {
1326
+ fontSize?: number;
1327
+ fontFamily?: string;
1328
+ cursorStyle?: 'block' | 'underline' | 'bar';
1329
+ cursorBlink?: boolean;
1330
+ theme?: ITheme;
1331
+ devicePixelRatio?: number;
1332
+ }
1333
+
1334
+ /**
1335
+ * Colors from RenderState (12 bytes packed)
1336
+ */
1337
+ declare interface RenderStateColors {
1338
+ background: RGB;
1339
+ foreground: RGB;
1340
+ cursor: RGB | null;
1341
+ }
1342
+
1343
+ /**
1344
+ * Cursor state from RenderState (8 bytes packed)
1345
+ * Layout: x(u16) + y(u16) + viewport_x(i16) + viewport_y(i16) + visible(bool) + blinking(bool) + style(u8) + _pad(u8)
1346
+ */
1347
+ declare interface RenderStateCursor {
1348
+ x: number;
1349
+ y: number;
1350
+ viewportX: number;
1351
+ viewportY: number;
1352
+ visible: boolean;
1353
+ blinking: boolean;
1354
+ style: 'block' | 'underline' | 'bar';
1355
+ }
1356
+
1357
+ /**
1358
+ * RGB color
1359
+ */
1360
+ export declare interface RGB {
1361
+ r: number;
1362
+ g: number;
1363
+ b: number;
1364
+ }
1365
+
1366
+ export declare interface SelectionCoordinates {
1367
+ startCol: number;
1368
+ startRow: number;
1369
+ endCol: number;
1370
+ endRow: number;
1371
+ }
1372
+
1373
+ export declare class SelectionManager {
1374
+ private terminal;
1375
+ private renderer;
1376
+ private wasmTerm;
1377
+ private textarea;
1378
+ private selectionStart;
1379
+ private selectionEnd;
1380
+ private isSelecting;
1381
+ private mouseDownTarget;
1382
+ private dirtySelectionRows;
1383
+ private selectionChangedEmitter;
1384
+ private boundMouseUpHandler;
1385
+ private boundContextMenuHandler;
1386
+ private boundClickHandler;
1387
+ private boundDocumentMouseMoveHandler;
1388
+ private autoScrollInterval;
1389
+ private autoScrollDirection;
1390
+ private static readonly AUTO_SCROLL_EDGE_SIZE;
1391
+ /**
1392
+ * Get current viewport Y position (how many lines scrolled into history)
1393
+ */
1394
+ private getViewportY;
1395
+ /**
1396
+ * Convert viewport row to absolute buffer row
1397
+ * Absolute row is an index into combined buffer: scrollback (0 to len-1) + screen (len to len+rows-1)
1398
+ */
1399
+ private viewportRowToAbsolute;
1400
+ /**
1401
+ * Convert absolute buffer row to viewport row (may be outside visible range)
1402
+ */
1403
+ private absoluteRowToViewport;
1404
+ private static readonly AUTO_SCROLL_SPEED;
1405
+ private static readonly AUTO_SCROLL_INTERVAL;
1406
+ constructor(terminal: Terminal, renderer: CanvasRenderer, wasmTerm: GhosttyTerminal, textarea: HTMLTextAreaElement);
1407
+ /**
1408
+ * Get the selected text as a string
1409
+ */
1410
+ getSelection(): string;
1411
+ /**
1412
+ * Check if there's an active selection
1413
+ */
1414
+ hasSelection(): boolean;
1415
+ /**
1416
+ * Copy the current selection to clipboard
1417
+ * @returns true if there was text to copy, false otherwise
1418
+ */
1419
+ copySelection(): boolean;
1420
+ /**
1421
+ * Clear the selection
1422
+ */
1423
+ clearSelection(): void;
1424
+ /**
1425
+ * Select all text in the terminal
1426
+ */
1427
+ selectAll(): void;
1428
+ /**
1429
+ * Select text at specific column and row with length
1430
+ * xterm.js compatible API
1431
+ */
1432
+ select(column: number, row: number, length: number): void;
1433
+ /**
1434
+ * Select entire lines from start to end
1435
+ * xterm.js compatible API
1436
+ */
1437
+ selectLines(start: number, end: number): void;
1438
+ /**
1439
+ * Get selection position as buffer range
1440
+ * xterm.js compatible API
1441
+ */
1442
+ getSelectionPosition(): {
1443
+ start: {
1444
+ x: number;
1445
+ y: number;
1446
+ };
1447
+ end: {
1448
+ x: number;
1449
+ y: number;
1450
+ };
1451
+ } | undefined;
1452
+ /**
1453
+ * Deselect all text
1454
+ * xterm.js compatible API
1455
+ */
1456
+ deselect(): void;
1457
+ /**
1458
+ * Focus the terminal (make it receive keyboard input)
1459
+ */
1460
+ focus(): void;
1461
+ /**
1462
+ * Get current selection coordinates (for rendering)
1463
+ */
1464
+ getSelectionCoords(): SelectionCoordinates | null;
1465
+ /**
1466
+ * Get dirty selection rows that need redraw (for clearing old highlight)
1467
+ */
1468
+ getDirtySelectionRows(): Set<number>;
1469
+ /**
1470
+ * Clear the dirty selection rows tracking (after redraw)
1471
+ */
1472
+ clearDirtySelectionRows(): void;
1473
+ /**
1474
+ * Get selection change event accessor
1475
+ */
1476
+ get onSelectionChange(): IEvent<void>;
1477
+ /**
1478
+ * Cleanup resources
1479
+ */
1480
+ dispose(): void;
1481
+ /**
1482
+ * Attach mouse event listeners to canvas
1483
+ */
1484
+ private attachEventListeners;
1485
+ /**
1486
+ * Mark current selection rows as dirty for redraw
1487
+ */
1488
+ private markCurrentSelectionDirty;
1489
+ /**
1490
+ * Update auto-scroll based on mouse Y position within canvas
1491
+ */
1492
+ private updateAutoScroll;
1493
+ /**
1494
+ * Start auto-scrolling in the given direction
1495
+ */
1496
+ private startAutoScroll;
1497
+ /**
1498
+ * Stop auto-scrolling
1499
+ */
1500
+ private stopAutoScroll;
1501
+ /**
1502
+ * Convert pixel coordinates to terminal cell coordinates
1503
+ */
1504
+ private pixelToCell;
1505
+ /**
1506
+ * Normalize selection coordinates (handle backward selection)
1507
+ * Returns coordinates in VIEWPORT space for rendering, clamped to visible area
1508
+ */
1509
+ private normalizeSelection;
1510
+ /**
1511
+ * Get word boundaries at a cell position
1512
+ */
1513
+ private getWordAtCell;
1514
+ /**
1515
+ * Copy text to clipboard
1516
+ *
1517
+ * Strategy (modern APIs first):
1518
+ * 1. Try ClipboardItem API (works in Safari and modern browsers)
1519
+ * - Safari requires the ClipboardItem to be created synchronously within user gesture
1520
+ * 2. Try navigator.clipboard.writeText (modern async API, may fail in Safari)
1521
+ * 3. Fall back to execCommand (legacy, for older browsers)
1522
+ */
1523
+ private copyToClipboard;
1524
+ /**
1525
+ * Copy using navigator.clipboard.writeText
1526
+ */
1527
+ private copyWithWriteText;
1528
+ /**
1529
+ * Copy using legacy execCommand (fallback for older browsers)
1530
+ */
1531
+ private copyWithExecCommand;
1532
+ /**
1533
+ * Request a render update (triggers selection overlay redraw)
1534
+ */
1535
+ private requestRender;
1536
+ }
1537
+
1538
+ export declare class Terminal implements ITerminalCore {
1539
+ cols: number;
1540
+ rows: number;
1541
+ element?: HTMLElement;
1542
+ textarea?: HTMLTextAreaElement;
1543
+ readonly buffer: IBufferNamespace;
1544
+ readonly unicode: IUnicodeVersionProvider;
1545
+ readonly options: Required<ITerminalOptions>;
1546
+ private ghostty?;
1547
+ wasmTerm?: GhosttyTerminal;
1548
+ renderer?: CanvasRenderer;
1549
+ private inputHandler?;
1550
+ private selectionManager?;
1551
+ private canvas?;
1552
+ private touchScrollActive;
1553
+ private touchScrollLastY;
1554
+ private linkDetector?;
1555
+ private currentHoveredLink?;
1556
+ private mouseMoveThrottleTimeout?;
1557
+ private pendingMouseMove?;
1558
+ private dataEmitter;
1559
+ private resizeEmitter;
1560
+ private bellEmitter;
1561
+ private selectionChangeEmitter;
1562
+ private keyEmitter;
1563
+ private titleChangeEmitter;
1564
+ private directoryChangeEmitter;
1565
+ private scrollEmitter;
1566
+ private renderEmitter;
1567
+ private cursorMoveEmitter;
1568
+ readonly onData: IEvent<string>;
1569
+ readonly onResize: IEvent<{
1570
+ cols: number;
1571
+ rows: number;
1572
+ }>;
1573
+ readonly onBell: IEvent<void>;
1574
+ readonly onSelectionChange: IEvent<void>;
1575
+ readonly onKey: IEvent<IKeyEvent>;
1576
+ readonly onTitleChange: IEvent<string>;
1577
+ readonly onDirectoryChange: IEvent<string>;
1578
+ readonly onScroll: IEvent<number>;
1579
+ readonly onRender: IEvent<{
1580
+ start: number;
1581
+ end: number;
1582
+ }>;
1583
+ readonly onCursorMove: IEvent<void>;
1584
+ private isOpen;
1585
+ private isDisposed;
1586
+ private animationFrameId?;
1587
+ private addons;
1588
+ private customKeyEventHandler?;
1589
+ private currentTitle;
1590
+ private currentDirectory;
1591
+ viewportY: number;
1592
+ private targetViewportY;
1593
+ private scrollAnimationStartTime?;
1594
+ private scrollAnimationStartY?;
1595
+ private scrollAnimationFrame?;
1596
+ private customWheelEventHandler?;
1597
+ private lastCursorY;
1598
+ private isDraggingScrollbar;
1599
+ private scrollbarDragStart;
1600
+ private scrollbarDragStartViewportY;
1601
+ private scrollbarVisible;
1602
+ private scrollbarOpacity;
1603
+ private scrollbarHideTimeout?;
1604
+ private readonly SCROLLBAR_HIDE_DELAY_MS;
1605
+ private readonly SCROLLBAR_FADE_DURATION_MS;
1606
+ constructor(options?: ITerminalOptions);
1607
+ /**
1608
+ * Handle runtime option changes (called when options are modified after terminal is open)
1609
+ * This enables xterm.js compatibility where options can be changed at runtime
1610
+ */
1611
+ private handleOptionChange;
1612
+ /**
1613
+ * Handle font changes (fontSize or fontFamily)
1614
+ * Updates canvas size to match new font metrics and forces a full re-render
1615
+ */
1616
+ private handleFontChange;
1617
+ /**
1618
+ * Parse a CSS color string to 0xRRGGBB format.
1619
+ * Returns 0 if the color is undefined or invalid.
1620
+ */
1621
+ private parseColorToHex;
1622
+ /**
1623
+ * Convert terminal options to WASM terminal config.
1624
+ */
1625
+ private buildWasmConfig;
1626
+ /**
1627
+ * Open terminal in a parent element
1628
+ *
1629
+ * Initializes all components and starts rendering.
1630
+ * Requires a pre-loaded Ghostty instance passed to the constructor.
1631
+ */
1632
+ open(parent: HTMLElement): void;
1633
+ /**
1634
+ * Handle touch-based scrolling (mobile)
1635
+ * @param deltaPx Finger delta in pixels (positive = finger moved down)
1636
+ */
1637
+ private handleTouchScrollPixels;
1638
+ /**
1639
+ * Write data to terminal
1640
+ */
1641
+ write(data: string | Uint8Array, callback?: () => void): void;
1642
+ /**
1643
+ * Internal write implementation (extracted from write())
1644
+ */
1645
+ private writeInternal;
1646
+ /**
1647
+ * Write data with newline
1648
+ */
1649
+ writeln(data: string | Uint8Array, callback?: () => void): void;
1650
+ /**
1651
+ * Paste text into terminal (triggers bracketed paste if supported)
1652
+ */
1653
+ paste(data: string): void;
1654
+ /**
1655
+ * Input data into terminal (as if typed by user)
1656
+ *
1657
+ * @param data - Data to input
1658
+ * @param wasUserInput - If true, triggers onData event (default: false for compat with some apps)
1659
+ */
1660
+ input(data: string, wasUserInput?: boolean): void;
1661
+ /**
1662
+ * Resize terminal
1663
+ */
1664
+ resize(cols: number, rows: number): void;
1665
+ /**
1666
+ * Clear terminal screen
1667
+ */
1668
+ clear(): void;
1669
+ /**
1670
+ * Reset terminal state
1671
+ */
1672
+ reset(): void;
1673
+ /**
1674
+ * Focus terminal input
1675
+ */
1676
+ focus(): void;
1677
+ /**
1678
+ * Blur terminal (remove focus)
1679
+ */
1680
+ blur(): void;
1681
+ /**
1682
+ * Load an addon
1683
+ */
1684
+ loadAddon(addon: ITerminalAddon): void;
1685
+ /**
1686
+ * Get the selected text as a string
1687
+ */
1688
+ getSelection(): string;
1689
+ /**
1690
+ * Check if there's an active selection
1691
+ */
1692
+ hasSelection(): boolean;
1693
+ /**
1694
+ * Clear the current selection
1695
+ */
1696
+ clearSelection(): void;
1697
+ /**
1698
+ * Copy the current selection to clipboard
1699
+ * @returns true if there was text to copy, false otherwise
1700
+ */
1701
+ copySelection(): boolean;
1702
+ /**
1703
+ * Select all text in the terminal
1704
+ */
1705
+ selectAll(): void;
1706
+ /**
1707
+ * Select text at specific column and row with length
1708
+ */
1709
+ select(column: number, row: number, length: number): void;
1710
+ /**
1711
+ * Select entire lines from start to end
1712
+ */
1713
+ selectLines(start: number, end: number): void;
1714
+ /**
1715
+ * Get selection position as buffer range
1716
+ */
1717
+ /**
1718
+ * Get the current viewport Y position.
1719
+ *
1720
+ * This is the number of lines scrolled back from the bottom of the
1721
+ * scrollback buffer. It may be fractional during smooth scrolling.
1722
+ */
1723
+ getViewportY(): number;
1724
+ getSelectionPosition(): IBufferRange | undefined;
1725
+ /**
1726
+ * Attach a custom keyboard event handler
1727
+ * Returns true to prevent default handling
1728
+ */
1729
+ attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
1730
+ /**
1731
+ * Attach a custom wheel event handler (Phase 2)
1732
+ * Returns true to prevent default handling
1733
+ */
1734
+ attachCustomWheelEventHandler(customWheelEventHandler?: (event: WheelEvent) => boolean): void;
1735
+ /**
1736
+ * Register a custom link provider
1737
+ * Multiple providers can be registered to detect different types of links
1738
+ *
1739
+ * @example
1740
+ * ```typescript
1741
+ * term.registerLinkProvider({
1742
+ * provideLinks(y, callback) {
1743
+ * // Detect URLs, file paths, etc.
1744
+ * callback(detectedLinks);
1745
+ * }
1746
+ * });
1747
+ * ```
1748
+ */
1749
+ registerLinkProvider(provider: ILinkProvider): void;
1750
+ /**
1751
+ * Scroll viewport by a number of lines
1752
+ * @param amount Number of lines to scroll (positive = down, negative = up)
1753
+ */
1754
+ scrollLines(amount: number): void;
1755
+ /**
1756
+ * Scroll viewport by a number of pages
1757
+ * @param amount Number of pages to scroll (positive = down, negative = up)
1758
+ */
1759
+ scrollPages(amount: number): void;
1760
+ /**
1761
+ * Scroll viewport to the top of the scrollback buffer
1762
+ */
1763
+ scrollToTop(): void;
1764
+ /**
1765
+ * Scroll viewport to the bottom (current output)
1766
+ */
1767
+ scrollToBottom(): void;
1768
+ /**
1769
+ * Scroll viewport to a specific line in the buffer
1770
+ * @param line Line number (0 = top of scrollback, scrollbackLength = bottom)
1771
+ */
1772
+ scrollToLine(line: number): void;
1773
+ /**
1774
+ * Smoothly scroll to a target viewport position
1775
+ * @param targetY Target viewport Y position (in lines, can be fractional)
1776
+ */
1777
+ private smoothScrollTo;
1778
+ /**
1779
+ * Animation loop for smooth scrolling
1780
+ * Uses asymptotic approach - moves a fraction of remaining distance each frame
1781
+ */
1782
+ private animateScroll;
1783
+ /**
1784
+ * Dispose terminal and clean up resources
1785
+ */
1786
+ dispose(): void;
1787
+ /**
1788
+ * Start the render loop
1789
+ */
1790
+ private startRenderLoop;
1791
+ /**
1792
+ * Get a line from native WASM scrollback buffer
1793
+ * Implements IScrollbackProvider
1794
+ */
1795
+ getScrollbackLine(offset: number): GhosttyCell[] | null;
1796
+ /**
1797
+ * Get scrollback length from native WASM
1798
+ * Implements IScrollbackProvider
1799
+ */
1800
+ getScrollbackLength(): number;
1801
+ /**
1802
+ * Clean up components (called on dispose or error)
1803
+ */
1804
+ private cleanupComponents;
1805
+ /**
1806
+ * Assert terminal is open (throw if not)
1807
+ */
1808
+ private assertOpen;
1809
+ /**
1810
+ * Handle mouse move for link hover detection and scrollbar dragging
1811
+ * Throttled to avoid blocking scroll events (except when dragging scrollbar)
1812
+ */
1813
+ private handleMouseMove;
1814
+ /**
1815
+ * Process mouse move for link detection (internal, called by throttled handler)
1816
+ */
1817
+ private processMouseMove;
1818
+ /**
1819
+ * Handle mouse leave to clear link hover
1820
+ */
1821
+ private handleMouseLeave;
1822
+ /**
1823
+ * Handle mouse click for link activation
1824
+ */
1825
+ private handleClick;
1826
+ /**
1827
+ * Handle wheel events for scrolling (Phase 2)
1828
+ */
1829
+ private handleWheel;
1830
+ /**
1831
+ * Handle mouse down for scrollbar interaction
1832
+ */
1833
+ private handleMouseDown;
1834
+ /**
1835
+ * Handle mouse up for scrollbar drag
1836
+ */
1837
+ private handleMouseUp;
1838
+ /**
1839
+ * Process scrollbar drag movement
1840
+ */
1841
+ private processScrollbarDrag;
1842
+ /**
1843
+ * Show scrollbar with fade-in and schedule auto-hide
1844
+ */
1845
+ private showScrollbar;
1846
+ /**
1847
+ * Hide scrollbar with fade-out
1848
+ */
1849
+ private hideScrollbar;
1850
+ /**
1851
+ * Fade in scrollbar
1852
+ */
1853
+ private fadeInScrollbar;
1854
+ /**
1855
+ * Fade out scrollbar
1856
+ */
1857
+ private fadeOutScrollbar;
1858
+ /**
1859
+ * Process any pending terminal responses and emit them via onData.
1860
+ *
1861
+ * This handles escape sequences that require the terminal to send a response
1862
+ * back to the PTY, such as:
1863
+ * - DSR 6 (cursor position): Shell sends \x1b[6n, terminal responds with \x1b[row;colR
1864
+ * - DSR 5 (operating status): Shell sends \x1b[5n, terminal responds with \x1b[0n
1865
+ *
1866
+ * Without this, shells like nushell that rely on cursor position queries
1867
+ * will hang waiting for a response that never comes.
1868
+ *
1869
+ * Note: We loop to read all pending responses, not just one. This is important
1870
+ * when multiple queries are processed in a single write() call (e.g., when
1871
+ * buffered data is written all at once during terminal initialization).
1872
+ */
1873
+ private processTerminalResponses;
1874
+ /**
1875
+ * Check for title changes in written data (OSC sequences)
1876
+ * Simplified implementation - looks for OSC 0, 1, 2, 7
1877
+ */
1878
+ private checkForTitleChange;
1879
+ /**
1880
+ * Query terminal mode state
1881
+ *
1882
+ * @param mode Mode number (e.g., 2004 for bracketed paste)
1883
+ * @param isAnsi True for ANSI modes, false for DEC modes (default: false)
1884
+ * @returns true if mode is enabled
1885
+ */
1886
+ getMode(mode: number, isAnsi?: boolean): boolean;
1887
+ /**
1888
+ * Check if bracketed paste mode is enabled
1889
+ */
1890
+ hasBracketedPaste(): boolean;
1891
+ /**
1892
+ * Check if focus event reporting is enabled
1893
+ */
1894
+ hasFocusEvents(): boolean;
1895
+ /**
1896
+ * Check if mouse tracking is enabled
1897
+ */
1898
+ hasMouseTracking(): boolean;
1899
+ }
1900
+
1901
+ /**
1902
+ * Opaque terminal pointer (WASM memory address)
1903
+ */
1904
+ export declare type TerminalHandle = number;
1905
+
1906
+ /**
1907
+ * URL Regex Provider
1908
+ *
1909
+ * Detects plain text URLs on a single line using regex.
1910
+ * Does not support multi-line URLs or file paths.
1911
+ *
1912
+ * Supported protocols:
1913
+ * - https://, http://
1914
+ * - mailto:
1915
+ * - ftp://, ssh://, git://
1916
+ * - tel:, magnet:
1917
+ * - gemini://, gopher://, news:
1918
+ */
1919
+ export declare class UrlRegexProvider implements ILinkProvider {
1920
+ private terminal;
1921
+ /**
1922
+ * URL regex pattern
1923
+ * Matches common protocols followed by valid URL characters
1924
+ * Excludes file paths (no ./ or ../ or bare /)
1925
+ */
1926
+ private static readonly URL_REGEX;
1927
+ /**
1928
+ * Characters to strip from end of URLs
1929
+ * Common punctuation that's unlikely to be part of the URL
1930
+ */
1931
+ private static readonly TRAILING_PUNCTUATION;
1932
+ constructor(terminal: ITerminalForUrlProvider);
1933
+ /**
1934
+ * Provide all regex-detected URLs on the given row
1935
+ */
1936
+ provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void;
1937
+ /**
1938
+ * Convert a buffer line to plain text string
1939
+ */
1940
+ private lineToText;
1941
+ dispose(): void;
1942
+ }
1943
+
1944
+ export { }