caique/raw
Every export of caique/raw, with its signature and doc comment: keyOf, canRender, renderList, askList, plus 3 types.
import { keyOf, canRender, renderList, … } from 'caique/raw';Functions
askList
Drive a list prompt with the arrow keys, repainting in place.
Returns the same Asked shape ask() does, so a caller can swap the two without
knowing which ran — and cancels the same way, because Ctrl-C in raw mode is a byte and
not a signal, and a person who presses it means to leave.
The cursor is hidden through closeout: the byte path resolves and restore() runs in
the finally; every path that never reaches the finally is the exit hook's.
function askList(spec: PromptSpec, io: RawIo, multi?: boolean): Promise<Asked>;| Parameter | Type |
|---|---|
spec | PromptSpec |
io | RawIo |
multi (optional) | boolean |
Returns Promise<Asked>
canRender
Whether this runtime can drive the raw renderer at all.
function canRender(keys: KeyStream): boolean;| Parameter | Type |
|---|---|
keys | KeyStream |
Returns boolean
keyOf
What a keypress means. Only the six that drive a list — everything else is other, and
a widget that does not know what to do with a key does nothing, which is what a person
expects from a key they pressed by accident.
function keyOf(data: string): Key;| Parameter | Type |
|---|---|
data | string |
Returns Key
renderList
One frame of the list. Exported so a test asserts the drawing rather than a screenshot.
function renderList(spec: PromptSpec, choices: Choice[], state: ListState, multi: boolean): string;| Parameter | Type |
|---|---|
spec | PromptSpec |
choices | Choice[] |
state | ListState |
multi | boolean |
Returns string
Interfaces
KeyStream
A stream that can be put into raw mode and read a key at a time.
interface KeyStream {
isTTY?: boolean;
/**
* Node's record of the mode. Read so that a stream somebody else already put into raw
* mode — a prompt library, the program itself — is left raw when this prompt ends.
*/
isRaw?: boolean;
setRawMode?(raw: boolean): unknown;
on(event: 'data', listener: (chunk: Buffer | string) => void): unknown;
off(event: 'data', listener: (chunk: Buffer | string) => void): unknown;
resume?(): unknown;
pause?(): unknown;
}RawIo
interface RawIo extends Io {
keys: KeyStream;
}Types
Key
type Key = 'up' | 'down' | 'space' | 'enter' | 'cancel' | 'other';