Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Prompt

23 exports Since v1.0.0 Source

Collecting & Elements

Since v1.0.0

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

Since v1.0.0

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>;
}
Since v1.0.0

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

Since v1.0.0

Signature

declare const confirm: (options: Prompt.ConfirmOptions) => Prompt<boolean>
Since v1.0.0

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>
Since v1.0.0

Signature

declare const date: (options: Prompt.DateOptions) => Prompt<Date>
Since v1.0.0

Signature

declare const file: (options?: Prompt.FileOptions) => Prompt<string>
Since v1.0.0

Signature

declare const float: (options: Prompt.FloatOptions) => Prompt<number>
Since v1.0.0

Signature

declare const hidden: (options: Prompt.TextOptions) => Prompt<Redacted>
Since v1.0.0

Signature

declare const integer: (options: Prompt.IntegerOptions) => Prompt<number>
Since v1.0.0

Signature

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

Signature

declare const multiSelect: <A>(options: Prompt.SelectOptions<A> & Prompt.MultiSelectOptions) => Prompt<Array<A>>
Since v1.0.0

Signature

declare const password: (options: Prompt.TextOptions) => Prompt<Redacted>
Since v1.0.0

Signature

declare const select: <A>(options: Prompt.SelectOptions<A>) => Prompt<A>
Since v1.0.0

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>
Since v1.0.0

Signature

declare const text: (options: Prompt.TextOptions) => Prompt<string>
Since v1.0.0

Signature

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

Execution

Since v1.0.0

Executes the specified Prompt.

Signature

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

Models

Prompt

interface
Since v1.0.0

Signature

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

Other

Since v1.0.0
Since v1.0.0

Symbols

Signature

declare const PromptTypeId: unique symbol
Since v1.0.0

Signature

type PromptTypeId = typeof PromptTypeId