Skip to main content
Module

x/cliffy/prompt/checkbox.ts>Checkbox

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Latest
import { Checkbox } from "https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/checkbox.ts";

Checkbox prompt representation.

Simple prompt:

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

const colors: Array<string> = await Checkbox.prompt({
  message: "Pick some colors",
  options: ["red", "green", "blue"],
});

Mixed option types:

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

const values: Array<string | number> = await Checkbox.prompt<string | number>({
  message: "Pick some colors",
  options: [1, 2, "3", "4"],
});

None primitive option types:

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

const dates: Array<Date> = await Checkbox.prompt({
  message: "Pick some dates",
  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 { Checkbox } from "./mod.ts";

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

Constructors

new
Checkbox(options: CheckboxOptions<TValue>)

Properties

private
confirmSubmit: boolean
protected
listIndex: number
protected
listOffset: number
protected
readonly
settings: CheckboxSettings<TValue>

Methods

protected
checkValue(): void

Check selected option.

protected
format(value: Array<TValue>): string

Format output value.

protected
getValue(): Array<TValue>

Get value of checked options.

protected
handleEvent(event: KeyCode): Promise<void>

Handle user input event.

protected
hint(): string | undefined
protected
mapOptions(promptOptions: CheckboxOptions<TValue>, options: Array<
| Extract<TValue, string | number>
| Extract<WidenType<TValue>, string | number>
>
): Array<CheckboxOptionSettings<TValue> | CheckboxOptionGroupSettings<TValue>>

Map string option values to options and set option defaults.

protected
match(): void
protected
submit(hasConfirmed?: boolean): Promise<void>
protected
transform(value: Array<TValue>): Array<TValue>

Map input value to output value.

protected
validate(value: Array<TValue>): boolean | string

Validate input value.

getDefaultSettings(options: CheckboxOptions<TValue>): CheckboxSettings<TValue>

Static Methods

inject<TValue>(value: Array<TValue>): 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: CheckboxOptions<TValue>): Promise<Array<WidenType<TValue>>>

Execute the prompt with provided options.