import type { KeyEvent, InputSource } from "./types.js"; export declare function parseKeypress(data: string): KeyEvent; /** * Try to read text bracketed by `open ... close` markers starting at * `pos` in `str`. Three outcomes: * * - `null` — `str` doesn't begin the `open` marker at `pos`. * - `{ kind: "partial", body }` — the `open` marker was found but * `close` hasn't arrived yet. Caller should buffer `body` and * re-attempt with the next chunk prepended (or simply stash it * until the close marker turns up). * - `{ kind: "complete", body, end }` — both markers found. `body` * is the text between them; `end` is the index in `str` just past * `close`, ready to resume scanning from. * * Used for bracketed-paste payloads (`\x1b[200~ ... \x1b[201~`) but * deliberately marker-agnostic — any future `open/close` framing can * reuse this. */ type BracketedRead = null | { kind: "partial"; body: string; } | { kind: "complete"; body: string; end: number; }; export declare function readBracketed(str: string, pos: number, open: string, close: string): BracketedRead; /** * Longest-prefix match against the known escape-sequence table at * `pos`. Returns the mapped `KeyEvent` plus the byte count consumed, * or `null` if either `str[pos] !== ESC` or no entry matches. */ export declare function readEscapeSequence(str: string, pos: number): { event: KeyEvent; consumed: number; } | null; /** * How many bytes a complete escape sequence that KEY_MAP does not know * takes up at `i`, or 0 when there is none. Ctrl+Left (`ESC [ 1 ; 5 D`), * F5 (`ESC [ 1 5 ~`) and the like are swallowed whole: read byte by byte * they would be Escape and then the letters `[1;5D`, typed into whatever * is being edited. */ export declare function unknownSequenceLength(str: string, i: number): number; /** * The Alt chord an `ESC ` pair means at `i`, or null when the byte * after the ESC is not a character a terminal sends that way. Terminal.app * and iTerm2 send Option+Left as `ESC b`, Option+Backspace as `ESC DEL`, * and Alt+y as `ESC y`. Read as Escape and then the character, `ESC b` * would type a `b`, and `ESC y` would answer a yes-or-no question that the * Escape had just opened. A real Escape key followed by a typed character * is read the same way only when both land in one read, which a person * cannot do by hand. */ export declare function altChord(str: string, i: number): { event: KeyEvent; consumed: number; } | null; export type TerminalInputOptions = { /** Emit Ctrl-C as a key WITHOUT raising SIGINT, so the app can run its own * teardown. Default false, which keeps the signal. */ suppressSigint?: boolean; }; export declare class TerminalInput implements InputSource { private keyWaiters; private keyQueue; private dataHandler; private sigcontHandler; private wasRaw; private initialized; private inLineMode; private suspended; private pasteBuffer; private escapeBuffer; private readonly suppressSigint; constructor(options?: TerminalInputOptions); private ensureInitialized; init(): void; private handleSuspendKeypress; /** Stop reading the terminal so a child process can. Pausing the stream * matters: with the listener gone but the stream still flowing, Node keeps * reading bytes from the terminal and dropping them, and a child editor * reading the same terminal loses keystrokes. The SIGCONT handler comes * off too: a child that was stopped and continued must not find stdin * back in raw mode. Ctrl+Z shares the suspend path, which a paused * stream does not disturb. */ release(): void; /** Take the terminal back after `release()`. */ reclaim(): void; private suspendForSigtstp; private resumeFromSuspend; nextKey(): Promise; /** * Internal: route a parsed `KeyEvent` to the next waiter or queue. * Shared by the per-keystroke emissions in * `parseAndEmit`. */ private emitKey; /** * Parse one stdin chunk into zero or more `KeyEvent`s and emit * them in order. Owns the side-band state machine across chunks: * an unfinished bracketed paste is parked in `this.pasteBuffer` * and resumed on the next call. * * Recognized units, tried in this order at each position: * 1. Continuation of a paste opened by a prior chunk * 2. A complete bracketed paste (`PASTE_START ... PASTE_END`) * 3. Ctrl+Z (0x1a) — raises SIGTSTP and stops parsing * 4. Ctrl+C (0x03) — raises SIGINT, emits, keeps parsing * 5. A known escape sequence (longest-prefix match) * 5b. A complete escape sequence the table does not know: dropped * 5c. ESC and a character: an Alt chord * 6. A single character (printable or ctrl+letter) */ private parseAndEmit; nextLine(prompt: string): Promise; destroy(): void; } export {};