import type { TerminalLinkOptions, TerminalLinkDetectionError } from "./link-types.js"; import type { TerminalTransport, TerminalTransportCloseDetails } from "./transport-types.js"; export type * from "./transport-types.js"; import type { TerminalColorMode, TerminalPalette } from "./terminal-palette.js"; export type { TerminalColorMode, TerminalPalette } from "./terminal-palette.js"; import type { TerminalLayout, TerminalMarker, TerminalMarkerOptions, TerminalPadding, TerminalInsets, TerminalScrollbar, TerminalScrollbarConfiguration } from "./scrollbar-types.js"; export type * from "./link-types.js"; export type { TerminalRectangle, TerminalInsets, TerminalPadding, TerminalLayout, TerminalTextPosition, TerminalMarker, TerminalMarkerOptions, TerminalScrollbarMarker, TerminalScrollbarInteraction, TerminalScrollbarFrame, TerminalScrollbarRenderer, TerminalScrollbarOptions, TerminalScrollbarConfiguration, TerminalScrollbar, TerminalScrollbarTooltipContext, TerminalScrollbarTooltipRenderer } from "./scrollbar-types.js"; export type * from "./scrollbar-appearance.js"; /** Logical terminal dimensions, confirmed by the producer rather than reflowed locally. */ export interface TerminalGrid { columns: number; rows: number; } export interface TerminalSize { width: number; height: number; } export interface TerminalPoint { x: number; y: number; } export type MouseTrackingMode = 0 | 9 | 1000 | 1002 | 1003; export interface TerminalGeometry extends TerminalGrid { cellWidth: number; cellHeight: number; mouseTracking: MouseTrackingMode; } export interface TerminalPeer { id: string | null; primaryId: string | null; isPrimary: boolean; } /** Font size is an integer from 8 to 32; fixed grids allow 1–300 columns and 1–100 rows. */ export type TerminalSizing = { mode: "auto"; fontSize?: number; } | { mode: "fixed"; fontSize?: number; columns: number; rows: number; }; export type TerminalSizingState = { mode: "auto"; fontSize: number; } | { mode: "fixed"; fontSize: number; columns: number; rows: number; }; export interface TerminalFontFace { url: string; weight?: string; style?: string; } /** Without faces, a non-generic family must be installed locally in the worker's environment. */ export interface TerminalFont { family: string; faces?: readonly TerminalFontFace[]; } export type TerminalBuffer = "main" | "alternate"; export type SelectionMode = "character" | "word" | "line" | "rectangle"; export interface SelectionRange { row: number; startColumn: number; endColumn: number; } export type TerminalViewport = ({ available: true; generation: string; buffer: TerminalBuffer; totalRows: number; liveTop: number; top: number; requestId: number; rowIds: readonly string[]; revision: number; } | { available: false; generation?: undefined; buffer?: undefined; totalRows?: undefined; liveTop?: undefined; top?: undefined; requestId?: undefined; rowIds?: readonly string[]; revision?: undefined; }) & { following: boolean; pending: boolean; followTail: boolean; offset: number; /** Producer rejection of the last absolute navigation request, cleared by the next request. */ navigationError?: string; }; export type TerminalSelection = ({ status: "valid"; text: string; requestId: number; revision: number; } | { status: "none" | "invalidated"; text: null; requestId: number; revision: number; } | { status: "pending"; text: null; requestId: number; revision?: undefined; } | { status: "unavailable"; text: null; requestId?: undefined; revision?: undefined; }) & { mode: SelectionMode; ranges: readonly Readonly[]; canExtend?: boolean; message: string; active: boolean; pending: boolean; copying: boolean; copyError: string; }; export type TerminalStatusLevel = "info" | "ready" | "error"; /** Native WebSocket close details, not an assertion that the terminal workload completed. */ export interface TerminalCloseDetails { /** RFC 6455 status reported by the browser, including 1006 for abnormal loss without a close frame. */ readonly code: number; /** Peer-provided close reason, or "". Treat as untrusted text. */ readonly reason: string; /** Whether the browser observed a clean WebSocket closing handshake, not workload success. */ readonly wasClean: boolean; } export type TerminalRendererKind = "webgpu" | "webgl2"; /** Auto prefers WebGPU and falls back to WebGL2 for capability/device acquisition failures. */ export type TerminalRendererPreference = "auto" | TerminalRendererKind; /** Metrics are initially empty; individual fields appear as initialization and presentation proceed. */ export interface TerminalStats { /** Active backend; absent until renderer initialization completes. */ renderer?: TerminalRendererKind; /** Why auto selected WebGL2 instead of WebGPU; absent for explicit selection or WebGPU. */ rendererFallbackReason?: string; revision?: number; fullFrames?: number; frames?: number; presentations?: number; changedCells?: number; lastChangedCells?: number; discardedFrames?: number; imageCount?: number; textureBytes?: number; atlasGlyphs?: number; atlasBytes?: number; bytesReceived?: number; imageUploadBytes?: number; imagePayloadBytes?: number; gpu?: "initializing" | "ready" | "error" | "stopped"; connected?: boolean; warnings?: readonly string[]; fps?: number; receivedKBps?: number; workloadMBps?: number; captureMs?: number; rendererCpuMs?: number; preparationCpuMs?: number; workloadBytes?: number; outputBatches?: number; serverElapsedMs?: number; quads?: number; drawCalls?: number; columns?: number; rows?: number; mouseTracking?: MouseTrackingMode; peer?: TerminalPeer; fontFamily?: string; rasterScale?: number; backingScale?: number; backingWidth?: number; backingHeight?: number; atlasRebuilds?: number; glyphUploadBytes?: number; instanceBufferBytes?: number; } export interface InputModifiers { ctrl: boolean; alt: boolean; shift: boolean; meta: boolean; } export type PointerButton = "left" | "middle" | "right"; /** Input intents contain no browser event. Returning a route controls browser cancellation. */ export type TerminalInput = ({ type: "key"; key: string; code: string; repeat: boolean; } & InputModifiers) | ({ type: "pointer"; button: PointerButton; point: Readonly; } & InputModifiers) | ({ type: "wheel"; deltaX: number; deltaY: number; deltaMode: number; point: Readonly | null; } & InputModifiers) | { type: "paste" | "text"; text: string; }; export type InputRouteValue = "continue" | "consume" | "application" | "browser"; export type TerminalActionName = "copySelection" | "pasteClipboard" | "copyOrPaste" | "clearSelection" | "scrollToLive" | "scrollLines"; export interface CopySelectionOptions { clear?: boolean; } export interface TerminalInputContext { readonly terminal: WebTerminalHandle; readonly selection: TerminalSelection; readonly viewport: TerminalViewport; readonly buffer: TerminalBuffer | null; readonly mouseCaptured: boolean; readonly historical: boolean; readonly readOnly: boolean; readonly connected: boolean; readonly peer: TerminalPeer; } /** Custom actions validate their own arguments and may complete asynchronously. */ export type InputActionHandler = (context: TerminalInputContext, args: unknown, input: Readonly | undefined) => unknown; export type InputDecision = { route: InputRouteValue; action?: never; args?: never; } | { action: string | InputActionHandler; args?: unknown; route?: never; }; export type InputInterceptor = (input: Readonly, context: TerminalInputContext) => InputRouteValue | InputDecision | undefined; export type InputBinding = { id: string; match: (input: Readonly, context: TerminalInputContext) => boolean; when?: (context: TerminalInputContext, input: Readonly) => boolean; remove?: false; } & InputDecision; export type InputBindingOverride = InputBinding | { id: string; remove: true; }; export interface InputPolicyOptions { inputBindings?: readonly InputBindingOverride[]; onInput?: InputInterceptor; actions?: Readonly>; } /** Built-ins have typed arguments/results; custom names and callbacks own their argument validation. */ export interface RunTerminalAction { (action: "copySelection", args?: CopySelectionOptions, input?: TerminalInput): Promise; (action: "pasteClipboard", args?: undefined, input?: TerminalInput): Promise; (action: "copyOrPaste", args?: undefined, input?: TerminalInput): Promise; (action: "clearSelection" | "scrollToLive", args?: undefined, input?: TerminalInput): Promise; (action: "scrollLines", args: number, input?: TerminalInput): Promise; (action: Name extends TerminalActionName ? never : Name, args?: unknown, input?: TerminalInput): Promise; (action: InputActionHandler, args?: unknown, input?: TerminalInput): Promise; } export interface SelectionRectangle { left: number; top: number; width: number; height: number; } export interface SelectionUIState { readonly selection: Readonly; readonly viewport: Readonly; readonly geometry: Readonly; readonly canvasSize: Readonly; readonly connected: boolean; readonly readOnly: boolean; } /** A frozen snapshot; preventDefault() synchronously to replace the built-in Copy button. */ export interface SelectionUIDetail extends SelectionUIState { readonly overlay: HTMLDivElement; readonly signal: AbortSignal; readonly runAction: RunTerminalAction; readonly rects: readonly Readonly[]; } export type SelectionUIEvent = CustomEvent; /** Application-reported OSC 9;4 indicator, independent of shell execution. */ export type TerminalProgressState = "none" | "normal" | "error" | "indeterminate" | "warning"; /** Immutable current progress; a hidden or indeterminate indicator has no percentage. */ export interface TerminalProgress { readonly state: TerminalProgressState; readonly percentage: number | null; } /** OSC 7501 semantic state, independent of progress and shell execution. */ export type TerminalProgramStatusState = "idle" | "working" | "blocked" | "done" | "error"; export type TerminalProgramStatusKind = "permission" | "question" | "auth"; /** A self-reported record, not an authenticated process or an aggregate of its children. */ export interface TerminalProgramStatusRecord { /** Empty identifies the root; slash-separated paths identify nested records. */ readonly id: string; readonly state: TerminalProgramStatusState; readonly kind: TerminalProgramStatusKind | null; readonly progress: number | null; readonly app: string | null; readonly effectiveApp: string | null; readonly title: string | null; readonly message: string | null; } /** Records in least-recently-updated order. Messages and titles are untrusted plain text. */ export interface TerminalProgramStatusInventory { readonly records: readonly TerminalProgramStatusRecord[]; } /** An immutable presented inventory; missing parent records are never manufactured. */ export interface TerminalProgramStatusSnapshot extends TerminalProgramStatusInventory { find(id: string): TerminalProgramStatusRecord | undefined; getDescendants(id: string): readonly TerminalProgramStatusRecord[]; } /** Last reported OSC 133 phase. Unknown does not mean idle; commandLine is not execution. */ export type TerminalShellIntegrationPhase = "unknown" | "prompt" | "commandLine" | "executing" | "finished"; /** Current shell phase and latest reported completion status, not command history. */ export interface TerminalShellIntegration { readonly phase: TerminalShellIntegrationPhase; /** Null means no reported status, not success. Preserved across the next prompt/command. */ readonly lastExitCode: number | null; } /** Last reported OSC 7 working directory, or all-null before any is reported. */ export interface TerminalWorkingDirectory { /** Raw URI as reported by the shell (typically `file://`), or null. */ readonly uri: string | null; /** Authority from the URI; "" for a local/unqualified authority. Null when uri is null. */ readonly host: string | null; /** Decoded filesystem path from the URI. Null when uri is null. */ readonly path: string | null; } /** * Latest OSC 133 marker, distinct from {@link TerminalShellIntegration}: it additionally carries * any raw trailing `key=value` parameters (e.g. a `cmdline_url` extension on marker C). This is * the single most-recent marker only. Use {@link WebTerminalHandle.markers} for retained * producer-backed positions and {@link WebTerminalHandle.getCommandMarkDetails} for their * raw parameters; do not reconstruct command history from coalesced activity callbacks. */ export interface TerminalCommandMark { readonly phase: TerminalShellIntegrationPhase; readonly exitCode: number | null; /** Verbatim `key=value[;key=value...]` trailing the marker, or null when none was present. */ readonly rawParameters: string | null; } /** * Supply exactly one live transport. url is shorthand for createWebSocketTransport(url). * onClose receives actual transport close details once, with the view already disconnected, * even before the first frame. A pending mount rejects after notification. No close is * synthesized for abort, disposal, initialization failure, or timeout, and none runs after * disposal. Callback exceptions reach the host. Transport close is not workload completion. */ export type WebTerminalOptions = WebTerminalCommonOptions & ({ url: string | URL; transport?: never; /** Receives native WebSocket close details, including failed connection attempts. */ onClose?: (details: TerminalCloseDetails) => void; } | { url?: never; transport: TerminalTransport; /** Custom closes carry a reason without invented WebSocket codes or handshake status. */ onClose?: (details: TerminalTransportCloseDetails) => void; }); interface WebTerminalCommonOptions extends InputPolicyOptions { /** Keep the final received frame visible after transport close, until dispose. Defaults to false. */ preserveOnDisconnect?: boolean; /** Local terminal palette selection. Defaults to dark; system follows prefers-color-scheme. */ colorMode?: TerminalColorMode; lightModePalette?: TerminalPalette; darkModePalette?: TerminalPalette; /** Canvas2D scrollbar: overlay auto-hides (default); beside stays visible. False enables host-owned chrome. */ scrollbar?: TerminalScrollbar; /** Outer CSS-pixel padding around the content and scrollbar. Defaults to zero. */ padding?: TerminalPadding; /** Coherent local layout, including displayed cell dimensions, for external UI. */ onLayoutChange?: (layout: TerminalLayout) => void; /** Retained producer-backed markers, not a stream of shell executions. */ onMarkersChange?: (markers: readonly TerminalMarker[]) => void; /** Optional module-worker entry, resolved against the page URL. Defaults to this bundle with #hex1b-terminal-worker. */ workerUrl?: string | URL; /** Optional isolated regex worker entry, resolved against the page URL. Defaults to this bundle with #hex1b-link-detection-worker. */ linkDetectionWorkerUrl?: string | URL; /** Per-view link interaction. Detection is opt-in; omitted preserves legacy OSC 8 navigation. */ links?: false | TerminalLinkOptions; /** Detection failures are local to this feature and also reported through onStatus. */ onLinkDetectionError?: (error: TerminalLinkDetectionError) => void; signal?: AbortSignal; scale?: number | "auto"; /** Mount-time backend selection. Defaults to auto; explicit modes never fall back. */ renderer?: TerminalRendererPreference; font?: TerminalFont; sizing?: TerminalSizing; label?: string; /** Initial per-view input policy. Change it later with setReadOnly; not a server authorization boundary. */ readOnly?: boolean; onStatus?: (message: string, level: TerminalStatusLevel) => void; onGeometry?: (geometry: TerminalGeometry) => void; onSizingChange?: (sizing: TerminalSizingState) => void; onRoleChange?: (peer: TerminalPeer) => void; /** * Receives the first authoritative presented title (including "") before mount resolves, * then distinct presented changes. The title getter is updated first. Titles are untrusted * text; render with textContent, not HTML. No notifications after disposal. */ onTitleChange?: (title: string) => void; /** * Receives the first authoritative presented progress before mount resolves, then distinct * presented changes. Both activity getters update before either callback. Intermediate * states may coalesce; this is not a callback for every OSC sequence. None hides the indicator. * No notifications after disposal; connection loss does not manufacture a progress clear. */ onProgressChange?: (progress: TerminalProgress) => void; /** * Receives the first presented inventory before mount resolves, then distinct changes. * Intermediate reports may coalesce. Getters update first. No callbacks after disposal; * disconnect retains the last state rather than implying program completion. */ onProgramStatusChange?: (status: TerminalProgramStatusSnapshot) => void; /** * Receives the first authoritative presented shell state before mount resolves, then distinct * presented changes. This is not a lossless command-start/finish stream: entire commands may * occur between frames. Replays provide current state, never synthetic command executions. */ onShellIntegrationChange?: (shellIntegration: TerminalShellIntegration) => void; /** * Receives the first authoritative presented working directory before mount resolves, then * distinct presented changes. All-null means none reported yet; a malformed or non-`file` OSC 7 * report does not change presented state. No notifications after disposal. */ onWorkingDirectoryChange?: (workingDirectory: TerminalWorkingDirectory) => void; /** * Receives the first authoritative presented command mark before mount resolves (null if none * yet reported), then distinct presented changes. Only the latest marker is transmitted, not a * history; entire commands may occur between frames. Use onMarkersChange for the retained * inventory. No notifications after disposal. */ onCommandMarkChange?: (commandMark: TerminalCommandMark | null) => void; onStats?: (stats: TerminalStats, text: string | undefined) => void; onViewportChange?: (viewport: TerminalViewport) => void; onSelectionChange?: (selection: TerminalSelection) => void; onInputError?: (error: Error) => void; /** Must return undefined synchronously; async handlers cannot claim default UI ownership. */ onSelectionUI?: (event: SelectionUIEvent) => undefined; } /** Owns only the appended element and transport connection, not the server terminal. */ export interface WebTerminalHandle { readonly element: HTMLDivElement; readonly colorMode: TerminalColorMode; readonly resolvedColorMode: "light" | "dark"; /** Recolors retained indexed/default text without reconnecting or changing explicit RGB colors. */ setColorMode(mode: TerminalColorMode): void; /** Replaces one mode's palette. The active mode repaints immediately. */ setPalette(mode: "light" | "dark", palette: TerminalPalette): void; readonly geometry: TerminalGeometry; readonly peer: TerminalPeer; readonly connected: boolean; /** Whether this view blocks application input, resize, and primary takeover. */ readonly readOnly: boolean; /** Current presented workload title, or "" when unset/cleared. Retained on disconnect/dispose. */ readonly title: string; /** Current presented progress, initially none. Retained on disconnect/dispose; check connected. */ readonly progress: TerminalProgress; /** Immutable latest presented inventory, initially empty. Retained on disconnect/dispose. */ readonly programStatus: TerminalProgramStatusSnapshot; /** Current presented shell state, initially unknown. Retained on disconnect/dispose. */ readonly shellIntegration: TerminalShellIntegration; /** Current presented working directory, all-null initially. Retained on disconnect/dispose. */ readonly workingDirectory: TerminalWorkingDirectory; /** Latest presented command mark, or null if none reported yet. Retained on disconnect/dispose. */ readonly commandMark: TerminalCommandMark | null; readonly stats: TerminalStats; readonly screenText: string; readonly sizing: TerminalSizingState; readonly inputBindings: InputBinding[]; readonly inputContext: TerminalInputContext; readonly viewport: TerminalViewport; readonly layout: TerminalLayout; readonly padding: TerminalInsets; readonly scrollbar: false | TerminalScrollbarConfiguration; readonly markers: readonly TerminalMarker[]; readonly selection: TerminalSelection; runAction: RunTerminalAction; scrollLines(delta: number): void; /** Request an absolute row in the currently presented history coordinate space. */ scrollToRow(top: number): void; scrollToLive(): void; /** Resolve a retained marker on the producer; rejects unavailable or removed anchors. */ scrollToMarker(id: string): Promise; /** Register a per-view, reflow-aware marker. The server enforces the per-view quota. */ addMarker(options: TerminalMarkerOptions): Promise; removeMarker(id: string): Promise; getCommandMarkDetails(id: string): Promise; setPadding(padding: TerminalPadding): void; setScrollbar(scrollbar: TerminalScrollbar): void; /** Repaint after changing host-owned painter state or embedding theme colors. */ refreshScrollbar(): void; clearSelection(): void; refreshSelectionUI(): void; copySelection(options?: CopySelectionOptions): Promise; paste(text: string): void; pasteClipboard(): Promise; /** * Changes this view's input policy without remounting or changing peer roles. * Output, history, selection and copying remain available. Cancels active gestures, * pending composition and clipboard paste; already dispatched commands cannot be recalled. * Hosts must separately enforce permissions on their per-view Hwt1PresentationAdapter. */ setReadOnly(readOnly: boolean): void; /** Atomically replaces link options, cancelling active link gestures and stale detections. */ setLinks(options: false | TerminalLinkOptions): void; focus(): void; requestPrimary(): void; resize(columns: number, rows: number): void; setSizing(sizing: TerminalSizing): void; resync(): void; dispose(): void; } //# sourceMappingURL=types.d.ts.map