1.0.0 • Published 9 years ago

inquirer-dynamic-list v1.0.0

Weekly downloads
9
License
MIT
Repository
github
Last release
9 years ago

inquirer-dynamic-list

npm version dependencies Build Status Build status

A subclass of inquirer's list whose choices can be updated on the fly.

Notice this is a proof of concept and breaks inquirer's encapsulation.

Installation

Install inquirer-dynamic-list by running:

$ npm install --save inquirer-dynamic-list

Documentation

dynamiclist~DynamicList

Kind: inner class of dynamiclist
Summary: Dynamic list widget
Access: public

new DynamicList(options)

ParamTypeDefaultDescription
optionsObjectoptions
options.choicesArray.<Object>initial choices
options.messageStringwidget message
options.emptyMessageString'No options'message for when no choices

Example

list = new DynamicList
	message: 'Foo'
	emptyMessage: 'Nothing to show'
	choices: [
		name: 'Foo'
		value: 'foo'
	]

# Run the list widget
list.run().then (answer) ->
	console.log(answer)

# You can add new choices on the fly
list.addChoice
	name: 'Bar'
	value: 'bar'

# We re-render to be able to see the new options
list.render()

dynamicList.render()

Kind: instance method of DynamicList
Summary: Render the list
Access: public
Example

list = new DynamicList
	message: 'Foo'
	emptyMessage: 'Nothing to show'
	choices: [
		name: 'Foo'
		value: 'foo'
	]

list.render()

dynamicList.addChoice(choice)

Kind: instance method of DynamicList
Summary: Add a choice
Access: public

ParamTypeDescription
choiceObjectchoice

Example

list = new DynamicList
	message: 'Foo'
	emptyMessage: 'Nothing to show'
	choices: [
		name: 'Foo'
		value: 'foo'
	]

list.addChoice(name: 'Bar', value: 'bar')
list.render()

dynamicList.removeChoice(choice)

Kind: instance method of DynamicList
Summary: Remove a choice
Access: public

ParamTypeDescription
choiceObjectchoice

Example

list = new DynamicList
	message: 'Foo'
	emptyMessage: 'Nothing to show'
	choices: [
		name: 'Foo'
		value: 'foo'
	]

list.removeChoice(name: 'Foo', value: 'foo')
list.render()

dynamicList.run() ⇒ Promise

Kind: instance method of DynamicList
Summary: Run the widget
Access: public
Fulfil: String answer
Example

list = new DynamicList
	message: 'Foo'
	emptyMessage: 'Nothing to show'
	choices: [
		name: 'Foo'
		value: 'foo'
	]

list.run().then (answer) ->
	console.log(answer)

Support

If you're having any problem, please raise an issue on GitHub and I'll be happy to help.

Tests

Run the test suite by doing:

$ gulp test

Contribute

Before submitting a PR, try to include tests, and make sure that coffeelint runs without any warning:

$ gulp lint

License

The project is licensed under the MIT license.