/** * screen-buffer.ts — a lightweight VT100/xterm screen emulator. * * Full-screen TUI programs (vim, htop, pi, …) repaint regions of the screen * in place with cursor-addressing escape sequences. An append-only stream * buffer is nearly useless for reading them: the interesting content is the * CURRENT SCREEN STATE, not the raw byte stream. This class maintains a * cols×rows character grid fed from the session's output stream so callers * can take a rendered snapshot at any time (think `tmux capture-pane`). * * Supported (enough for real TUIs): cursor movement (CUP/CUU/CUD/CUF/CUB/ * CNL/CPL/CHA/VPA), erase (ED/EL/ECH), insert/delete (ICH/DCH/IL/DL), * scrolling (SU/SD, DECSTBM scroll region, IND/RI/NEL), alternate screen * (?1049/?47/?1047), save/restore cursor (DECSC/DECRC, CSI s/u), tabs, * wide (CJK) characters, and OSC/DCS/APC/PM/SOS string skipping. * * It also auto-answers the terminal queries TUIs commonly block on when no * real terminal is present: DSR 6 (cursor position), DA1/DA2, XTWINOPS * 14/16/18 (sizes), and OSC 10/11 color queries. * * SGR attributes (colors/bold) are intentionally discarded — snapshots are * plain text for LLM consumption. * * This module MUST NOT import any platform SDK. */ export interface ScreenOptions { cols: number; rows: number; /** Callback used to answer terminal queries (written back to the app's stdin). */ respond?: (data: string) => void; } /** Approximate wcwidth: 2 for common East-Asian wide ranges, 0 for combining. */ export declare function charWidth(cp: number): number; export declare class TerminalScreen { cols: number; rows: number; /** * Count of screen-painting control operations seen (cursor addressing, * erase, scroll-region…). Heuristic signal that the program is a * full-screen TUI rather than a line-oriented REPL. */ paintOps: number; private lines; private curX; private curY; private savedX; private savedY; private scrollTop; private scrollBottom; private altSaved; private respond; private state; private csiParams; private csiIntermediates; private oscBuf; private strEsc; constructor(opts: ScreenOptions); get altActive(): boolean; cursor(): { x: number; y: number; }; private blankLine; /** Rendered plain-text snapshot of the current screen. */ snapshot(): string; resize(cols: number, rows: number): void; reset(): void; feed(data: string): void; private feedGround; private putChar; private lineFeed; private reverseLineFeed; private scrollUp; private scrollDown; private feedEsc; private startCsi; private feedCsi; private dispatchCsi; private handleDecMode; private eraseDisplay; private eraseLine; private insertLines; private deleteLines; private insertChars; private deleteChars; private eraseChars; private feedString; private dispatchOsc; } //# sourceMappingURL=screen-buffer.d.ts.map