Skip to main content Link Search Menu Expand Document (external link)

Prompt overview

Added in v1.0.0


Table of contents


collecting & elements

all

Runs all the provided prompts in sequence respecting the structure provided in input.

Supports multiple arguments, a single argument tuple / array or record / struct.

Signature

export declare const all: <const Arg extends Iterable<Prompt<any>>>(arg: Arg) => All.Return<Arg>

Added in v1.0.0

combinators

flatMap

Signature

export declare const flatMap: {
  <Output, Output2>(f: (output: Output) => Prompt<Output2>): (self: Prompt<Output>) => Prompt<Output2>
  <Output, Output2>(self: Prompt<Output>, f: (output: Output) => Prompt<Output2>): Prompt<Output2>
}

Added in v1.0.0

map

Signature

export declare const map: {
  <Output, Output2>(f: (output: Output) => Output2): (self: Prompt<Output>) => Prompt<Output2>
  <Output, Output2>(self: Prompt<Output>, f: (output: Output) => Output2): Prompt<Output2>
}

Added in v1.0.0

constructors

confirm

Signature

export declare const confirm: (options: Prompt.ConfirmOptions) => Prompt<boolean>

Added in v1.0.0

custom

Creates a custom Prompt from the provided render and process functions with the specified initial state.

The render function will be used to render the terminal prompt to a user and is invoked at the beginning of each terminal render frame. The process function is invoked immediately after a user presses a key.

Signature

export declare const custom: <State, Output>(
  initialState: State,
  render: (
    prevState: Option<State>,
    nextState: State,
    action: Prompt.Action<State, Output>
  ) => Effect<Terminal, never, string>,
  process: (input: UserInput, state: State) => Effect<Terminal, never, Prompt.Action<State, Output>>
) => Prompt<Output>

Added in v1.0.0

date

Signature

export declare const date: (options: Prompt.DateOptions) => Prompt<Date>

Added in v1.0.0

float

Signature

export declare const float: (options: Prompt.FloatOptions) => Prompt<number>

Added in v1.0.0

hidden

Signature

export declare const hidden: (options: Prompt.TextOptions) => Prompt<Secret>

Added in v1.0.0

integer

Signature

export declare const integer: (options: Prompt.IntegerOptions) => Prompt<number>

Added in v1.0.0

list

Signature

export declare const list: (options: Prompt.ListOptions) => Prompt<ReadonlyArray<string>>

Added in v1.0.0

password

Signature

export declare const password: (options: Prompt.TextOptions) => Prompt<Secret>

Added in v1.0.0

select

Signature

export declare const select: <A>(options: Prompt.SelectOptions<A>) => Prompt<A>

Added in v1.0.0

succeed

Creates a Prompt which immediately succeeds with the specified value.

NOTE: This method will not attempt to obtain user input or render anything to the screen.

Signature

export declare const succeed: <A>(value: A) => Prompt<A>

Added in v1.0.0

text

Signature

export declare const text: (options: Prompt.TextOptions) => Prompt<string>

Added in v1.0.0

toggle

Signature

export declare const toggle: (options: Prompt.ToggleOptions) => Prompt<boolean>

Added in v1.0.0

execution

run

Executes the specified Prompt.

Signature

export declare const run: <Output>(self: Prompt<Output>) => Effect<Terminal, QuitException, Output>

Added in v1.0.0

models

Prompt (interface)

Signature

export interface Prompt<Output> extends Prompt.Variance<Output>, Pipeable, Effect<Terminal, QuitException, Output> {}

Added in v1.0.0

symbols

PromptTypeId

Signature

export declare const PromptTypeId: typeof PromptTypeId

Added in v1.0.0

PromptTypeId (type alias)

Signature

export type PromptTypeId = typeof PromptTypeId

Added in v1.0.0

utils

All (namespace)

Added in v1.0.0

PromptAny (type alias)

Signature

export type PromptAny = Prompt<any>

Added in v1.0.0

Return (type alias)

Signature

export type Return<Arg extends Iterable<PromptAny>> = [Arg] extends [ReadonlyArray<PromptAny>]
  ? ReturnTuple<Arg>
  : [Arg] extends [Iterable<PromptAny>]
    ? ReturnIterable<Arg>
    : never

Added in v1.0.0

ReturnIterable (type alias)

Signature

export type ReturnIterable<T extends Iterable<PromptAny>> = [T] extends [Iterable<Prompt.Variance<infer A>>]
  ? Prompt<Array<A>>
  : never

Added in v1.0.0

ReturnTuple (type alias)

Signature

export type ReturnTuple<T extends ReadonlyArray<unknown>> = Prompt<
  T[number] extends never ? [] : { -readonly [K in keyof T]: [T[K]] extends [Prompt.Variance<infer _A>] ? _A : never }
> extends infer X
  ? X
  : never

Added in v1.0.0

Prompt (namespace)

Added in v1.0.0

ConfirmOptions (interface)

Signature

