import { TextBufferRenderable, type TextBufferOptions, StyledText, type RenderContext, type TextChunk } from "@opentui/core"; import { type TerminalData } from "./ffi.js"; /** * Defines a region to highlight in the terminal output. */ export interface HighlightRegion { /** Line number (0-based) */ line: number; /** Start column (0-based, inclusive) */ start: number; /** End column (0-based, exclusive) */ end: number; /** If true, replaces the highlighted text with 'x' characters (for testing) */ replaceWithX?: boolean; /** Background color for the highlight (hex string like "#ff0000") */ backgroundColor: string; } /** * Applies highlights to chunks for a specific line. * Splits chunks at highlight boundaries and applies background colors. */ export declare function applyHighlightsToLine(chunks: TextChunk[], highlights: HighlightRegion[]): TextChunk[]; export interface CursorStyle { /** Whether to show the cursor */ visible?: boolean; /** Cursor style: 'block' inverts colors, 'underline' adds underline attribute */ style?: "block" | "underline"; } export declare function terminalDataToStyledText(data: TerminalData, highlights?: HighlightRegion[], cursor?: { x: number; y: number; style: "block" | "underline"; }): StyledText; export interface GhosttyTerminalOptions extends TextBufferOptions { ansi?: string | Buffer | Uint8Array; cols?: number; rows?: number; limit?: number; trimEnd?: boolean; highlights?: HighlightRegion[]; /** * Enable persistent mode for streaming/interactive use cases. * When true, the terminal maintains state between feed() calls. * Much more efficient for streaming than updating the ansi prop repeatedly. */ persistent?: boolean; /** * Show the terminal cursor. Defaults to false. */ showCursor?: boolean; /** * Cursor style: 'block' or 'underline'. When omitted, the terminal's * native cursor style is preserved (e.g. bar set via DECSCUSR). */ cursorStyle?: "block" | "underline"; /** * Whether this component participates in focus management. * When true, cursor rendering is gated on focus state. */ focusable?: boolean; } /** @deprecated Use GhosttyTerminalOptions instead */ export type TerminalBufferOptions = GhosttyTerminalOptions; export declare class GhosttyTerminalRenderable extends TextBufferRenderable { private _ansi; private _cols; private _rows; private _limit?; private _trimEnd?; private _highlights?; private _ansiDirty; private _lineCount; private _showCursor; private _cursorStyle; private _renderCursor; private _persistent; private _persistentTerminal; constructor(ctx: RenderContext, options: GhosttyTerminalOptions); /** * Returns the total number of lines in the terminal buffer (after limit and trimming) */ get lineCount(): number; get limit(): number | undefined; set limit(value: number | undefined); get trimEnd(): boolean | undefined; set trimEnd(value: boolean | undefined); get highlights(): HighlightRegion[] | undefined; set highlights(value: HighlightRegion[] | undefined); get showCursor(): boolean; set showCursor(value: boolean); get cursorStyle(): "block" | "underline" | undefined; set cursorStyle(value: "block" | "underline" | undefined); get ansi(): string | Buffer | Uint8Array; set ansi(value: string | Buffer | Uint8Array); get cols(): number; set cols(value: number); get rows(): number; set rows(value: number); /** Whether this terminal is in persistent mode */ get persistent(): boolean; /** Persistent mode cannot be changed after construction */ set persistent(_value: boolean); /** * Feed data to the terminal. Only works in persistent mode. * For stateless mode, update the `ansi` property instead. * * @param data - ANSI data to feed to the terminal */ feed(data: string | Buffer | Uint8Array): void; /** * Reset the terminal to its initial state. Only works in persistent mode. */ reset(): void; /** * Get the current cursor position. Only works in persistent mode. * @returns [x, y] cursor position */ getCursor(): [number, number]; /** * Get plain text content of the terminal. */ getText(): string; /** * Clean up resources. Called automatically when the component unmounts. */ destroy(): void; protected onRemove(): void; private hideTerminalCursor; private renderTerminalCursor; focus(): void; blur(): void; protected renderSelf(buffer: any): void; /** * Maps an ANSI line number to the corresponding scrollTop position for a parent ScrollBox. * Uses the actual rendered Y position from the text buffer's line info, which accounts * for text wrapping and actual layout. * * @param lineNumber - The line number (0-based) in the ANSI output * @returns The scrollTop value to pass to ScrollBox.scrollTo() * * @example * ```tsx * const scrollPos = terminalBufferRef.current.getScrollPositionForLine(42) * scrollBoxRef.current.scrollTo(scrollPos) * ``` */ getScrollPositionForLine(lineNumber: number): number; } /** @deprecated Use GhosttyTerminalRenderable instead */ export declare const TerminalBufferRenderable: typeof GhosttyTerminalRenderable; //# sourceMappingURL=terminal-buffer.d.ts.map