- Ask the user to select items from a list
radio
option to allow only one selected item- default selected items
const sh = require('kool-shell')
sh.select('What do you want for dinner ?', [
'A double cheese',
{ value: 'An omelette du fromage', selected: true }
'Some vegetables'
])
.then(result => {
if (result.length > 1) console.log('Are you sure to eat all of this?')
})
Ask label
to the user.
Display a list of items
. With the keyboard, the user needs to choose item in this list.
Return a promise that will be resolved when the user submit his selection by typing the Enter key. The resolved value is an array of the selected items.
label
(String): A statement or query to write to the console, prepended to the list.items
(Array): List of item the user choose from.- an item can be a simple string
- you can also make an object with these parameters:
value
(String): the display value of this itemselected
(Boolean, default false): if true the item will be selected by defaultonChosen
(Function) A function that will be called when the user has submit his selection. It's like theonSubmit
option but for individual choice. It can be a promise for asynchronous actions like anothersh.select
input.
options
(Object)radio
(Boolean, default false): Allow only one selected item, like the<radio>
input in HTMLinstructions
(String) Change the instruction of the input (useful if you don't want the message in English)checked
(String) The checked symbol added before a checked itemunchecked
(String) The unchecked symbol added before an unchecked itemonSubmit
: (Function): A function that will be called when the user has answered. You can return a simple value or a promise if you want to do asynchronous actions. The input will resolve with the return value from the onSubmit function. If you reject your onSubmit promise,sh.select
will be rejected as well. TheonSubmit
option can be useful to avoid too much nested promises or to process the user answer before resolvingsh.select
.