/** * The keys a prompt acts on. Everything else a terminal can send decodes to * `Char` when it is printable and `Unknown` when it is not, so a prompt never has * to know what a function key looks like. */ export declare const KeyName: Readonly<{ readonly Up: 'up'; readonly Down: 'down'; readonly Left: 'left'; readonly Right: 'right'; readonly Home: 'home'; readonly End: 'end'; readonly Enter: 'enter'; readonly Space: 'space'; readonly Tab: 'tab'; readonly ShiftTab: 'shiftTab'; readonly Backspace: 'backspace'; readonly ClearLine: 'clearLine'; readonly Escape: 'escape'; readonly Interrupt: 'interrupt'; readonly Char: 'char'; readonly Unknown: 'unknown'; }>; export type KeyName = (typeof KeyName)[keyof typeof KeyName]; export interface Key { readonly name: KeyName; /** What the key typed. Empty for every name but `Char`. */ readonly char: string; } /** * Bytes from a raw-mode terminal, decoded into keys. * * A class rather than a function because two things have to survive between * reads: a half-arrived escape sequence, and a UTF-8 code point split across the * chunk boundary. `TextDecoder` in streaming mode holds the second; `#pending` * holds the first, and an incomplete sequence is kept rather than guessed at. * * The one guess it does make: a chunk holding nothing but `0x1b` reads as the * Escape key. A terminal that split that byte from the `[A` behind it across two * reads would have it read as Escape followed by nothing bindable. Bun's PTY and every terminal * measured deliver a sequence in one read - `1b 5b 41` arrived as one chunk on * Bun 1.4.0, docs/bun-apis.md - and the alternative is a timer that delays every * real Escape. */ export declare class KeyDecoder { #private; push(bytes: Uint8Array): readonly Key[]; }