Prompt
Collecting & Elements
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
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>;
};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
Signature
declare const confirm: (options: Prompt.ConfirmOptions) => Prompt<boolean>;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>;Signature
declare const date: (options: Prompt.DateOptions) => Prompt<Date>;Signature
declare const file: (options?: Prompt.FileOptions) => Prompt<string>;Signature
declare const float: (options: Prompt.FloatOptions) => Prompt<number>;Signature
declare const integer: (options: Prompt.IntegerOptions) => Prompt<number>;Signature
declare const list: (options: Prompt.ListOptions) => Prompt<Array<string>>;multiSelect
Signature
declare const multiSelect: <A>(
options: Prompt.SelectOptions<A> & Prompt.MultiSelectOptions,
) => Prompt<Array<A>>;Signature
declare const password: (options: Prompt.TextOptions) => Prompt<Redacted>;Signature
declare const select: <A>(options: Prompt.SelectOptions<A>) => Prompt<A>;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>;Signature
declare const text: (options: Prompt.TextOptions) => Prompt<string>;Signature
declare const toggle: (options: Prompt.ToggleOptions) => Prompt<boolean>;Execution
Models
Other
Symbols
PromptTypeId
Signature
declare const PromptTypeId: unique symbol;PromptTypeId type
Signature
type PromptTypeId = typeof PromptTypeId;
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.