Skip to content

Prompt

23 exports Added in v1.0.0 Source

Collecting & Elements

all

Added in v1.0.0 Source

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

Supports either a tuple / iterable of prompts or a record / struct of prompts as an argument.

Signature

declare const all: <Arg extends Iterable<Prompt<any>> | Record<string, Prompt<any>>>(
  arg: Arg,
) => All.Return<Arg>;

Example

import * as Prompt from "@effect/cli/Prompt"
import * as Effect from "effect/Effect"

const username = Prompt.text({
  message: "Enter your username: ",
})

const password = Prompt.password({
  message: "Enter your password: ",
  validate: (value) =>
    value.length === 0 ? Effect.fail("Password cannot be empty") : Effect.succeed(value),
})

const allWithTuple = Prompt.all([username, password])

const allWithRecord = Prompt.all({ username, password })

Combinators

flatMap

Added in v1.0.0 Source

Signature

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>;
};

map

Added in v1.0.0 Source

Signature

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>;
};

Constructors

confirm

Added in v1.0.0 Source

Signature

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

custom

Added in v1.0.0 Source

Creates a custom Prompt from the specified initial state and handlers.

The initial state can either be a pure value or an Effect. This is particularly useful when the initial state of the Prompt must be computed by performing some effectful computation, such as reading data from the file system.

A Prompt is essentially a render loop where user input triggers a new frame to be rendered to the Terminal. The handlers of a custom prompt are used to control what is rendered to the Terminal each frame. During each frame, the following occurs:

1. The render handler is called with this frame's prompt state and prompt action and returns an ANSI escape string to be rendered to the Terminal 2. The Terminal obtains input from the user 3. The process handler is called with the input obtained from the user and this frame's prompt state and returns the next prompt action that should be performed 4. The clear handler is called with this frame's prompt state and prompt action and returns an ANSI escape string used to clear the screen of the Terminal

Signature

declare const custom: <State, Output>(
  initialState: State | Effect<State, never, Prompt.Environment>,
  handlers: Prompt.Handlers<State, Output>,
) => Prompt<Output>;

date

Added in v1.0.0 Source

Signature

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

file

Added in v1.0.0 Source

Signature

declare const file: (options?: Prompt.FileOptions) => Prompt<string>;

float

Added in v1.0.0 Source

Signature

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

hidden

Added in v1.0.0 Source

Signature

declare const hidden: (options: Prompt.TextOptions) => Prompt<Redacted>;

integer

Added in v1.0.0 Source

Signature

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

list

Added in v1.0.0 Source

Signature

declare const list: (options: Prompt.ListOptions) => Prompt<Array<string>>;

multiSelect

Added in v1.0.0 Source

Signature

declare const multiSelect: <A>(
  options: Prompt.SelectOptions<A> & Prompt.MultiSelectOptions,
) => Prompt<Array<A>>;

password

Added in v1.0.0 Source

Signature

declare const password: (options: Prompt.TextOptions) => Prompt<Redacted>;

select

Added in v1.0.0 Source

Signature

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

succeed

Added in v1.0.0 Source

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

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

text

Added in v1.0.0 Source

Signature

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

toggle

Added in v1.0.0 Source

Signature

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

Execution

run

Added in v1.0.0 Source

Executes the specified Prompt.

Signature

declare const run: <Output>(
  self: Prompt<Output>,
) => Effect<Output, QuitException, Prompt.Environment>;

Models

Prompt interface

Added in v1.0.0 Source

Signature

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

Other

All

Added in v1.0.0 Source

Prompt

Added in v1.0.0 Source

Symbols

PromptTypeId

Added in v1.0.0 Source

Signature

declare const PromptTypeId: unique symbol;

PromptTypeId type

Added in v1.0.0 Source

Signature

type PromptTypeId = typeof PromptTypeId;