promptSelect

import { promptSelect } from "jsr:@ende/cli/unstable-prompt-select";

function ยท experimental

function promptSelect<V = undefined>(message: string, values: PromptEntry<V>[], options: PromptSelectOptions = [UNSUPPORTED]): PromptEntry<V> | null

Shows the given message and waits for the user's input. Returns the user's selected value as string.

Also supports filtering of the options by typing.

message: string

The prompt message to show to the user.

values: PromptEntry<V>[]

The values for the prompt.

options: PromptSelectOptions = [UNSUPPORTED]

The options for the prompt.

Returns

The string that was entered or null if stdin is not a TTY.

Example: Basic usage

import { promptSelect } from "@ende/cli/unstable-prompt-select";

const browser = promptSelect("Please select browser", [
  "Chrome",
  "Firefox",
  "Safari",
], { clear: true });

Example: With title and value

import { promptSelect } from "@ende/cli/unstable-prompt-select";

const browsers = promptSelect(
  "Please select browsers:",
  [{
    label: "safari",
    value: 1,
  }, {
    label: "chrome",
    value: 2,
  }, {
    label: "firefox",
    value: 3,
  }],
  { clear: true },
);

Example: With multiple options

import { promptSelect } from "@ende/cli/unstable-prompt-select";

const browser = promptSelect("What country are you from?", [
  "Brazil",
  "United States",
  "Japan",
  "China",
  "Canada",
  "Spain",
], { clear: true, visibleLines: 3, indicator: "*" });

Source