ghostty-web 0.1.0

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,953 @@
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 selectionManager?;
16
+ constructor(canvas: HTMLCanvasElement, options?: RendererOptions);
17
+ private measureFont;
18
+ /**
19
+ * Remeasure font metrics (call after font loads or changes)
20
+ */
21
+ remeasureFont(): void;
22
+ private rgbToCSS;
23
+ /**
24
+ * Resize canvas to fit terminal dimensions
25
+ */
26
+ resize(cols: number, rows: number): void;
27
+ /**
28
+ * Render the terminal buffer to canvas
29
+ */
30
+ render(buffer: IRenderable, forceAll?: boolean): void;
31
+ /**
32
+ * Render a single line
33
+ */
34
+ private renderLine;
35
+ /**
36
+ * Render a single cell
37
+ */
38
+ private renderCell;
39
+ /**
40
+ * Render cursor
41
+ */
42
+ private renderCursor;
43
+ private startCursorBlink;
44
+ private stopCursorBlink;
45
+ /**
46
+ * Update theme colors
47
+ */
48
+ setTheme(theme: ITheme): void;
49
+ /**
50
+ * Update font size
51
+ */
52
+ setFontSize(size: number): void;
53
+ /**
54
+ * Update font family
55
+ */
56
+ setFontFamily(family: string): void;
57
+ /**
58
+ * Update cursor style
59
+ */
60
+ setCursorStyle(style: 'block' | 'underline' | 'bar'): void;
61
+ /**
62
+ * Enable/disable cursor blinking
63
+ */
64
+ setCursorBlink(enabled: boolean): void;
65
+ /**
66
+ * Get current font metrics
67
+ */
68
+ getMetrics(): FontMetrics;
69
+ /**
70
+ * Get canvas element (needed by SelectionManager)
71
+ */
72
+ getCanvas(): HTMLCanvasElement;
73
+ /**
74
+ * Set selection manager (for rendering selection overlay)
75
+ */
76
+ setSelectionManager(manager: SelectionManager): void;
77
+ /**
78
+ * Clear entire canvas
79
+ */
80
+ clear(): void;
81
+ /**
82
+ * Render selection overlay
83
+ */
84
+ private renderSelection;
85
+ /**
86
+ * Cleanup resources
87
+ */
88
+ dispose(): void;
89
+ }
90
+
91
+ /**
92
+ * Cell style flags (bitfield)
93
+ */
94
+ export declare enum CellFlags {
95
+ BOLD = 1,
96
+ ITALIC = 2,
97
+ UNDERLINE = 4,
98
+ STRIKETHROUGH = 8,
99
+ INVERSE = 16,
100
+ INVISIBLE = 32,
101
+ BLINK = 64,
102
+ FAINT = 128
103
+ }
104
+
105
+ /**
106
+ * Cursor position and visibility
107
+ */
108
+ export declare interface Cursor {
109
+ x: number;
110
+ y: number;
111
+ visible: boolean;
112
+ }
113
+
114
+ export declare class EventEmitter<T> {
115
+ private listeners;
116
+ fire(arg: T): void;
117
+ event: IEvent<T>;
118
+ dispose(): void;
119
+ }
120
+
121
+ export declare class FitAddon implements ITerminalAddon {
122
+ private _terminal?;
123
+ private _resizeObserver?;
124
+ private _resizeDebounceTimer?;
125
+ private _lastCols?;
126
+ private _lastRows?;
127
+ private _isResizing;
128
+ /**
129
+ * Activate the addon (called by Terminal.loadAddon)
130
+ */
131
+ activate(terminal: ITerminalCore): void;
132
+ /**
133
+ * Dispose the addon and clean up resources
134
+ */
135
+ dispose(): void;
136
+ /**
137
+ * Fit the terminal to its container
138
+ *
139
+ * Calculates optimal dimensions and resizes the terminal.
140
+ * Does nothing if dimensions cannot be calculated or haven't changed.
141
+ */
142
+ fit(): void;
143
+ /**
144
+ * Propose dimensions to fit the terminal to its container
145
+ *
146
+ * Calculates cols and rows based on:
147
+ * - Terminal container element dimensions (clientWidth/Height)
148
+ * - Terminal element padding
149
+ * - Font metrics (character cell size)
150
+ * - Scrollbar width reservation
151
+ *
152
+ * @returns Proposed dimensions or undefined if cannot calculate
153
+ */
154
+ proposeDimensions(): ITerminalDimensions | undefined;
155
+ /**
156
+ * Observe the terminal's container for resize events
157
+ *
158
+ * Sets up a ResizeObserver to automatically call fit() when the
159
+ * container size changes. Resize events are debounced to avoid
160
+ * excessive calls during window drag operations.
161
+ *
162
+ * Call dispose() to stop observing.
163
+ */
164
+ observeResize(): void;
165
+ }
166
+
167
+ export declare interface FontMetrics {
168
+ width: number;
169
+ height: number;
170
+ baseline: number;
171
+ }
172
+
173
+ /**
174
+ * Main Ghostty WASM wrapper class
175
+ */
176
+ export declare class Ghostty {
177
+ private exports;
178
+ private memory;
179
+ constructor(wasmInstance: WebAssembly.Instance);
180
+ /**
181
+ * Get current memory buffer (may change when memory grows)
182
+ */
183
+ private getBuffer;
184
+ /**
185
+ * Create a key encoder instance
186
+ */
187
+ createKeyEncoder(): KeyEncoder;
188
+ /**
189
+ * Create a terminal emulator instance
190
+ */
191
+ createTerminal(cols?: number, rows?: number): GhosttyTerminal;
192
+ /**
193
+ * Load Ghostty WASM from URL or file path
194
+ * If no path is provided, attempts to load from common default locations
195
+ */
196
+ static load(wasmPath?: string): Promise<Ghostty>;
197
+ }
198
+
199
+ /**
200
+ * Cell structure matching ghostty_cell_t in C (12 bytes)
201
+ */
202
+ export declare interface GhosttyCell {
203
+ codepoint: number;
204
+ fg_r: number;
205
+ fg_g: number;
206
+ fg_b: number;
207
+ bg_r: number;
208
+ bg_g: number;
209
+ bg_b: number;
210
+ flags: number;
211
+ width: number;
212
+ }
213
+
214
+ /**
215
+ * GhosttyTerminal - Wraps the WASM terminal emulator
216
+ *
217
+ * Provides a TypeScript-friendly interface to Ghostty's complete
218
+ * terminal implementation via WASM.
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const ghostty = await Ghostty.load('./ghostty-vt.wasm');
223
+ * const term = ghostty.createTerminal(80, 24);
224
+ *
225
+ * term.write('Hello\x1b[31m Red\x1b[0m\n');
226
+ * const cursor = term.getCursor();
227
+ * const cells = term.getLine(0);
228
+ *
229
+ * term.free();
230
+ * ```
231
+ */
232
+ export declare class GhosttyTerminal {
233
+ private exports;
234
+ private memory;
235
+ private handle;
236
+ private _cols;
237
+ private _rows;
238
+ /**
239
+ * Size of ghostty_cell_t in bytes (12 bytes in WASM)
240
+ * Structure: codepoint(u32) + fg_rgb(3xu8) + bg_rgb(3xu8) + flags(u8) + width(u8)
241
+ */
242
+ private static readonly CELL_SIZE;
243
+ /**
244
+ * Create a new terminal.
245
+ *
246
+ * @param exports WASM exports
247
+ * @param memory WASM memory
248
+ * @param cols Number of columns (default: 80)
249
+ * @param rows Number of rows (default: 24)
250
+ * @throws Error if allocation fails
251
+ */
252
+ constructor(exports: GhosttyWasmExports, memory: WebAssembly.Memory, cols?: number, rows?: number);
253
+ /**
254
+ * Free the terminal. Must be called to prevent memory leaks.
255
+ */
256
+ free(): void;
257
+ /**
258
+ * Write data to terminal (parses VT sequences and updates screen).
259
+ *
260
+ * @param data UTF-8 string or Uint8Array
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * term.write('Hello, World!\n');
265
+ * term.write('\x1b[1;31mBold Red\x1b[0m\n');
266
+ * term.write(new Uint8Array([0x1b, 0x5b, 0x41])); // Up arrow
267
+ * ```
268
+ */
269
+ write(data: string | Uint8Array): void;
270
+ /**
271
+ * Resize the terminal.
272
+ *
273
+ * @param cols New column count
274
+ * @param rows New row count
275
+ */
276
+ resize(cols: number, rows: number): void;
277
+ /**
278
+ * Get terminal dimensions.
279
+ */
280
+ get cols(): number;
281
+ get rows(): number;
282
+ /**
283
+ * Get terminal dimensions (for IRenderable compatibility)
284
+ */
285
+ getDimensions(): {
286
+ cols: number;
287
+ rows: number;
288
+ };
289
+ /**
290
+ * Get cursor position and visibility.
291
+ */
292
+ getCursor(): Cursor;
293
+ /**
294
+ * Get scrollback length (number of lines in history).
295
+ */
296
+ getScrollbackLength(): number;
297
+ /**
298
+ * Get a line of cells from the visible screen.
299
+ *
300
+ * @param y Line number (0 = top visible line)
301
+ * @returns Array of cells, or null if y is out of bounds
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const cells = term.getLine(0);
306
+ * if (cells) {
307
+ * for (const cell of cells) {
308
+ * const char = String.fromCodePoint(cell.codepoint);
309
+ * const isBold = (cell.flags & CellFlags.BOLD) !== 0;
310
+ * console.log(`"${char}" ${isBold ? 'bold' : 'normal'}`);
311
+ * }
312
+ * }
313
+ * ```
314
+ */
315
+ getLine(y: number): GhosttyCell[] | null;
316
+ /**
317
+ * Get a line from scrollback history.
318
+ *
319
+ * @param offset Line offset from top of scrollback (0 = oldest line)
320
+ * @returns Array of cells, or null if not available
321
+ */
322
+ getScrollbackLine(offset: number): GhosttyCell[] | null;
323
+ /**
324
+ * Check if any part of the screen is dirty.
325
+ */
326
+ isDirty(): boolean;
327
+ /**
328
+ * Check if a specific row is dirty.
329
+ */
330
+ isRowDirty(y: number): boolean;
331
+ /**
332
+ * Clear all dirty flags (call after rendering).
333
+ */
334
+ clearDirty(): void;
335
+ /**
336
+ * Get all visible lines at once (convenience method).
337
+ *
338
+ * @returns Array of line arrays, or empty array on error
339
+ */
340
+ getAllLines(): GhosttyCell[][];
341
+ /**
342
+ * Get only the dirty lines (for optimized rendering).
343
+ *
344
+ * @returns Map of row number to cell array
345
+ */
346
+ getDirtyLines(): Map<number, GhosttyCell[]>;
347
+ }
348
+
349
+ /**
350
+ * Interface for libghostty-vt WASM exports
351
+ */
352
+ declare interface GhosttyWasmExports extends WebAssembly.Exports {
353
+ memory: WebAssembly.Memory;
354
+ ghostty_wasm_alloc_opaque(): number;
355
+ ghostty_wasm_free_opaque(ptr: number): void;
356
+ ghostty_wasm_alloc_u8_array(len: number): number;
357
+ ghostty_wasm_free_u8_array(ptr: number, len: number): void;
358
+ ghostty_wasm_alloc_u16_array(len: number): number;
359
+ ghostty_wasm_free_u16_array(ptr: number, len: number): void;
360
+ ghostty_wasm_alloc_u8(): number;
361
+ ghostty_wasm_free_u8(ptr: number): void;
362
+ ghostty_wasm_alloc_usize(): number;
363
+ ghostty_wasm_free_usize(ptr: number): void;
364
+ ghostty_sgr_new(allocator: number, parserPtrPtr: number): number;
365
+ ghostty_sgr_free(parser: number): void;
366
+ ghostty_sgr_reset(parser: number): void;
367
+ ghostty_sgr_set_params(parser: number, paramsPtr: number, subsPtr: number, paramsLen: number): number;
368
+ ghostty_sgr_next(parser: number, attrPtr: number): boolean;
369
+ ghostty_sgr_attribute_tag(attrPtr: number): number;
370
+ ghostty_sgr_attribute_value(attrPtr: number, tagPtr: number): number;
371
+ ghostty_wasm_alloc_sgr_attribute(): number;
372
+ ghostty_wasm_free_sgr_attribute(ptr: number): void;
373
+ ghostty_key_encoder_new(allocator: number, encoderPtrPtr: number): number;
374
+ ghostty_key_encoder_free(encoder: number): void;
375
+ ghostty_key_encoder_setopt(encoder: number, option: number, valuePtr: number): number;
376
+ ghostty_key_encoder_encode(encoder: number, eventPtr: number, bufPtr: number, bufLen: number, writtenPtr: number): number;
377
+ ghostty_key_event_new(allocator: number, eventPtrPtr: number): number;
378
+ ghostty_key_event_free(event: number): void;
379
+ ghostty_key_event_set_action(event: number, action: number): void;
380
+ ghostty_key_event_set_key(event: number, key: number): void;
381
+ ghostty_key_event_set_mods(event: number, mods: number): void;
382
+ ghostty_key_event_set_utf8(event: number, ptr: number, len: number): void;
383
+ ghostty_terminal_new(cols: number, rows: number): TerminalHandle;
384
+ ghostty_terminal_new_with_config(cols: number, rows: number, configPtr: number): TerminalHandle;
385
+ ghostty_terminal_free(terminal: TerminalHandle): void;
386
+ ghostty_terminal_write(terminal: TerminalHandle, dataPtr: number, dataLen: number): void;
387
+ ghostty_terminal_resize(terminal: TerminalHandle, cols: number, rows: number): void;
388
+ ghostty_terminal_get_cols(terminal: TerminalHandle): number;
389
+ ghostty_terminal_get_rows(terminal: TerminalHandle): number;
390
+ ghostty_terminal_get_cursor_x(terminal: TerminalHandle): number;
391
+ ghostty_terminal_get_cursor_y(terminal: TerminalHandle): number;
392
+ ghostty_terminal_get_cursor_visible(terminal: TerminalHandle): boolean;
393
+ ghostty_terminal_is_dirty(terminal: TerminalHandle): boolean;
394
+ ghostty_terminal_is_row_dirty(terminal: TerminalHandle, row: number): boolean;
395
+ ghostty_terminal_clear_dirty(terminal: TerminalHandle): void;
396
+ ghostty_terminal_get_line(terminal: TerminalHandle, row: number, bufPtr: number, bufLen: number): number;
397
+ ghostty_terminal_get_scrollback_line(terminal: TerminalHandle, offset: number, bufPtr: number, bufLen: number): number;
398
+ ghostty_terminal_get_scrollback_length(terminal: TerminalHandle): number;
399
+ }
400
+
401
+ export declare interface IDisposable {
402
+ dispose(): void;
403
+ }
404
+
405
+ export declare type IEvent<T> = (listener: (arg: T) => void) => IDisposable;
406
+
407
+ /**
408
+ * InputHandler class
409
+ * Attaches keyboard event listeners to a container and converts
410
+ * keyboard events to terminal input data
411
+ */
412
+ export declare class InputHandler {
413
+ private encoder;
414
+ private container;
415
+ private onDataCallback;
416
+ private onBellCallback;
417
+ private keydownListener;
418
+ private keypressListener;
419
+ private pasteListener;
420
+ private isDisposed;
421
+ /**
422
+ * Create a new InputHandler
423
+ * @param ghostty - Ghostty instance (for creating KeyEncoder)
424
+ * @param container - DOM element to attach listeners to
425
+ * @param onData - Callback for terminal data (escape sequences to send to PTY)
426
+ * @param onBell - Callback for bell/beep event
427
+ */
428
+ constructor(ghostty: Ghostty, container: HTMLElement, onData: (data: string) => void, onBell: () => void);
429
+ /**
430
+ * Attach keyboard event listeners to container
431
+ */
432
+ private attach;
433
+ /**
434
+ * Map KeyboardEvent.code to USB HID Key enum value
435
+ * @param code - KeyboardEvent.code value
436
+ * @returns Key enum value or null if unmapped
437
+ */
438
+ private mapKeyCode;
439
+ /**
440
+ * Extract modifier flags from KeyboardEvent
441
+ * @param event - KeyboardEvent
442
+ * @returns Mods flags
443
+ */
444
+ private extractModifiers;
445
+ /**
446
+ * Check if this is a printable character with no special modifiers
447
+ * @param event - KeyboardEvent
448
+ * @returns true if printable character
449
+ */
450
+ private isPrintableCharacter;
451
+ /**
452
+ * Handle keydown event
453
+ * @param event - KeyboardEvent
454
+ */
455
+ private handleKeyDown;
456
+ /**
457
+ * Handle paste event from clipboard
458
+ * @param event - ClipboardEvent
459
+ */
460
+ private handlePaste;
461
+ /**
462
+ * Dispose the InputHandler and remove event listeners
463
+ */
464
+ dispose(): void;
465
+ /**
466
+ * Check if handler is disposed
467
+ */
468
+ isActive(): boolean;
469
+ }
470
+
471
+ export declare interface IRenderable {
472
+ getLine(y: number): GhosttyCell[] | null;
473
+ getCursor(): {
474
+ x: number;
475
+ y: number;
476
+ visible: boolean;
477
+ };
478
+ getDimensions(): {
479
+ cols: number;
480
+ rows: number;
481
+ };
482
+ isRowDirty(y: number): boolean;
483
+ clearDirty(): void;
484
+ }
485
+
486
+ export declare interface ITerminalAddon {
487
+ activate(terminal: ITerminalCore): void;
488
+ dispose(): void;
489
+ }
490
+
491
+ export declare interface ITerminalCore {
492
+ cols: number;
493
+ rows: number;
494
+ element?: HTMLElement;
495
+ textarea?: HTMLTextAreaElement;
496
+ }
497
+
498
+ export declare interface ITerminalDimensions {
499
+ cols: number;
500
+ rows: number;
501
+ }
502
+
503
+ /**
504
+ * xterm.js-compatible interfaces
505
+ */
506
+ export declare interface ITerminalOptions {
507
+ cols?: number;
508
+ rows?: number;
509
+ cursorBlink?: boolean;
510
+ cursorStyle?: 'block' | 'underline' | 'bar';
511
+ theme?: ITheme;
512
+ scrollback?: number;
513
+ fontSize?: number;
514
+ fontFamily?: string;
515
+ allowTransparency?: boolean;
516
+ wasmPath?: string;
517
+ }
518
+
519
+ export declare interface ITheme {
520
+ foreground?: string;
521
+ background?: string;
522
+ cursor?: string;
523
+ cursorAccent?: string;
524
+ selectionBackground?: string;
525
+ selectionForeground?: string;
526
+ black?: string;
527
+ red?: string;
528
+ green?: string;
529
+ yellow?: string;
530
+ blue?: string;
531
+ magenta?: string;
532
+ cyan?: string;
533
+ white?: string;
534
+ brightBlack?: string;
535
+ brightRed?: string;
536
+ brightGreen?: string;
537
+ brightYellow?: string;
538
+ brightBlue?: string;
539
+ brightMagenta?: string;
540
+ brightCyan?: string;
541
+ brightWhite?: string;
542
+ }
543
+
544
+ /**
545
+ * Physical key codes (based on USB HID Usage Tables - Keyboard/Keypad Page 0x07)
546
+ * Reference: https://www.usb.org/sites/default/files/hut1_21.pdf
547
+ */
548
+ export declare enum Key {
549
+ A = 4,
550
+ B = 5,
551
+ C = 6,
552
+ D = 7,
553
+ E = 8,
554
+ F = 9,
555
+ G = 10,
556
+ H = 11,
557
+ I = 12,
558
+ J = 13,
559
+ K = 14,
560
+ L = 15,
561
+ M = 16,
562
+ N = 17,
563
+ O = 18,
564
+ P = 19,
565
+ Q = 20,
566
+ R = 21,
567
+ S = 22,
568
+ T = 23,
569
+ U = 24,
570
+ V = 25,
571
+ W = 26,
572
+ X = 27,
573
+ Y = 28,
574
+ Z = 29,
575
+ ONE = 30,
576
+ TWO = 31,
577
+ THREE = 32,
578
+ FOUR = 33,
579
+ FIVE = 34,
580
+ SIX = 35,
581
+ SEVEN = 36,
582
+ EIGHT = 37,
583
+ NINE = 38,
584
+ ZERO = 39,
585
+ ENTER = 40,
586
+ ESCAPE = 41,
587
+ BACKSPACE = 42,
588
+ TAB = 43,
589
+ SPACE = 44,
590
+ MINUS = 45,// - and _
591
+ EQUAL = 46,// = and +
592
+ BRACKET_LEFT = 47,// [ and {
593
+ BRACKET_RIGHT = 48,// ] and }
594
+ BACKSLASH = 49,// \ and |
595
+ SEMICOLON = 51,// ; and :
596
+ QUOTE = 52,// ' and "
597
+ GRAVE = 53,// ` and ~
598
+ COMMA = 54,// , and <
599
+ PERIOD = 55,// . and >
600
+ SLASH = 56,// / and ?
601
+ CAPS_LOCK = 57,
602
+ F1 = 58,
603
+ F2 = 59,
604
+ F3 = 60,
605
+ F4 = 61,
606
+ F5 = 62,
607
+ F6 = 63,
608
+ F7 = 64,
609
+ F8 = 65,
610
+ F9 = 66,
611
+ F10 = 67,
612
+ F11 = 68,
613
+ F12 = 69,
614
+ PRINT_SCREEN = 70,
615
+ SCROLL_LOCK = 71,
616
+ PAUSE = 72,
617
+ INSERT = 73,
618
+ HOME = 74,
619
+ PAGE_UP = 75,
620
+ DELETE = 76,
621
+ END = 77,
622
+ PAGE_DOWN = 78,
623
+ RIGHT = 79,
624
+ LEFT = 80,
625
+ DOWN = 81,
626
+ UP = 82,
627
+ NUM_LOCK = 83,
628
+ KP_DIVIDE = 84,// Keypad /
629
+ KP_MULTIPLY = 85,// Keypad *
630
+ KP_MINUS = 86,// Keypad -
631
+ KP_PLUS = 87,// Keypad +
632
+ KP_ENTER = 88,// Keypad Enter
633
+ KP_1 = 89,
634
+ KP_2 = 90,
635
+ KP_3 = 91,
636
+ KP_4 = 92,
637
+ KP_5 = 93,
638
+ KP_6 = 94,
639
+ KP_7 = 95,
640
+ KP_8 = 96,
641
+ KP_9 = 97,
642
+ KP_0 = 98,
643
+ KP_PERIOD = 99,// Keypad .
644
+ NON_US_BACKSLASH = 100,// \ and | on non-US keyboards
645
+ APPLICATION = 101,// Context menu key
646
+ F13 = 104,
647
+ F14 = 105,
648
+ F15 = 106,
649
+ F16 = 107,
650
+ F17 = 108,
651
+ F18 = 109,
652
+ F19 = 110,
653
+ F20 = 111,
654
+ F21 = 112,
655
+ F22 = 113,
656
+ F23 = 114,
657
+ F24 = 115
658
+ }
659
+
660
+ /**
661
+ * Key action
662
+ */
663
+ export declare enum KeyAction {
664
+ RELEASE = 0,
665
+ PRESS = 1,
666
+ REPEAT = 2
667
+ }
668
+
669
+ /**
670
+ * Key Encoder
671
+ * Converts keyboard events into terminal escape sequences
672
+ */
673
+ export declare class KeyEncoder {
674
+ private exports;
675
+ private encoder;
676
+ constructor(exports: GhosttyWasmExports);
677
+ /**
678
+ * Set an encoder option
679
+ */
680
+ setOption(option: KeyEncoderOption, value: boolean | number): void;
681
+ /**
682
+ * Enable Kitty keyboard protocol with specified flags
683
+ */
684
+ setKittyFlags(flags: KittyKeyFlags): void;
685
+ /**
686
+ * Encode a key event to escape sequence
687
+ */
688
+ encode(event: KeyEvent): Uint8Array;
689
+ /**
690
+ * Free encoder resources
691
+ */
692
+ dispose(): void;
693
+ }
694
+
695
+ /**
696
+ * Key encoder options
697
+ */
698
+ export declare enum KeyEncoderOption {
699
+ CURSOR_KEY_APPLICATION = 0,// DEC mode 1
700
+ KEYPAD_KEY_APPLICATION = 1,// DEC mode 66
701
+ IGNORE_KEYPAD_WITH_NUMLOCK = 2,// DEC mode 1035
702
+ ALT_ESC_PREFIX = 3,// DEC mode 1036
703
+ MODIFY_OTHER_KEYS_STATE_2 = 4,// xterm modifyOtherKeys
704
+ KITTY_KEYBOARD_FLAGS = 5
705
+ }
706
+
707
+ /**
708
+ * Key event structure
709
+ */
710
+ export declare interface KeyEvent {
711
+ action: KeyAction;
712
+ key: Key;
713
+ mods: Mods;
714
+ consumedMods?: Mods;
715
+ composing?: boolean;
716
+ utf8?: string;
717
+ unshiftedCodepoint?: number;
718
+ }
719
+
720
+ /**
721
+ * Kitty keyboard protocol flags
722
+ * From include/ghostty/vt/key/encoder.h
723
+ */
724
+ declare enum KittyKeyFlags {
725
+ DISABLED = 0,
726
+ DISAMBIGUATE = 1,// Disambiguate escape codes
727
+ REPORT_EVENTS = 2,// Report press and release
728
+ REPORT_ALTERNATES = 4,// Report alternate key codes
729
+ REPORT_ALL = 8,// Report all events
730
+ REPORT_ASSOCIATED = 16,// Report associated text
731
+ ALL = 31
732
+ }
733
+
734
+ /**
735
+ * Modifier keys
736
+ */
737
+ export declare enum Mods {
738
+ NONE = 0,
739
+ SHIFT = 1,
740
+ CTRL = 2,
741
+ ALT = 4,
742
+ SUPER = 8,// Windows/Command key
743
+ CAPSLOCK = 16,
744
+ NUMLOCK = 32
745
+ }
746
+
747
+ export declare interface RendererOptions {
748
+ fontSize?: number;
749
+ fontFamily?: string;
750
+ cursorStyle?: 'block' | 'underline' | 'bar';
751
+ cursorBlink?: boolean;
752
+ theme?: ITheme;
753
+ devicePixelRatio?: number;
754
+ }
755
+
756
+ /**
757
+ * RGB color
758
+ */
759
+ export declare interface RGB {
760
+ r: number;
761
+ g: number;
762
+ b: number;
763
+ }
764
+
765
+ export declare interface SelectionCoordinates {
766
+ startCol: number;
767
+ startRow: number;
768
+ endCol: number;
769
+ endRow: number;
770
+ }
771
+
772
+ export declare class SelectionManager {
773
+ private terminal;
774
+ private renderer;
775
+ private wasmTerm;
776
+ private selectionStart;
777
+ private selectionEnd;
778
+ private isSelecting;
779
+ private previousSelection;
780
+ private selectionChangedEmitter;
781
+ private boundMouseUpHandler;
782
+ constructor(terminal: Terminal, renderer: CanvasRenderer, wasmTerm: GhosttyTerminal);
783
+ /**
784
+ * Get the selected text as a string
785
+ */
786
+ getSelection(): string;
787
+ /**
788
+ * Check if there's an active selection
789
+ */
790
+ hasSelection(): boolean;
791
+ /**
792
+ * Check if currently in the process of selecting (mouse is down)
793
+ */
794
+ isActivelySelecting(): boolean;
795
+ /**
796
+ * Clear the selection
797
+ */
798
+ clearSelection(): void;
799
+ /**
800
+ * Select all text in the terminal
801
+ */
802
+ selectAll(): void;
803
+ /**
804
+ * Get normalized selection coordinates (for rendering)
805
+ */
806
+ getSelectionCoords(): SelectionCoordinates | null;
807
+ /**
808
+ * Get previous selection coordinates (for clearing old highlight)
809
+ */
810
+ getPreviousSelectionCoords(): SelectionCoordinates | null;
811
+ /**
812
+ * Clear the previous selection tracking (after redraw)
813
+ */
814
+ clearPreviousSelection(): void;
815
+ /**
816
+ * Get selection change event accessor
817
+ */
818
+ get onSelectionChange(): IEvent<void>;
819
+ /**
820
+ * Cleanup resources
821
+ */
822
+ dispose(): void;
823
+ /**
824
+ * Attach mouse event listeners to canvas
825
+ */
826
+ private attachEventListeners;
827
+ /**
828
+ * Convert pixel coordinates to terminal cell coordinates
829
+ */
830
+ private pixelToCell;
831
+ /**
832
+ * Normalize selection coordinates (handle backward selection)
833
+ */
834
+ private normalizeSelection;
835
+ /**
836
+ * Get word boundaries at a cell position
837
+ */
838
+ private getWordAtCell;
839
+ /**
840
+ * Copy text to clipboard
841
+ */
842
+ private copyToClipboard;
843
+ /**
844
+ * Fallback clipboard copy using execCommand (works in more contexts)
845
+ */
846
+ private copyToClipboardFallback;
847
+ /**
848
+ * Request a render update (triggers selection overlay redraw)
849
+ */
850
+ private requestRender;
851
+ }
852
+
853
+ export declare class Terminal implements ITerminalCore {
854
+ cols: number;
855
+ rows: number;
856
+ element?: HTMLElement;
857
+ textarea?: HTMLTextAreaElement;
858
+ private options;
859
+ private ghostty?;
860
+ private wasmTerm?;
861
+ private renderer?;
862
+ private inputHandler?;
863
+ private selectionManager?;
864
+ private canvas?;
865
+ private dataEmitter;
866
+ private resizeEmitter;
867
+ private bellEmitter;
868
+ private selectionChangeEmitter;
869
+ readonly onData: IEvent<string>;
870
+ readonly onResize: IEvent<{
871
+ cols: number;
872
+ rows: number;
873
+ }>;
874
+ readonly onBell: IEvent<void>;
875
+ readonly onSelectionChange: IEvent<void>;
876
+ private isOpen;
877
+ private isDisposed;
878
+ private animationFrameId?;
879
+ private addons;
880
+ constructor(options?: ITerminalOptions);
881
+ /**
882
+ * Open terminal in a parent element
883
+ * This initializes all components and starts rendering
884
+ */
885
+ open(parent: HTMLElement): Promise<void>;
886
+ /**
887
+ * Write data to terminal
888
+ */
889
+ write(data: string | Uint8Array): void;
890
+ /**
891
+ * Write data with newline
892
+ */
893
+ writeln(data: string): void;
894
+ /**
895
+ * Resize terminal
896
+ */
897
+ resize(cols: number, rows: number): void;
898
+ /**
899
+ * Clear terminal screen
900
+ */
901
+ clear(): void;
902
+ /**
903
+ * Reset terminal state
904
+ */
905
+ reset(): void;
906
+ /**
907
+ * Focus terminal input
908
+ */
909
+ focus(): void;
910
+ /**
911
+ * Load an addon
912
+ */
913
+ loadAddon(addon: ITerminalAddon): void;
914
+ /**
915
+ * Get the selected text as a string
916
+ */
917
+ getSelection(): string;
918
+ /**
919
+ * Check if there's an active selection
920
+ */
921
+ hasSelection(): boolean;
922
+ /**
923
+ * Clear the current selection
924
+ */
925
+ clearSelection(): void;
926
+ /**
927
+ * Select all text in the terminal
928
+ */
929
+ selectAll(): void;
930
+ /**
931
+ * Dispose terminal and clean up resources
932
+ */
933
+ dispose(): void;
934
+ /**
935
+ * Start the render loop
936
+ */
937
+ private startRenderLoop;
938
+ /**
939
+ * Clean up components (called on dispose or error)
940
+ */
941
+ private cleanupComponents;
942
+ /**
943
+ * Assert terminal is open (throw if not)
944
+ */
945
+ private assertOpen;
946
+ }
947
+
948
+ /**
949
+ * Opaque terminal pointer (WASM memory address)
950
+ */
951
+ export declare type TerminalHandle = number;
952
+
953
+ export { }