import type { ClipboardPasteRequest, ClipboardPasteResult, ClipboardProtocolOptions, CoreTerminalOptions, Disposable, KeyInput, PointerInput, TerminalBufferRange, TerminalBufferSnapshot, TerminalEventMap, TerminalGeometry, TerminalTheme, TerminalViewportChangeEvent, ViewportSnapshot, WasmSource } from './core/types.js'; import type { RendererInfo, RendererPreference } from './renderers/hybrid.js'; /** * Options used to create a browser terminal. * * @remarks * Browser geometry is measured from the host and active font unless both `cols` and `rows` are * supplied. The host must have a nonzero width and height. */ export interface TerminalOptions extends CoreTerminalOptions { /** Host element. It may also be supplied later through {@link BrowserTerminal.open}. */ readonly container?: HTMLElement; /** Document used for DOM, font, and measurement work. Defaults to the global document. */ readonly documentOverride?: Document; /** * Worker policy: main thread, dedicated worker, or shared worker. * * @defaultValue A dedicated worker when `Worker` and `OffscreenCanvas` are supported, otherwise * the main thread. A dedicated worker that fails during startup is retried on the main thread; * shared-worker startup remains strict. `true` is equivalent to `'dedicated'`. */ readonly worker?: boolean | 'dedicated' | 'shared'; /** * Preferred renderer with automatic fallback. * * @defaultValue `'auto'`, which tries WebGPU, WebGL2, then Canvas 2D during initialization and * after an accelerated renderer cannot recover at runtime. */ readonly renderer?: RendererPreference; /** Enables alpha in terminal theme colors and rendering surfaces. @defaultValue `false` */ readonly allowTransparency?: boolean; /** Minimum WCAG contrast ratio applied to rendered text. @defaultValue `1` */ readonly minimumContrastRatio?: number; /** * CSS font-family stack used for measurement and rendering. * * @defaultValue `'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'` */ readonly fontFamily?: string; /** @defaultValue `14` CSS pixels. */ readonly fontSizePx?: number; /** @defaultValue `1.25` times the font size. */ readonly lineHeight?: number; /** @defaultValue `400` */ readonly fontWeight?: string | number; /** @defaultValue `700` */ readonly fontWeightBold?: string | number; /** @defaultValue `0` CSS pixels. */ readonly letterSpacingPx?: number; /** * Accessibility mirror level. * * @remarks * `'full'` mirrors visible viewport text from the rendering context into a live DOM log. Use it * when the product requires that assistive-technology surface and include its update cost in * performance testing. * * @defaultValue `'basic'` */ readonly accessibility?: 'off' | 'basic' | 'full'; /** @defaultValue `'Terminal'` */ readonly ariaLabel?: string; /** * Browser-compatible Ghostty VT WASM source. * * @defaultValue The `ghostty-vt.wasm` URL derived from the package entry point. */ readonly wasm?: Exclude; /** * Browser-compatible callback bridge WASM source. * * @defaultValue The `ghostty-callbacks.wasm` URL derived from the package entry point. */ readonly callbacksWasm?: Exclude; } /** Complete font metrics configuration for the browser renderer. */ export interface TerminalFontOptions { /** CSS font-family stack. */ readonly family: string; /** Font size in CSS pixels. */ readonly sizePx: number; /** Line height relative to the font size. */ readonly lineHeight: number; /** Normal font weight. */ readonly weight: string | number; /** Bold font weight. */ readonly boldWeight: string | number; /** Additional letter spacing in CSS pixels. */ readonly letterSpacingPx: number; } /** Font face loaded into the document and terminal worker. */ export interface TerminalFontFace { /** Font-family name assigned to the face. */ readonly family: string; /** A CSS `url(...)` source or raw OpenType font bytes. */ readonly source: string | ArrayBuffer; /** Optional browser font-face descriptors. */ readonly descriptors?: FontFaceDescriptors; } /** Bidirectional byte streams connecting a terminal to a PTY or remote shell. */ export interface TerminalTransport { /** Bytes received from a PTY or remote shell and written into the terminal. */ readonly readable: ReadableStream; /** Bytes generated by terminal input and written back to the PTY or remote shell. */ readonly writable: WritableStream; } /** Backpressure and cancellation policy for a terminal transport. */ export interface TerminalConnectionOptions { /** Signal used to close the connection. */ readonly signal?: AbortSignal; /** * Maximum queued terminal-input bytes before the connection fails. * * @defaultValue `1048576` bytes (1 MiB). */ readonly highWaterMarkBytes?: number; } /** Lifecycle state of a terminal transport connection. */ export type TerminalConnectionStatus = 'connecting' | 'open' | 'closing' | 'closed' | 'error'; /** Active connection between terminal input/output and a transport. */ export interface TerminalConnection extends Disposable { /** Current connection lifecycle state. */ readonly status: TerminalConnectionStatus; /** Settles after both transport directions finish. */ readonly closed: Promise; /** Terminal connection failure, when status is `error`. */ readonly error: Error | undefined; /** Gracefully closes both transport directions. */ close(reason?: string): Promise; /** Subscribes to lifecycle state changes. */ onStatusChange(listener: (status: TerminalConnectionStatus) => void): Disposable; } /** Extension activated against a browser terminal and disposed with it. */ export interface TerminalAddon extends Disposable { /** Attaches the addon to its terminal. */ activate(terminal: BrowserTerminal): void; } /** Operation that changed retained terminal text or its physical row layout. */ export type TerminalBufferChangeReason = 'write' | 'resize' | 'reset' | 'restore' | 'scrollback'; /** Notification that consumers of {@link BrowserTerminal.readBuffer} must refresh their data. */ export interface TerminalBufferChangeEvent { /** Operation that invalidated retained-buffer reads. */ readonly reason: TerminalBufferChangeReason; } /** Event payloads emitted by a browser terminal. */ export type BrowserTerminalEventMap = Omit & { /** Emitted when retained text or physical row layout changes, but not for viewport-only scrolls. */ readonly bufferChange: TerminalBufferChangeEvent; /** Emitted after a changed browser layout has been dispatched to the terminal backend. */ readonly resize: TerminalGeometry; /** Renderer selected after capability detection, restoration, or runtime fallback. */ readonly renderer: RendererInfo; /** Emitted after queued output has been parsed and rendered. */ readonly writeParsed: undefined; /** Emitted when the terminal selection changes. */ readonly selectionChange: undefined; /** Absolute zero-based offset of the first visible buffer row. */ readonly scroll: number; /** Authoritative buffer state emitted after a frame is painted. */ readonly viewportChange: TerminalViewportChangeEvent; /** Geometry emitted after applying a font change. */ readonly font: TerminalGeometry; }; /** * High-level browser terminal API. * * @remarks * A terminal owns its DOM, worker or main-thread backend, renderer, loaded fonts, addons, active * transports, and event listeners. Release them together with {@link BrowserTerminal.dispose}. */ export interface BrowserTerminal { /** Root DOM element owned by the terminal. */ readonly element: HTMLElement; /** The current grid and device-pixel backing-surface dimensions. */ readonly geometry: TerminalGeometry; /** Live active renderer and text-shaping information. */ readonly renderer: RendererInfo; /** Current authored theme. Missing properties inherit from `DEFAULT_THEME`. */ readonly theme: Readonly; /** Mounts a terminal created without a container. */ open(container: HTMLElement): Promise; /** * Queues text or bytes for VT parsing and returns immediately. * * @remarks Prefer bytes for PTY output to avoid a decode and encode cycle. */ write(data: string | Uint8Array): void; /** * Parses and renders text or bytes before resolving. * * @remarks Use this boundary for transport backpressure, ordered snapshots, and tests. */ writeAsync(data: string | Uint8Array): Promise; /** Encodes a physical keyboard input toward the PTY. */ sendKey(input: KeyInput): void; /** Encodes a pointer input or updates selection. */ sendPointer(input: PointerInput): void; /** Sends text input toward the PTY. */ sendText(data: string): void; /** Sends text through bracketed-paste handling when enabled. */ paste(data: string): void; /** * Enables the Kitty clipboard protocol bridge. * * @internal This capability is reserved for clipboard addons so clipboard access stays opt-in. */ enableClipboard(options?: ClipboardProtocolOptions): Promise; /** * Delivers a user-authorized MIME clipboard snapshot to Ghostty. * * @internal This capability is reserved for clipboard addons. */ pasteClipboard(request: ClipboardPasteRequest): Promise; /** Focuses the terminal input element. */ focus(): void; /** Blurs the terminal input element. */ blur(): void; /** * Fits the grid to the current container dimensions. * * @remarks Call after revealing a terminal that was measured in a hidden container. */ resize(): void; /** Sets an explicit character-grid size. */ resize(cols: number, rows: number): void; /** Recalculates grid geometry from the container, including when initial grid options were set. */ fit(): void; /** Scrolls the viewport by a signed row delta. */ 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 the current selection as plain 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 its initial values. */ reset(): void; /** * Reads a complete visible viewport snapshot. * * @remarks This crosses the worker boundary when worker rendering is active. Avoid polling it on * the output hot path. */ readViewport(): Promise; /** Reads a clamped page of retained buffer rows; defaults to the visible viewport. */ readBuffer(range?: TerminalBufferRange): Promise; /** Loads a font face in every rendering context used by the terminal. */ loadFont(face: TerminalFontFace): Promise; /** Applies font options and returns the resulting 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 theme and resolves after the resulting frame is rendered. */ setTheme(theme: TerminalTheme): Promise; /** Patches the current theme and resolves after the resulting frame is rendered. */ updateTheme(theme: TerminalTheme): Promise; /** Activates an addon and transfers disposal ownership to the terminal. */ loadAddon(addon: TerminalAddon): void; /** * Connects PTY byte streams with backpressure and lifecycle reporting. * * @remarks Incoming chunks are parsed sequentially with {@link BrowserTerminal.writeAsync}. * Terminal input is written to the transport without text conversion. */ connect(transport: TerminalTransport, options?: TerminalConnectionOptions): TerminalConnection; /** Subscribes to a typed browser terminal event. */ on(type: Key, listener: (value: BrowserTerminalEventMap[Key]) => void): Disposable; /** Releases workers, renderers, transports, addons, listeners, loaded fonts, and DOM resources. */ dispose(): void; } //# sourceMappingURL=types.d.ts.map