caique
API reference

caique/ask

Every export of caique/ask, with its signature and doc comment: ask, projection, plus 6 types.

The six widgets, in line mode (R5) — and line mode is not a fallback, it is the floor.

import { ask, projection } from 'caique/ask';

Functions

ask

Ask one prompt and return its answer.

function ask(prompt: BoundPrompt | PromptSpec, io: Io): Promise<Asked>;
ParameterType
promptBoundPrompt | PromptSpec
ioIo

Returns Promise<Asked>

projection

What a widget would have written, without reading anything — the static projection (U3). The docs gallery, --help and a transcript in an issue all want the question without the conversation, and every other package in this family can answer that; so does this.

function projection(spec: PromptSpec): string;
ParameterType
specPromptSpec

Returns string

Interfaces

Io

interface Io {
    reader: Reader;
    writer: Writer;
    /**
     * The run's language for what caique draws itself — the instruction under a list, a problem
     * with an answer, the giving-up line — never the author's question (`localised-human-surfaces`
     * R6). `sayFor(runtime.locale)` from `caique/locale` builds it; absent, it is English.
     */
    say?: (english: string) => string;
}

Reader

A line of input, or undefined when the stream ended — which is a cancellation.

interface Reader {
    line(options?: ReadOptions): Promise<string | undefined>;
}

ReadOptions

interface ReadOptions {
    /**
     * Do not echo what is typed. Set for `password`, and honoured by whatever is reading —
     * this module never sees a terminal, so it cannot hide anything itself, and a widget
     * that never writes back what it read cannot leak it either.
     */
    hidden?: boolean;
}

Writer

interface Writer {
    write(text: string): void;
    /**
     * How many columns the terminal behind this writer is, when it knows. Line mode never
     * reads it; the raw renderer does, because a row wider than the terminal occupies more
     * than one row of screen and the repaint has to climb all of them.
     */
    readonly columns?: number | undefined;
    /**
     * How many rows the terminal is, when it knows. The raw renderer windows a list to it, so a
     * list longer than the screen never climbs above the top row on a repaint.
     */
    readonly rows?: number | undefined;
}

Types

Answer

type Answer = string | boolean | string[];

Asked

Answered, or cancelled — cancellation is a value here and a CANCELLED error above (R4).

type Asked = {
    ok: true;
    value: Answer;
} | {
    ok: false;
    reason: 'cancelled';
};

On this page