import type { ClipboardPasteRequest, ClipboardPasteResult, ClipboardProtocolOptions, Disposable, KeyInput, PointerInput, TerminalBufferRange, TerminalBufferSnapshot, TerminalGeometry, TerminalTheme, ViewportSnapshot } from './core/types.js'; import { XTERM_COMPATIBILITY_BRIDGE, type XtermCompatibilityBridge } from './internal/xterm-compatibility.js'; import { type RendererInfo } from './renderers/hybrid.js'; import type { BrowserTerminal, BrowserTerminalEventMap, TerminalAddon, TerminalConnection, TerminalConnectionOptions, TerminalFontFace, TerminalFontOptions, TerminalOptions, TerminalTransport } from './types.js'; /** * Browser terminal combining Ghostty VT state, worker isolation, rendering, DOM input, and PTY * streams. * * @remarks * Create terminals through {@link createTerminal}. The terminal owns every resource activated * through it and releases those resources together through {@link GespenstTerminal.dispose}. * * @example Minimal browser terminal * ```ts * const terminal = await createTerminal({ container }); * terminal.write('\x1b[32mready\x1b[0m\r\n'); * terminal.focus(); * ``` */ export declare class GespenstTerminal implements BrowserTerminal { /** Root DOM element owned by the terminal. */ readonly element: HTMLElement; private readonly backend; private readonly dom; private readonly options; private font; private readonly events; private readonly resizeObserver; private layout; private geometryValue; private viewportState; private wheelRemainderRows; private disposed; private readonly cleanups; private readonly connections; private readonly addons; private readonly fontFaces; private themeValue; private clipboardToken; private clipboardActive; private readonly encoder; private readonly compatibilityInputListeners; /** @internal Runtime-only capability used by the version-matched xterm adapter. */ readonly [XTERM_COMPATIBILITY_BRIDGE]: XtermCompatibilityBridge; private constructor(); /** * Creates and asynchronously initializes a browser terminal. * * @remarks * The returned promise resolves after WASM, font readiness, execution context, and renderer * initialization. If initialization fails, any inserted terminal root is removed. */ static create(options: TerminalOptions): Promise; /** Current character-grid and backing-surface geometry. */ get geometry(): TerminalGeometry; /** Active renderer and shaping implementation. */ get renderer(): RendererInfo; /** Current authored theme. Missing values inherit from `DEFAULT_THEME`. */ get theme(): Readonly; /** Mounts a terminal created without a container and recalculates its layout. */ open(container: HTMLElement): Promise; /** Queues terminal output for VT parsing without waiting for the next rendered frame. */ write(data: string | Uint8Array): void; /** Parses and renders terminal output before resolving. */ writeAsync(data: string | Uint8Array): Promise; private writeAndRender; /** Encodes a physical keyboard input toward the PTY. */ sendKey(input: KeyInput): void; /** Encodes a pointer input or updates terminal selection. */ sendPointer(input: PointerInput): void; /** Sends composed text toward the PTY. */ sendText(data: string): void; /** Sends text through bracketed-paste handling when enabled. */ paste(data: string): void; /** * Enables the optional Kitty clipboard protocol bridge for one addon. * * @internal Addon authors should prefer `@gespenst/clipboard`. */ enableClipboard(options?: ClipboardProtocolOptions): Promise; /** Delivers a user-authorized browser clipboard snapshot to Ghostty. */ pasteClipboard(request: ClipboardPasteRequest): Promise; /** Focuses the hidden terminal input. */ focus(): void; /** Removes focus from the hidden terminal input. */ blur(): void; /** * Fits to the container or applies an explicit character-grid size. * * @remarks Calling without both dimensions respects fixed `cols` and `rows` creation options. * Use {@link GespenstTerminal.fit} to force container measurement. */ resize(cols?: number, rows?: number): void; /** Recalculates terminal geometry from its current container, ignoring fixed initial grid values. */ fit(): void; private applyLayout; /** Scrolls the viewport by a signed row count. */ scrollLines(delta: number): void; /** Scrolls to the beginning of the buffer. */ scrollToTop(): void; /** Scrolls to the end of the buffer. */ scrollToBottom(): void; /** Selects all terminal buffer content. */ selectAll(): void; /** Clears the active text selection. */ clearSelection(): void; /** Reads selected text. */ getSelection(): Promise; /** Serializes terminal state into Ghostty snapshot bytes. */ snapshot(): Promise; /** Restores terminal state from compatible snapshot bytes. */ restore(snapshot: Uint8Array): Promise; /** Resets terminal state to initial values. */ reset(): void; /** Reads a complete visible viewport snapshot. */ readViewport(): Promise; /** Reads retained active-buffer rows without reparsing terminal output. */ readBuffer(range?: TerminalBufferRange): Promise; /** * Loads a font face in the document and active rendering backend. * * @remarks Loading a face does not select it. Follow with {@link GespenstTerminal.setFont} when the * terminal should use the new family. */ loadFont(face: TerminalFontFace): Promise; /** Applies font values and returns recalculated terminal geometry. */ setFont(options: Partial): Promise; /** Changes the maximum retained scrollback lines. */ setScrollbackLines(lines: number): void; /** Changes Ghostty's default cursor shape and blink behavior. */ setDefaultCursor(style: import('./core/types.js').CursorStyle, blink: boolean): void; /** Changes the browser accessibility mirror level. */ setAccessibility(level: 'off' | 'basic' | 'full'): void; /** Changes the renderer's minimum contrast ratio. */ setMinimumContrastRatio(ratio: number): void; /** Replaces the terminal color theme. */ setTheme(theme: TerminalTheme): Promise; /** Patches the current terminal color theme. */ updateTheme(theme: TerminalTheme): Promise; /** Activates an addon and owns it until terminal disposal. */ loadAddon(addon: TerminalAddon): void; /** Subscribes to a typed browser terminal event. */ on(type: Key, listener: (value: BrowserTerminalEventMap[Key]) => void): Disposable; /** * Connects terminal output and input to bidirectional PTY byte streams. * * @remarks * Incoming chunks are awaited through {@link GespenstTerminal.writeAsync}. Outgoing input is * copied into a bounded queue whose default limit is 1 MiB. Geometry is intentionally separate; * subscribe to `resize` and forward columns and rows through the backend's control protocol. */ connect(transport: TerminalTransport, options?: TerminalConnectionOptions): TerminalConnection; /** Releases transports, addons, fonts, workers, renderers, events, and DOM resources. */ dispose(): void; private bindDom; private handleRendered; private handleInput; private positionInputAtCursor; private applyInputFont; private handleKeyDown; private updateAccessibility; private applyThemeToDom; private ensureActive; private currentOptions; } /** * Creates and asynchronously initializes a browser terminal. * * @param options - Host, execution, renderer, layout, font, accessibility, and WASM options. * @returns A ready terminal whose initial geometry and renderer can be inspected immediately. * * @example * ```ts * const terminal = await createTerminal({ * container: document.querySelector('#terminal')!, * }); * ``` */ export declare function createTerminal(options: TerminalOptions): Promise; //# sourceMappingURL=terminal.d.ts.map