import type { EventEmitter } from 'node:events'; import type { Key } from 'node:readline'; export interface PromptChoice { label: string; value: Value; hint?: string | undefined; } export interface PromptTextOptions { message: string; placeholder?: string; defaultValue?: string; /** Editable text the prompt opens with, for editing a value in place. */ initialValue?: string | undefined; validate?: (value: string | undefined) => string | undefined; } export interface PromptNumberOptions { message: string; /** Editable text the prompt opens with, for editing a value in place. */ initialValue?: number | undefined; validate?: (value: number) => string | undefined; } export interface PromptConfirmOptions { message: string; initialValue?: boolean; active?: string; inactive?: string; } export interface PromptSelectOptions { message: string; choices: Array>; /** The choice to open on, for editing a value in place. */ initialValue?: Value | undefined; } export interface PromptMultiselectOptions { message: string; choices: Array>; /** The choices to open selected, for editing a value in place. */ initialValues?: Value[] | undefined; } /** * The terminal edge behind the prompt functions: whether questions can be * asked, and how to ask each kind. * * A test replaces this with an in-memory client (see * `memory-prompt.ts`) via {@link setPromptClient} — the code under * test keeps calling `promptText` and friends as usual. */ export interface PromptClient { canPrompt: () => boolean; text: (options: PromptTextOptions) => Promise; number: (options: PromptNumberOptions) => Promise; confirm: (options: PromptConfirmOptions) => Promise; select: (options: PromptSelectOptions) => Promise; autocomplete: (options: PromptSelectOptions) => Promise; autocompleteMultiselect: (options: PromptMultiselectOptions) => Promise; } /** * Note on a prompt message that dismissing it returns to the previous step. * * Only for prompts whose caller catches the dismissal: elsewhere it still * stops the CLI, and saying otherwise would mislead. The note goes in the * message because clack renders its own keyboard hints from a hardcoded list * that a caller cannot add to. */ export declare const withBackHint: (message: string) => string; /** * The arrow keypress an Emacs-style control keypress stands for, or * undefined for any other key: ctrl-p is up and ctrl-n is down. */ export declare const arrowKeyFor: (key: Key | undefined) => Key | undefined; /** * Re-emit Emacs-style control keypresses as the arrow keys they stand for. * * Clack navigates on the readline key name, so a synthetic arrow keypress * moves the cursor in every prompt kind. Its own alias table cannot express * this: aliases match bare key names, unaware of ctrl, and are ignored by * prompts that track typed input, such as autocomplete. */ export declare const emitArrowKeyAliases: (input: EventEmitter) => void; /** * A value as the choice a list prompt opens on: the value when the list * offers it, and otherwise nothing. * * A value the list does not offer, such as an id passed as an argument that * is not among the resources fetched, would leave clack holding a selection * with no choice behind it — so the prompt opens on its first choice, the * same as one with no value to start from. */ export declare const offeredValue: (choices: Array>, value: Value | undefined) => Value | undefined; /** Every one of the values a list prompt offers, in the order given. */ export declare const offeredValues: (choices: Array>, values: Value[] | undefined) => Value[]; export declare class TerminalPromptClient implements PromptClient { /** * Prompts read raw keypresses and render an interface, so they need a * terminal on both ends: when stdin is a pipe or a file it holds request * params, not answers, and when stderr is redirected nobody sees the * question. */ canPrompt: () => boolean; text: (options: PromptTextOptions) => Promise; number: (options: PromptNumberOptions) => Promise; confirm: (options: PromptConfirmOptions) => Promise; select: (options: PromptSelectOptions) => Promise; autocomplete: (options: PromptSelectOptions) => Promise; autocompleteMultiselect: (options: PromptMultiselectOptions) => Promise; } export declare const setPromptClient: (promptClient: PromptClient) => void; export declare const resetPromptClient: () => void; /** Whether the CLI can ask the user a question. */ export declare const canPrompt: () => boolean; export declare const promptText: (options: PromptTextOptions) => Promise; export declare const promptNumber: (options: PromptNumberOptions) => Promise; export declare const promptConfirm: (options: PromptConfirmOptions) => Promise; export declare const promptSelect: (options: PromptSelectOptions) => Promise; export declare const promptAutocomplete: (options: PromptSelectOptions) => Promise; export declare const promptAutocompleteMultiselect: (options: PromptMultiselectOptions) => Promise; export interface SearchableChoice { label?: string | undefined; hint?: string | undefined; } /** * Match a choice by every whitespace separated term of the input, matched * case insensitively against the label and the hint. */ export declare const searchChoices: (input: string, choice: SearchableChoice) => boolean;