0.3.2 • Published 4 years ago

multiselect-prompt v0.3.2

Weekly downloads
192
License
ISC
Repository
github
Last release
4 years ago

multiselect-prompt

Deprecated. Use the MultiSelect prompt from enquirer.


A prompt to select zero or more items.

asciicast

npm version dependency status dev dependency status ISC-licensed chat on gitter

multiselect-prompt uses cli-styles and prompt-skeleton to have a look & feel consistent with other prompts.

Installing

npm install multiselect-prompt

Usage

const prompt = require('multiselect-prompt')

const colors = [
	{title: 'red',    value: '#f00'},
	{title: 'yellow', value: '#ff0'},
	{title: 'green',  value: '#0f0'},
	{title: 'blue',   value: '#00f', selected: true},
	{title: 'black',  value: '#000'},
	{title: 'white',  value: '#fff'}
]

const selected = (items) => items
	.filter((item) => item.selected)
	.map((item) => item.value)

// All these options are optional
const opts = {
	cursor: 1,     // Initial position of the cursor, defaults to 0 (first entry)
	maxChoices: 3, // Maximum number of selectable options (defaults to Infinity)
	// The message to display as hint if enabled, below is the default value
	hint: '– Space to select. Return to submit.'
}

prompt('Which colors do you like?', colors, opts)
.on('data', (data) => console.log('Changed to', selected(data.value)))
.on('abort', (items) => console.log('Aborted with', selected(items)))
.on('submit', (items) => console.log('Submitted with', selected(items)))

Related

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.