/** * Keyboard input parser - converts terminal input to key events * * Uses the termio tokenizer for escape sequence boundary detection, * then interprets sequences as keypresses. */ import { Buffer } from 'buffer'; import { type Tokenizer } from './termio/tokenize.js'; /** DECRPM status values (response to DECRQM) */ export declare const DECRPM_STATUS: { readonly NOT_RECOGNIZED: 0; readonly SET: 1; readonly RESET: 2; readonly PERMANENTLY_SET: 3; readonly PERMANENTLY_RESET: 4; }; /** * A response sequence received from the terminal (not a keypress). * Emitted in answer to queries like DECRQM, DA1, OSC 11, etc. */ export type TerminalResponse = /** DECRPM: answer to DECRQM (request DEC private mode status) */ { type: 'decrpm'; mode: number; status: number; } /** DA1: primary device attributes (used as a universal sentinel) */ | { type: 'da1'; params: number[]; } /** DA2: secondary device attributes (terminal version info) */ | { type: 'da2'; params: number[]; } /** Kitty keyboard protocol: current flags (answer to CSI ? u) */ | { type: 'kittyKeyboard'; flags: number; } /** DSR: cursor position report (answer to CSI 6 n) */ | { type: 'cursorPosition'; row: number; col: number; } /** OSC response: generic operating-system-command reply (e.g. OSC 11 bg color) */ | { type: 'osc'; code: number; data: string; } /** XTVERSION: terminal name/version string (answer to CSI > 0 q). * Example values: "xterm.js(5.5.0)", "ghostty 1.2.0", "iTerm2 3.6". */ | { type: 'xtversion'; name: string; }; /** Mutable cross-call state for the decomposed-paste matcher. */ export type Win32PasteState = { /** true between the decomposed start and end markers */ active: boolean; /** progress into the marker pattern currently being matched */ matched: number; /** keys held while a marker prefix match is in flight */ held: ParsedKey[]; /** collected paste content while active */ buffer: string; }; export type Win32ProtocolState = { held: ParsedKey[]; sequence: string; startedAt?: number; }; /** * Parser state carried between parseMultipleKeypresses calls: paste mode, * buffered incomplete input, and the internal tokenizer instance. */ export type KeyParseState = { mode: 'NORMAL' | 'IN_PASTE'; incomplete: string; pasteBuffer: string; /** * Pending high surrogate from a win32-input-mode record. Uc is a UTF-16 * code unit, so supplementary-plane characters (emoji, CJK ext-B) arrive * as two consecutive records; the high half waits here for its low half. */ win32HighSurrogate?: number; /** * Pending high surrogate for the Alt+numpad synthesis path — separate * from win32HighSurrogate because the two Alt rounds of one supplementary * char interleave with keydown records (Alt-down, numpad digits) that * would settle the regular slot before the low half arrives. */ win32AltHighSurrogate?: number; /** * Decomposed bracketed-paste tracking for win32-input-mode. Classic * conhost synthesizes pastes as per-char KEY_EVENT_RECORDs — including * the ESC[200~ / ESC[201~ markers themselves — so under W32IM the markers * arrive as ordinary key records and must be reassembled here (issue #147). */ win32Paste?: Win32PasteState; /** * Terminal CSI/SS3 bytes synthesized by conhost as one win32 input * record per character. Only Vk=0/Sc=0 records enter this matcher, keeping * physically typed text out of the protocol path. */ win32Protocol?: Win32ProtocolState; /** * Pending prefix of an SGR mouse report that fragmented mid-sequence * (ConPTY split a report across reads and App's escape timer flushed the * buffered ESC prefix). Holds at most one incomplete `[