import { ReactNode } from 'react'; import { EventEmitter } from 'events'; /** * Minimal buffer interface — matches BrowserBuffer's public API. * This avoids a hard dependency on @gridland/web for the testing utilities. */ interface ReadableBuffer { width: number; height: number; char: Uint32Array; fg: Float32Array; bg: Float32Array; attributes: Uint32Array; } /** * Screen provides query helpers for reading buffer content in tests. * Unlike ink-testing which parses ANSI, we read TypedArrays directly. */ declare class Screen { private buffer; private _frames; constructor(buffer: ReadableBuffer); /** Capture a frame snapshot (call after each render) */ captureFrame(): void; /** Get the current screen text (plain chars, trailing spaces trimmed) */ text(): string; /** Get raw text including all spaces (no trimming) */ rawText(): string; /** Check if the screen contains the given text */ contains(text: string): boolean; /** Check if the screen matches a regex */ matches(pattern: RegExp): boolean; /** Get a specific line (0-indexed) */ line(n: number): string; /** Get all non-empty lines */ lines(): string[]; /** Get all captured frames */ frames(): string[]; /** Get the number of columns */ get width(): number; /** Get the number of rows */ get height(): number; /** Get the raw attributes u32 at a cell position (0-indexed row, col) */ attributeAt(row: number, col: number): number; /** Get the raw fg RGBA floats at a cell position as [r, g, b, a] */ fgAt(row: number, col: number): [number, number, number, number]; } /** * Minimal render context interface for key input. */ interface KeyInputContext { keyInput: EventEmitter; _internalKeyInput: EventEmitter; } /** * KeySender simulates keyboard input for testing. */ declare class KeySender { private ctx; constructor(ctx: KeyInputContext); private sendKey; /** Type a string of text character by character */ type(text: string): void; /** Press a single character key */ press(char: string): void; /** Press a key with modifier flags (ctrl, meta, shift, option). */ pressWith(char: string, options: { ctrl?: boolean; meta?: boolean; shift?: boolean; option?: boolean; }): void; /** Send raw data (for escape sequences etc.) */ raw(data: string): void; enter(): void; escape(): void; tab(): void; backspace(): void; delete(): void; space(): void; up(): void; down(): void; left(): void; right(): void; home(): void; end(): void; pageUp(): void; pageDown(): void; } interface WaitForOptions { /** Timeout in ms (default: 3000) */ timeout?: number; /** Polling interval in ms (default: 50) */ interval?: number; } /** * Wait for a condition to be met on the screen. * * @param screen - The screen to poll * @param condition - Either a string (wait for screen to contain it) or a function (wait for it to not throw) * @param options - Timeout and interval settings */ declare function waitFor(screen: Screen, condition: string | (() => void), options?: WaitForOptions): Promise; interface TuiInstance { /** Screen queries — read buffer content */ screen: Screen; /** Key input simulation */ keys: KeySender; /** Wait for text or assertion */ waitFor: (condition: string | (() => void), options?: WaitForOptions) => Promise; /** Force a synchronous render cycle */ flush: () => void; /** Re-render with new content */ rerender: (node: ReactNode) => void; /** Unmount and clean up */ unmount: () => void; } interface RenderTuiOptions { /** Number of columns (default: 80) */ cols?: number; /** Number of rows (default: 24) */ rows?: number; } /** * Render a Gridland component for testing. * * Note: This function requires @opentui/core and the gridland-web browser runtime * to be available. It works in test environments that have the opentui monorepo * accessible and proper module resolution configured. * * For simpler testing (Screen, Keys, waitFor), use those classes directly * with a BrowserBuffer — they have no external dependencies. */ declare function renderTui(node: ReactNode, options?: RenderTuiOptions): TuiInstance; /** * Clean up all active test instances. Call in afterEach(). */ declare function cleanup(): void; export { KeySender, type RenderTuiOptions, Screen, type TuiInstance, type WaitForOptions, cleanup, renderTui, waitFor };