support/src/content/types/array.md
The ArrayPrompt class is used for creating prompts that display an array of choices in the terminal, and return one more more value.
Array prompts support the following keypress combinations.
| Keypress | Action | Description |
|---|---|---|
| <kbd>shift</kbd>+<kbd>▲</kbd> | shiftUp | undefined |
| <kbd>shift</kbd>+<kbd>▼</kbd> | shiftDown | undefined |
| <kbd>fn</kbd>+<kbd>▲</kbd> (mac) or <kbd>Page Up</kbd> (win) | pageUp | undefined |
| <kbd>fn</kbd>+<kbd>▼</kbd> (mac) or <kbd>Page Down</kbd> (win) | pageDown | undefined |
Array prompts take the following options.
| Name | Type | Default | Description |
|---|---|---|---|
limit | Number | options.choices.length | The 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 | `Number | String | Array` |
hint | String | undefined | todo |
name | String | undefined | todo |
type | String | undefined | todo |
messsage | String | undefined | todo |
choices | Array | undefined | todo |
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.
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
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