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.
Install inquirer-dynamic-list
by running:
$ npm install --save inquirer-dynamic-list
Kind: inner class of dynamiclist
Summary: Dynamic list widget
Access: public
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options | |
options.choices | Array.<Object> |
initial choices | |
options.message | String |
widget message | |
[options.emptyMessage] | String |
'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()
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()
Kind: instance method of DynamicList
Summary: Add a choice
Access: public
Param | Type | Description |
---|---|---|
choice | Object |
choice |
Example
list = new DynamicList
message: 'Foo'
emptyMessage: 'Nothing to show'
choices: [
name: 'Foo'
value: 'foo'
]
list.addChoice(name: 'Bar', value: 'bar')
list.render()
Kind: instance method of DynamicList
Summary: Remove a choice
Access: public
Param | Type | Description |
---|---|---|
choice | Object |
choice |
Example
list = new DynamicList
message: 'Foo'
emptyMessage: 'Nothing to show'
choices: [
name: 'Foo'
value: 'foo'
]
list.removeChoice(name: 'Foo', value: 'foo')
list.render()
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)
If you're having any problem, please raise an issue on GitHub and I'll be happy to help.
Run the test suite by doing:
$ gulp test
- Issue Tracker: github.com/mkorakakis/inquirer-dynamic-list/issues
- Source Code: github.com/mkorakakis/inquirer-dynamic-list
Before submitting a PR, try to include tests, and make sure that coffeelint runs without any warning:
$ gulp lint
The project is licensed under the MIT license.