Back to Enquirer

Array Prompt

support/src/content/types/array.md

2.4.02.2 KB
Original Source

Array Prompt

The ArrayPrompt class is used for creating prompts that display an array of choices in the terminal, and return one more more value.

Keypresses

Array prompts support the following keypress combinations.

KeypressActionDescription
<kbd>shift</kbd>+<kbd></kbd>shiftUpundefined
<kbd>shift</kbd>+<kbd></kbd>shiftDownundefined
<kbd>fn</kbd>+<kbd></kbd> (mac) or <kbd>Page Up</kbd> (win)pageUpundefined
<kbd>fn</kbd>+<kbd></kbd> (mac) or <kbd>Page Down</kbd> (win)pageDownundefined

Options

Array prompts take the following options.

NameTypeDefaultDescription
limitNumberoptions.choices.lengthThe number of choices to make visible in the terminal. Users can scroll up and down to reveal more choices when the entire list is not shown.
initial`NumberStringArray`
hintStringundefinedtodo
nameStringundefinedtodo
typeStringundefinedtodo
messsageStringundefinedtodo
choicesArrayundefinedtodo

Options Examples

options.limit

Type: number

Default: Defaults to choices.length

Description: The number of choices to make visible ("on screen") in the terminal. Users can scroll up and down to reveal more choices when the entire list is not shown.

The following prompt would only render three choices in the terminal at any given time.

js
const prompt = new Prompt({
  name: 'alphabet',
  message: 'Choose some letters',
  choices: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
  limit: 3
});

array-option-limit.gif

Instance properties

  • prompt.choices - Normalized array of choices created from options.choices.
  • prompt.list - Visible list of choices, if options.limit is defined, or the entire choices array.
  • prompt.cursor - the position of the cursor in the visible prompt.list array
  • [prompt-autocompletion][]
  • [prompt-select][]
  • [prompt-multiselect][]
  • [prompt-checkbox][]
  • [prompt-radio][]