export interface ConfirmOptions {
  /**
   * The message to display in the prompt.
   */
  readonly message: string
  /**
   * The intitial value of the confirm prompt (defaults to `false`).
   */
  readonly initial?: boolean
  /**
   * The label to display after a user has responded to the prompt.
   */
  readonly label?: {
    /**
     * The label used if the prompt is confirmed (defaults to `"yes"`).
     */
    readonly confirm: string
    /**
     * The label used if the prompt is not confirmed (defaults to `"no"`).
     */
    readonly deny: string
  }
  /**
   * The placeholder to display when a user is responding to the prompt.
   */
  readonly placeholder?: {
    /**
     * The placeholder to use if the `initial` value of the prompt is `true`
     * (defaults to `"(Y/n)"`).
     */
    readonly defaultConfirm?: string
    /**
     * The placeholder to use if the `initial` value of the prompt is `false`
     * (defaults to `"(y/N)"`).
     */
    readonly defaultDeny?: string
  }
}

Added in v1.0.0

DateOptions (interface)

Signature

export interface DateOptions {
  /**
   * The message to display in the prompt.
   */
  readonly message: string
  /**
   * The initial date value to display in the prompt (defaults to the current
   * date).
   */
  readonly initial?: globalThis.Date
  /**
   * The format mask of the date (defaults to `YYYY-MM-DD HH:mm:ss`).
   */
  readonly dateMask?: string
  /**
   * An effectful function that can be used to validate the value entered into
   * the prompt before final submission.
   */
  readonly validate?: (value: globalThis.Date) => Effect<never, string, globalThis.Date>
  /**
   * Custom locales that can be used in place of the defaults.
   */
  readonly locales?: {
    /**
     * The full names of each month of the year.
     */
    readonly months: [string, string, string, string, string, string, string, string, string, string, string, string]
    /**
     * The short names of each month of the year.
     */
    readonly monthsShort: [
      string,
      string,
      string,
      string,
      string,
      string,
      string,
      string,
      string,
      string,
      string,
      string
    ]
    /**
     * The full names of each day of the week.
     */
    readonly weekdays: [string, string, string, string, string, string, string]
    /**
     * The short names of each day of the week.
     */
    readonly weekdaysShort: [string, string, string, string, string, string, string]
  }
}

Added in v1.0.0

FloatOptions (interface)

Signature

export interface FloatOptions extends IntegerOptions {
  /**
   * The precision to use for the floating point value (defaults to `2`).
   */
  readonly precision?: number
}

Added in v1.0.0

IntegerOptions (interface)

Signature

export interface IntegerOptions {
  /**
   * The message to display in the prompt.
   */
  readonly message: string
  /**
   * The minimum value that can be entered by the user (defaults to `-Infinity`).
   */
  readonly min?: number
  /**
   * The maximum value that can be entered by the user (defaults to `Infinity`).
   */
  readonly max?: number
  /**
   * The value that will be used to increment the prompt value when using the
   * up arrow key (defaults to `1`).
   */
  readonly incrementBy?: number
  /**
   * The value that will be used to decrement the prompt value when using the
   * down arrow key (defaults to `1`).
   */
  readonly decrementBy?: number
  /**
   * An effectful function that can be used to validate the value entered into
   * the prompt before final submission.
   */
  readonly validate?: (value: number) => Effect<never, string, number>
}

Added in v1.0.0

ListOptions (interface)

Signature

export interface ListOptions extends TextOptions {
  /**
   * The delimiter that separates list entries.
   */
  readonly delimiter?: string
}

Added in v1.0.0

SelectChoice (interface)

Signature

export interface SelectChoice<A> {
  /**
   * The name of the select option that is displayed to the user.
   */
  readonly title: string
  /**
   * The underlying value of the select option.
   */
  readonly value: A
  /**
   * An optional description for the select option which will be displayed
   * to the user.
   */
  readonly description?: string
  /**
   * Whether or not this select option is disabled.
   */
  readonly disabled?: boolean
}

Added in v1.0.0

SelectOptions (interface)

Signature

export interface SelectOptions<A> {
  /**
   * The message to display in the prompt.
   */
  readonly message: string
  /**
   * The choices to display to the user.
   */
  readonly choices: ReadonlyArray<SelectChoice<A>>
  /**
   * The number of choices to display at one time (defaults to `10`).
   */
  readonly maxPerPage?: number
}

Added in v1.0.0

TextOptions (interface)

Signature

export interface TextOptions {
  /**
   * The message to display in the prompt.
   */
  readonly message: string
  /**
   * The default value of the text option.
   */
  readonly default?: string
  /**
   * An effectful function that can be used to validate the value entered into
   * the prompt before final submission.
   */
  readonly validate?: (value: string) => Effect<never, string, string>
}

Added in v1.0.0

ToggleOptions (interface)

Signature

export interface ToggleOptions {
  /**
   * The message to display in the prompt.
   */
  readonly message: string
  /**
   * The intitial value of the toggle prompt (defaults to `false`).
   */
  readonly initial?: boolean
  /**
   * The text to display when the toggle is in the active state (defaults to
   * `on`).
   */
  readonly active?: string
  /**
   * The text to display when the toggle is in the inactive state (defaults to
   * `off`).
   */
  readonly inactive?: string
}

Added in v1.0.0

Variance (interface)

Signature

export interface Variance<Output> {
  readonly [PromptTypeId]: Prompt.VarianceStruct<Output>
}

Added in v1.0.0

VarianceStruct (interface)

Signature

export interface VarianceStruct<Output> {
  readonly _Output: (_: never) => Output
}

Added in v1.0.0

Action (type alias)

Signature

export type Action<State, Output> = PromptAction<State, Output>

Added in v1.0.0