import { _ as PartialPromptTheme, a as SubmitResult, b as ValidateFn, c as TerminalOutput, d as runPrompt, f as submit, g as NotChoiceTuple, h as ChoiceValue, i as PromptConfig, l as assertTTY, m as Choice, n as KeypressEvent, o as TerminalIO, p as withTerminalIO, r as NonInteractiveError, s as TerminalInput, t as HandleKeyResult, u as isTTY, v as PromptTheme, y as SchemaOrValidate } from "./renderer-DZNelBoQ.js"; import { StandardSchema } from "@crustjs/utils/schema"; /** * Default prompt theme with a polished, gum/clack-inspired aesthetic. * * Uses `@crustjs/style` color functions for ANSI output that respects * terminal capability detection (NO_COLOR, non-TTY graceful degradation). * Its TTY check reads `process.stdout`; prompts fill unset theme slots * with these styles detected from their own output stream instead. */ export declare const defaultTheme: PromptTheme; /** * Options for the {@link confirm} prompt. * * @example * ```ts * const shouldContinue = await confirm({ * message: "Do you want to continue?", * }); * ``` * * @example * ```ts * const agreed = await confirm({ * message: "Accept terms?", * active: "Agree", * inactive: "Decline", * default: false, * }); * ``` */ interface ConfirmOptions { /** The prompt message displayed to the user */ readonly message?: string | undefined; /** * Value used when the user presses Enter without toggling. * * @default true */ readonly default?: boolean | undefined; /** Initial value — if provided, the prompt is skipped and this value is returned immediately */ readonly initial?: boolean | undefined; /** * Label for the affirmative option. * * @default "Yes" */ readonly active?: string | undefined; /** * Label for the negative option. * * @default "No" */ readonly inactive?: string | undefined; /** Per-prompt theme overrides */ readonly theme?: PartialPromptTheme | undefined; } /** * Display an interactive yes/no confirmation prompt. * * Shows two side-by-side options (default: "Yes" / "No") that the user * toggles with arrow keys, h/l, y/n, or Tab, then confirms with Enter. * * If `initial` is provided, the prompt is skipped and the value is returned * immediately — useful for prefilling from CLI flags. * * In non-interactive environments (no TTY), the `default` value is returned * automatically if explicitly provided. * * @param options - Confirm prompt configuration * @returns The user's boolean selection * @throws {NonInteractiveError} when the input or output is not a TTY and no `initial` or explicit `default` is provided * * @example * ```ts * const proceed = await confirm({ * message: "Do you want to continue?", * }); * ``` * * @example * ```ts * // Custom labels with default value * const accepted = await confirm({ * message: "Accept the license?", * active: "Accept", * inactive: "Decline", * default: false, * }); * ``` * * @example * ```ts * // Skip prompt when flag is provided * const yes = await confirm({ * message: "Continue?", * initial: flags.yes, * }); * ``` */ export declare function confirm(options: ConfirmOptions, io?: TerminalIO): Promise; /** Options for the {@link filter} prompt. */ interface FilterOptions { /** The prompt message displayed to the user */ readonly message?: string | undefined; /** List of choices — strings or `{ label, value, hint? }` objects */ readonly choices: readonly Choice[]; /** Initial value — if provided, the prompt is skipped and this value is returned immediately */ readonly initial?: T | undefined; /** Default value — matches a choice using reference equality for object values. Returned automatically in non-interactive environments. */ readonly default?: T | undefined; /** Placeholder text shown when the query input is empty */ readonly placeholder?: string | undefined; /** * Maximum number of visible filtered results before scrolling. * * @default 10 */ readonly maxVisible?: number | undefined; /** Per-prompt theme overrides */ readonly theme?: PartialPromptTheme | undefined; } /** * Display an interactive fuzzy-filter prompt over a list of choices. * * Type to filter the list using fuzzy matching. Navigate filtered results * with Up/Down arrows, confirm with Enter. Matched characters are * highlighted in the results. * * If `initial` is provided, the prompt is skipped and the value is returned * immediately — useful for prefilling from CLI flags. * * In non-interactive environments (no TTY), the `default` value is returned * automatically if provided. * * @param options - Filter prompt configuration * @returns The value of the selected choice * @throws {NonInteractiveError} when the input or output is not a TTY and no `initial` or `default` is provided * * @example * ```ts * const lang = await filter({ * message: "Search for a language", * choices: ["TypeScript", "JavaScript", "Rust", "Python", "Go"], * }); * ``` * * @example * ```ts * const pkg = await filter<{ name: string; version: string }>({ * message: "Find a package", * choices: [ * { label: "react", value: { name: "react", version: "18.2" } }, * { label: "vue", value: { name: "vue", version: "3.3" } }, * ], * placeholder: "Type to filter...", * }); * ``` * * @example * ```ts * // Skip prompt when flag is provided * const tool = await filter({ * message: "Pick a tool", * choices: ["prettier", "eslint", "biome"], * initial: flags.tool, * }); * ``` */ export declare function filter, ...Choice[]]>(options: FilterOptions> & { readonly choices: C; }, io?: TerminalIO): Promise>; export declare function filter(options: FilterOptions & { readonly choices: C & NotChoiceTuple; }, io?: TerminalIO): Promise; export declare function filter[] = readonly Choice[]>(options: FilterOptions & { readonly choices: C & NotChoiceTuple; }, io?: TerminalIO): Promise; interface InputBaseOptions { /** The prompt message displayed to the user */ readonly message?: string | undefined; /** Placeholder text shown when the input is empty. Overrides the default value as visual placeholder when both are set. */ readonly placeholder?: string | undefined; /** Default value used when the user submits an empty input. Also shown as placeholder text when `placeholder` is not set. */ readonly default?: string | undefined; /** Initial value — if provided, the prompt is skipped and this value is returned immediately */ readonly initial?: string | undefined; /** Per-prompt theme overrides */ readonly theme?: PartialPromptTheme | undefined; } /** * Options for the {@link input} prompt. * * Use `schema` for Standard Schema validation and transformation, or * `validate` for a throw-on-failure function. They are mutually exclusive. * * @typeParam Output - the Standard Schema output type. Defaults to `string` * when no schema is supplied. * * @example * ```ts * // Function shape — resolves to string * const name = await input({ * message: "What is your name?", * validate: (v) => { * if (v.length === 0) throw new Error("Name is required"); * }, * }); * ``` * * @example * ```ts * // Schema shape — resolves to the schema's parsed output type * const port = await input({ * message: "Port?", * schema: z.coerce.number().int().min(1), * }); * // typeof port === "number" * ``` */ type InputOptions = InputBaseOptions & SchemaOrValidate; /** * Display an interactive single-line text input prompt. * * Supports placeholder text, default values, validation with inline error * display, and full cursor editing (insert, delete, arrow keys, home/end). * * If `initial` is provided, the prompt is skipped and the value is returned * immediately — useful for prefilling from CLI flags. * * In non-interactive environments (no TTY), the `default` value is returned * automatically if provided. * * Use `schema` for Standard Schema validation/transformation or `validate` * for a throw-on-failure function. The two options are mutually exclusive. * * @param options - Input prompt configuration * @returns The entered text, or the schema's output when `schema` is supplied. * @throws {NonInteractiveError} when the input or output is not a TTY and no `initial` or `default` is provided * * @example * ```ts * const name = await input({ * message: "What is your name?", * placeholder: "John Doe", * validate: (v) => { * if (v.length === 0) throw new Error("Name cannot be empty"); * }, * }); * ``` * * @example * ```ts * // Schema validation — returns the parsed/transformed value * const port = await input({ * message: "Port?", * schema: z.coerce.number().int().min(1), * }); * // typeof port === "number" * ``` */ export declare function input(options: InputBaseOptions & { readonly schema: StandardSchema; readonly validate?: never; }, io?: TerminalIO): Promise; export declare function input(options?: InputBaseOptions & { readonly schema?: never; readonly validate?: ValidateFn; }, io?: TerminalIO): Promise; /** * Options for the {@link multifilter} prompt. */ interface MultifilterOptions { /** The prompt message displayed to the user */ readonly message?: string | undefined; /** List of choices — strings or `{ label, value, hint? }` objects */ readonly choices: readonly Choice[]; /** Default selected values — pre-selects matching choices */ readonly default?: readonly T[] | undefined; /** Initial value — if provided, the prompt is skipped and this value is returned immediately */ readonly initial?: readonly T[] | undefined; /** * Whether at least one item must be selected. * * @default false */ readonly required?: boolean | undefined; /** Minimum number of selections required */ readonly min?: number | undefined; /** Maximum number of selections allowed */ readonly max?: number | undefined; /** Placeholder text shown when the query input is empty */ readonly placeholder?: string | undefined; /** * Maximum number of visible filtered results before scrolling. * * @default 10 */ readonly maxVisible?: number | undefined; /** Per-prompt theme overrides */ readonly theme?: PartialPromptTheme | undefined; } /** * Display an interactive fuzzy-filter prompt with checkbox-style multi-selection. * * Type to filter the list using fuzzy matching. Navigate filtered results with * Up/Down arrows, toggle the highlighted item with Space, and confirm with * Enter. Matched characters are highlighted in the results. * * If `initial` is provided, the prompt is skipped and the values are returned * immediately. * * In non-interactive environments (no TTY), the `default` values are returned * automatically if provided. */ export declare function multifilter, ...Choice[]]>(options: MultifilterOptions> & { readonly choices: C; }, io?: TerminalIO): Promise[]>; export declare function multifilter(options: MultifilterOptions & { readonly choices: C & NotChoiceTuple; }, io?: TerminalIO): Promise; export declare function multifilter[] = readonly Choice[]>(options: MultifilterOptions & { readonly choices: C & NotChoiceTuple; }, io?: TerminalIO): Promise; /** * Options for the {@link multiselect} prompt. * * @example * ```ts * const toppings = await multiselect({ * message: "Select toppings", * choices: ["cheese", "pepperoni", "mushrooms", "olives"], * }); * ``` * * @example * ```ts * const features = await multiselect({ * message: "Enable features", * choices: [ * { label: "TypeScript", value: "ts", hint: "recommended" }, * { label: "ESLint", value: "eslint" }, * { label: "Prettier", value: "prettier" }, * ], * default: ["ts"], * required: true, * }); * ``` */ interface MultiselectOptions { /** The prompt message displayed to the user */ readonly message?: string | undefined; /** List of choices — strings or `{ label, value, hint? }` objects */ readonly choices: readonly Choice[]; /** Default selected values — matches choices using reference equality for object values. */ readonly default?: readonly T[] | undefined; /** Initial value — if provided, the prompt is skipped and this value is returned immediately */ readonly initial?: readonly T[] | undefined; /** * Whether at least one item must be selected. * * @default false */ readonly required?: boolean | undefined; /** Minimum number of selections required */ readonly min?: number | undefined; /** Maximum number of selections allowed */ readonly max?: number | undefined; /** * Maximum number of visible choices before scrolling. * * @default 10 */ readonly maxVisible?: number | undefined; /** Per-prompt theme overrides */ readonly theme?: PartialPromptTheme | undefined; } /** * Display an interactive checkbox-style multi-selection prompt. * * Navigate with Up/Down arrows (or k/j vim keys), toggle selection with Space, * toggle all with 'a', invert selection with 'i', and confirm with Enter. * When the list exceeds `maxVisible` items, the viewport scrolls with * indicators showing more items above or below. * * If `initial` is provided, the prompt is skipped and the value is returned * immediately -- useful for prefilling from CLI flags. * * In non-interactive environments (no TTY), the `default` values are returned * automatically if provided. * * @param options - Multiselect prompt configuration * @returns Array of selected values * @throws {NonInteractiveError} when the input or output is not a TTY and no `initial` or `default` is provided * * @example * ```ts * const toppings = await multiselect({ * message: "Select toppings", * choices: ["cheese", "pepperoni", "mushrooms", "olives"], * }); * ``` * * @example * ```ts * const features = await multiselect({ * message: "Enable features", * choices: [ * { label: "TypeScript", value: "ts", hint: "recommended" }, * { label: "ESLint", value: "eslint" }, * { label: "Prettier", value: "prettier" }, * ], * default: ["ts"], * required: true, * }); * ``` * * @example * ```ts * // Skip prompt when flags are provided * const features = await multiselect({ * message: "Features?", * choices: ["auth", "logging", "metrics"], * initial: flags.features, * }); * ``` */ export declare function multiselect, ...Choice[]]>(options: MultiselectOptions> & { readonly choices: C; }, io?: TerminalIO): Promise[]>; export declare function multiselect(options: MultiselectOptions & { readonly choices: C & NotChoiceTuple; }, io?: TerminalIO): Promise; export declare function multiselect[] = readonly Choice[]>(options: MultiselectOptions & { readonly choices: C & NotChoiceTuple; }, io?: TerminalIO): Promise; interface PasswordBaseOptions { /** The prompt message displayed to the user */ readonly message?: string | undefined; /** * Character used to mask the input. * * @default "*" */ readonly mask?: string | undefined; /** Initial value — if provided, the prompt is skipped and this value is returned immediately */ readonly initial?: string | undefined; /** Per-prompt theme overrides */ readonly theme?: PartialPromptTheme | undefined; } /** * Options for the {@link password} prompt. * * Use `schema` for Standard Schema validation and transformation, or * `validate` for a throw-on-failure function. They are mutually exclusive. * * @example * ```ts * const secret = await password({ * message: "Enter your password:", * validate: (v) => { * if (v.length < 8) throw new Error("Password must be at least 8 characters"); * }, * }); * ``` */ type PasswordOptions = PasswordBaseOptions & SchemaOrValidate; /** * Display an interactive masked password input prompt. * * Characters are shown as the mask character (default `"*"`) as the user * types. After submission, a fixed-length mask is displayed to prevent * revealing the password length. * * Supports validation with inline error display and full cursor editing * (insert, delete, arrow keys, home/end). * * If `initial` is provided, the prompt is skipped and the value is returned * immediately — useful for prefilling from CLI flags. * * Use `schema` for Standard Schema validation/transformation or `validate` * for a throw-on-failure function. The two options are mutually exclusive. * * @param options - Password prompt configuration * @returns The entered text, or the schema's output when `schema` is supplied. * @throws {NonInteractiveError} when the input or output is not a TTY and no `initial` is provided * * @example * ```ts * const secret = await password({ * message: "Enter your password:", * validate: (v) => { * if (v.length < 8) throw new Error("Password must be at least 8 characters"); * }, * }); * ``` * * @example * ```ts * // Custom mask character * const pin = await password({ * message: "Enter PIN:", * mask: "●", * }); * ``` */ export declare function password(options: PasswordBaseOptions & { readonly schema: StandardSchema; readonly validate?: never; }, io?: TerminalIO): Promise; export declare function password(options?: PasswordBaseOptions & { readonly schema?: never; readonly validate?: ValidateFn; }, io?: TerminalIO): Promise; /** * Options for the {@link select} prompt. * * @example * ```ts * const color = await select({ * message: "Pick a color", * choices: ["red", "green", "blue"], * }); * ``` * * @example * ```ts * const port = await select({ * message: "Choose a port", * choices: [ * { label: "HTTP", value: 80 }, * { label: "HTTPS", value: 443, hint: "recommended" }, * ], * default: 443, * }); * ``` */ interface SelectOptions { /** The prompt message displayed to the user */ readonly message?: string | undefined; /** List of choices — strings or `{ label, value, hint? }` objects */ readonly choices: readonly Choice[]; /** Default value — sets the initial cursor position using reference equality for object values. */ readonly default?: T | undefined; /** Initial value — if provided, the prompt is skipped and this value is returned immediately */ readonly initial?: T | undefined; /** * Maximum number of visible choices before scrolling. * * @default 10 */ readonly maxVisible?: number | undefined; /** Per-prompt theme overrides */ readonly theme?: PartialPromptTheme | undefined; } /** * Display an interactive single-selection prompt from a list of choices. * * Navigate with Up/Down arrows (or k/j vim keys), confirm with Enter. * When the list exceeds `maxVisible` items, the viewport scrolls with * indicators showing more items above or below. * * If `initial` is provided, the prompt is skipped and the value is returned * immediately -- useful for prefilling from CLI flags. * * In non-interactive environments (no TTY), the `default` value is returned * automatically if provided. * * @param options - Select prompt configuration * @returns The value of the selected choice * @throws {NonInteractiveError} when the input or output is not a TTY and no `initial` or `default` is provided * * @example * ```ts * const color = await select({ * message: "Pick a color", * choices: ["red", "green", "blue"], * }); * ``` * * @example * ```ts * const port = await select({ * message: "Choose a port", * choices: [ * { label: "HTTP", value: 80 }, * { label: "HTTPS", value: 443, hint: "recommended" }, * ], * default: 443, * }); * ``` * * @example * ```ts * // Skip prompt when flag is provided * const env = await select({ * message: "Environment?", * choices: ["dev", "staging", "prod"], * initial: flags.env, * }); * ``` */ export declare function select, ...Choice[]]>(options: SelectOptions> & { readonly choices: C; }, io?: TerminalIO): Promise>; export declare function select(options: SelectOptions & { readonly choices: C & NotChoiceTuple; }, io?: TerminalIO): Promise; export declare function select[] = readonly Choice[]>(options: SelectOptions & { readonly choices: C & NotChoiceTuple; }, io?: TerminalIO): Promise; /** Configuration for {@link createPrompts}. */ interface CreatePromptsOptions { /** * Partial theme applied to every prompt from this instance. * Per-call `theme` options layer on top; unspecified slots * fall back to `defaultTheme`. */ readonly theme?: PartialPromptTheme | undefined; } /** * A set of prompt functions bound to a theme. * * Same signatures as the bare exports (`input`, `select`, …); the only * difference is the theme resolution order: `defaultTheme` ← instance * theme ← per-call `theme` option. */ interface PromptsInstance { /** * The fully resolved instance theme. Pass to custom `runPrompt` * renderers to match this instance's styling. */ readonly theme: PromptTheme; readonly input: typeof input; readonly password: typeof password; readonly confirm: typeof confirm; readonly select: typeof select; readonly multiselect: typeof multiselect; readonly filter: typeof filter; readonly multifilter: typeof multifilter; } /** * Create a {@link PromptsInstance} with a theme applied to every prompt. * * There is no global theme state: theming is explicit, owned by whoever * holds the instance. * * @example * ```ts * import { createPrompts } from "@crustjs/prompts"; * import { magenta, cyan } from "@crustjs/style"; * * const p = createPrompts({ theme: { prefix: magenta, success: cyan } }); * const name = await p.input({ message: "Name?" }); * ``` */ export declare function createPrompts(options?: CreatePromptsOptions): PromptsInstance; /** * Result of a fuzzy match against a single candidate. */ interface FuzzyMatchResult { /** Whether the candidate matches the query */ readonly match: boolean; /** Match quality score — higher is better. 0 if no match. */ readonly score: number; /** Indices of matched characters in the candidate string */ readonly indices: readonly number[]; } /** * A fuzzy-filtered item with its match metadata. */ interface FuzzyFilterResult { /** The original item, with its full type (e.g. a choice's `hint`) */ readonly item: Item; /** Match quality score */ readonly score: number; /** Indices of matched characters in the label */ readonly indices: readonly number[]; } /** * Test whether a query fuzzy-matches a candidate string. * * Each character in `query` must appear in `candidate` in order (but not * necessarily contiguously). Matching is case-insensitive. * * The score rewards: * - Consecutive matched characters (contiguity bonus) * - Matches at the start of the string * - Matches at word boundaries (after space, `-`, `_`, `.`) * * @param query - The search query * @param candidate - The string to match against * @returns Match result with boolean, score, and matched character indices * * @example * ```ts * fuzzyMatch("abc", "alphabet cookie"); // { match: true, score: ..., indices: [0, 9, 10] } * fuzzyMatch("xyz", "hello"); // { match: false, score: 0, indices: [] } * fuzzyMatch("", "anything"); // { match: true, score: 0, indices: [] } * ``` */ export declare function fuzzyMatch(query: string, candidate: string): FuzzyMatchResult; /** * Filter and sort a list of labeled items by fuzzy-matching against a query. * * Returns only items that match, sorted by score descending (best matches first). * An empty query returns all items (each with score 0 and empty indices). * * @param query - The search query * @param items - Array of items with `label` and `value` properties * @returns Matched items, as the same objects passed in, sorted by score (highest first) * * @example * ```ts * const results = fuzzyFilter("ts", [ * { label: "TypeScript", value: "ts" }, * { label: "JavaScript", value: "js" }, * { label: "Rust", value: "rs" }, * ]); * // Returns TypeScript and Rust (both contain "t" then "s") * ``` */ export declare function fuzzyFilter(query: string, items: readonly Item[]): FuzzyFilterResult[]; /** Apply the filter-match style to matched runs in a label. */ export declare function highlightMatches(label: string, indices: readonly number[], theme: PromptTheme): string; /** Prefix glyph shown while the prompt is active. */ export declare const PREFIX_SYMBOL = "┃"; /** Prefix glyph shown after the prompt is submitted. */ export declare const PREFIX_SUBMITTED = "✓"; /** Cursor indicator for focused items in list-style prompts. */ export declare const CURSOR_INDICATOR = "›"; /** Indicator shown when more list items can be scrolled into view. */ export declare const SCROLL_INDICATOR = "..."; /** Glyph for a checked checkbox or selected confirm option. */ export declare const CHECKBOX_CHECKED = "●"; /** Glyph for an unchecked checkbox or unselected confirm option. */ export declare const CHECKBOX_UNCHECKED = "○"; /** Render `text` with a cursor at `cursorPos`, or the placeholder when `text` is empty. */ export declare function renderTextWithCursor(text: string, cursorPos: number, theme: PromptTheme, placeholder?: string): string; /** The updated text and cursor position returned by `handleTextEdit`. */ interface TextEditState { readonly text: string; readonly cursorPos: number; } /** * Result of a text-edit operation. * `null` means the key was not a text-editing key and the caller should * handle it (e.g., Enter for submit, arrow-up/down for list navigation). */ type TextEditResult = TextEditState | null; /** * Handle common text-editing keypresses: backspace, delete, left, right, * home, end, and printable character insertion. * * Edits step over whole Unicode code points, so surrogate pairs are never * split; `cursorPos` remains a UTF-16 offset into `text`. * * Returns the updated `{ text, cursorPos }` if the key was handled, * or `null` if the key is not a text-editing key (so the caller can * handle it for prompt-specific logic like submit or list navigation). * * @param key - The keypress event * @param text - Current text content * @param cursorPos - Current cursor position within the text * @returns Updated text/cursor, or `null` if not a text-edit key */ export declare function handleTextEdit(key: KeypressEvent, text: string, cursorPos: number): TextEditResult; /** * Format the submitted line for a prompt. * * Produces `"prefix message value"`, `"prefix value"`, `"prefix message"`, * or just `"prefix"` depending on which parts are present — ensuring clean * spacing with no trailing spaces or `"undefined"`. * * @param prefix - Themed prefix string (e.g., styled "✔") * @param message - Optional themed message string * @param value - Optional themed submitted value string * @returns Formatted submitted line */ export declare function formatSubmitted(prefix: string, message?: string, value?: string): string; /** * Format the prompt header together with inline content. * * When a message is present, the content goes on an indented line below: * ``` * prefix message * content * ``` * * When the message is absent, the content sits on the same line as the prefix: * ``` * prefix content * ``` * * An optional `suffix` (e.g., a default-value hint) is appended to the * header portion before the content line. * * @param prefix - Themed prefix string (e.g., styled "▸") * @param message - Optional themed message string * @param content - The inline content (input value, placeholder, toggles, etc.) * @param suffix - Optional text appended after the header (e.g., default hint) * @returns Formatted prompt line(s) */ export declare function formatPromptLine(prefix: string, message: string | undefined, content: string, suffix?: string): string; /** Render a scrollable list with viewport indicators. */ export declare function renderChoiceList(items: readonly T[], scrollOffset: number, maxVisible: number, renderItem: (item: T, index: number) => string, hint: (text: string) => string): string[]; export { type Choice, type ChoiceValue, type ConfirmOptions, type CreatePromptsOptions, type FilterOptions, type FuzzyFilterResult, type FuzzyMatchResult, type HandleKeyResult, type InputOptions, type KeypressEvent, type MultifilterOptions, type MultiselectOptions, NonInteractiveError, type PartialPromptTheme, type PasswordOptions, type PromptConfig, type PromptTheme, type PromptsInstance, type SelectOptions, type SubmitResult, type TerminalIO, type TerminalInput, type TerminalOutput, type TextEditResult, type TextEditState, type ValidateFn, assertTTY, isTTY, runPrompt, submit, withTerminalIO };