caique/spec
Every export of caique/spec, with its signature and doc comment: flagOf, problemWith, BUILT_IN_KINDS, plus 4 types.
What a prompt is, before anything draws one (R1).
import { flagOf, problemWith, BUILT_IN_KINDS } from 'caique/spec';Functions
flagOf
--output-dir, which is what a refusal has to say to be actionable.
function flagOf(option: string): string;| Parameter | Type |
|---|---|
option | string |
Returns string
problemWith
A select without choices, or a confirm with them, is a spec that cannot be drawn.
Caught here rather than in the widget, so a program with a malformed prompt fails on the
first run instead of the first time someone reaches that option.
function problemWith(spec: PromptSpec): string | undefined;| Parameter | Type |
|---|---|
spec | PromptSpec |
Returns string \| undefined
Constants
BUILT_IN_KINDS
The six caique draws itself, as data rather than as a switch nobody can read back.
const BUILT_IN_KINDS: ReadonlySet<string>;Interfaces
BoundPrompt
A prompt spec bound to the option it answers.
interface BoundPrompt extends PromptSpec {
/** The option's long name, without dashes — `output-dir`, not `--output-dir`. */
option: string;
}Choice
One choice in a select or multiselect. value is what the option receives.
interface Choice {
value: string;
label?: string;
hint?: string;
}PromptSpec
interface PromptSpec {
kind: PromptKind;
/** What a person is asked. Also what an agent reads in the refusal when it cannot be asked. */
message: string;
/** Offered as the answer if the person just presses return. */
initial?: string | boolean | string[];
/** Required for `select` and `multiselect`; meaningless for the rest. */
choices?: Choice[];
/** Returns a message when the answer is unacceptable, or nothing when it is fine. */
validate?: (value: string) => string | undefined;
/**
* The most choices a raw `select` or `multiselect` shows at once, clack's name for it. The
* screen caps it too: never more than the terminal's rows less three.
*/
maxItems?: number;
}Types
PromptKind
The six kinds a prompt can be — plus whatever a plugin adds.
type PromptKind = 'text' | 'confirm' | 'select' | 'multiselect' | 'password' | 'path' | (string & {});