/** * Virtual Terminal for Testing * * A complete terminal simulator that: * - Implements TerminalRegion interface (drop-in replacement for tests) * - Tracks character positions in a 2D grid * - Handles ANSI escape codes (colors, cursor movement) * - Simulates text wrapping when width changes * - Allows resizing to test flex layouts and reflow * - Emits resize events that native TerminalRegion can listen to * - Provides readback of actual displayed content * * Use this instead of CapturableTerminal for comprehensive testing of: * - Resize behavior * - Text wrapping * - Flex layout calculations * - ANSI code handling */ import { EventEmitter } from 'events'; export interface TerminalCell { char: string; fgColor?: string; bgColor?: string; bold?: boolean; italic?: boolean; underline?: boolean; } export interface VirtualTerminalOptions { width?: number; height?: number; autoWrap?: boolean; } /** * A virtual terminal that simulates real terminal behavior for testing * Has the same API as TerminalRegion so it can be used as a drop-in replacement */ export declare class VirtualTerminal extends EventEmitter { private grid; private autoWrap; private cursorX; private cursorY; private currentStyle; private writeHistory; private setLineCalls; private _width; private _height; private writeStream; constructor(options?: VirtualTerminalOptions); get width(): number; get height(): number; /** * Set a line (1-based line numbers) - implements TerminalRegion interface * This simulates what happens when col.render() calls setLine * * Note: col.render() already handles merging at the x position, so setLine * receives the final merged line content. We just need to store it. */ setLine(lineNumber: number, content: string | { text: string; style?: any; }): void; /** * Get a line (1-based line numbers) - implements TerminalRegion interface * Returns the actual content that would be displayed */ getLine(lineNumber: number): string; /** * Clear a line (1-based) */ clearLine(lineNumber: number): void; /** * Set entire content (multiple lines) */ set(content: string | Array<{ text: string; style?: any; }> | any): void; /** * Flush - no-op for simulator */ flush(): void; /** * Set throttle - no-op for simulator */ setThrottle(fps: number): void; /** * Destroy - clears simulator */ destroy(clearFirst?: boolean): void; /** * Get width (for TerminalRegion interface) */ getWidth(): number; /** * Get height (for TerminalRegion interface) */ getHeight(): number; /** * Resize the terminal - this simulates what happens when a terminal is resized * Text that no longer fits will wrap or be truncated * * This method reflows existing content and emits a 'resize' event * that native TerminalRegion can listen to (via process.stdout.on('resize')) */ resize(newWidth: number, newHeight: number): void; /** * Expand terminal height */ private expandTo; /** * Write data to the terminal (simulating stdout.write) * Handles ANSI escape codes and updates the grid */ private write; /** * Handle ANSI escape codes */ private handleAnsiCode; /** * Apply ANSI escape code to current style */ private applyAnsiCode; /** * Get the character at a specific position */ getCell(x: number, y: number): TerminalCell | null; /** * Get a line as a string (strips ANSI for plain text, or includes ANSI) * Returns only the actual content, trimming trailing spaces */ private getLineAt; /** * Get all lines as an array */ getAllLines(includeAnsi?: boolean): string[]; /** * Get a snapshot of the terminal as a string */ snapshot(includeAnsi?: boolean): string; /** * Clear the terminal */ clear(): void; /** * Get write history (for debugging) */ getWriteHistory(): Array<{ data: string; timestamp: number; }>; /** * Get setLine call history */ getSetLineCalls(): Array<{ line: number; content: string; }>; /** * Create a NodeJS.WriteStream-like object that writes to this simulator * Useful for passing to native TerminalRegion * * This stream emits 'resize' events that native TerminalRegion listens to */ createWriteStream(): NodeJS.WriteStream; /** * Simulate a resize event * This is the key feature for testing resize behavior! * * This will: * 1. Resize the terminal grid and reflow content * 2. Update the writeStream's columns/rows (via getters) * 3. Emit 'resize' events that native TerminalRegion listens to */ simulateResize(newWidth: number, newHeight: number): void; } //# sourceMappingURL=virtual-terminal.d.ts.map