Skip to main content
Module

x/cliffy/prompt/mod.ts>Select

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Latest
class Select
extends GenericList<TValue, TValue, TValue, SelectOptionSettings<TValue>, SelectOptionGroupSettings<TValue>>
import { Select } from "https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/mod.ts";

Select prompt representation.

Simple prompt:

import { Select } from "./mod.ts";

const color: string = await Select.prompt({
  message: "Pick a color",
  options: ["red", "green", "blue"],
});

Mixed option types:

import { Select } from "./mod.ts";

const value: string | number = await Select.prompt<string | number>({
  message: "Pick a color",
  options: [1, 2, "3", "4"],
});

None primitive option types:

import { Select } from "./mod.ts";

const date: Date = await Select.prompt({
  message: "Pick a date",
  options: [
    {
      name: "Date 1",
      value: new Date(100000),
    },
    {
      name: "Date 2",
      value: new Date(200000),
    },
    {
      name: "Date 3",
      value: new Date(300000),
    },
  ],
});

Grouped options:

import { Select } from "./mod.ts";

const value = await Select.prompt({
  message: "Select a value",
  options: [{
    name: "Group 1",
    options: ["foo", "bar", "baz"],
  }, {
    name: "Group 2",
    options: ["beep", "boop"],
  }],
});

Constructors

new
Select(options: SelectOptions<TValue>)

Properties

protected
listIndex: number
protected
listOffset: number
protected
options: Array<SelectOptionSettings<TValue> | SelectOptionGroupSettings<TValue>>
protected
readonly
settings: SelectSettings<TValue>

Methods

protected
format(value: TValue): string

Format output value.

protected
getValue(): TValue

Get value of selected option.

protected
input(): string
protected
mapOptions(promptOptions: SelectOptions<TValue>, options: Array<
| Extract<TValue, string | number>
| Extract<WidenType<TValue>, string | number>
| GenericListSeparatorOption
>
): Array<SelectOptionSettings<TValue> | SelectOptionGroupSettings<TValue>>

Map string option values to options and set option defaults.

protected
submit(): Promise<void>
protected
transform(value: TValue): TValue

Map input value to output value.

protected
validate(value: TValue): boolean | string

Validate input value.

getDefaultSettings(options: SelectOptions<TValue>): SelectSettings<TValue>

Static Methods

inject(value: string): void

Inject prompt value. If called, the prompt doesn't prompt for an input and returns immediately the injected value. Can be used for unit tests or pre selections.

prompt<TValue>(options: SelectOptions<TValue>): Promise<WidenType<TValue>>

Execute the prompt with provided options.