UNPKG

2.89 kBMarkdownView Raw
1# inquirer-autocomplete-prompt
2
3[![Greenkeeper badge](https://badges.greenkeeper.io/mokkabonna/inquirer-autocomplete-prompt.svg)](https://greenkeeper.io/)
4
5Autocomplete prompt for [inquirer](https://github.com/SBoudrias/Inquirer.js)
6
7[![build status](https://secure.travis-ci.org/mokkabonna/inquirer-autocomplete-prompt.svg)](http://travis-ci.org/mokkabonna/inquirer-autocomplete-prompt)
8[![dependency status](https://david-dm.org/mokkabonna/inquirer-autocomplete-prompt.svg)](https://david-dm.org/mokkabonna/inquirer-autocomplete-prompt)
9
10## Installation
11
12```
13npm install --save inquirer-autocomplete-prompt
14```
15
16## Usage
17
18
19This prompt is anonymous, meaning you can register this prompt with the type name you please:
20
21```javascript
22inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
23inquirer.prompt({
24 type: 'autocomplete',
25 ...
26})
27```
28
29Change `autocomplete` to whatever you might prefer.
30
31### Options
32
33> **Note:** _allowed options written inside square brackets (`[]`) are optional. Others are required._
34
35`type`, `name`, `message`, `source`[, `pageSize`, `filter`, `when`, `suggestOnly`, `validate`]
36
37See [inquirer](https://github.com/SBoudrias/Inquirer.js) readme for meaning of all except **source** and **suggestOnly**.
38
39**Source** will be called with previous answers object and the current user input each time the user types, it **must** return a promise.
40
41**Source** will be called once at at first before the user types anything with **null** as the value. If a new search is triggered by user input it maintains the correct order, meaning that if the first call completes after the second starts, the results of the first call are never displayed.
42
43**suggestOnly** is default **false**. Setting it to true turns the input into a normal text input. Meaning that pressing enter selects whatever value you currently have. And pressing tab autocompletes the currently selected value in the list. This way you can accept manual input instead of forcing a selection from the list.
44
45**validate** is only active when **suggestOnly** is set to **true**. It behaves like validate for the input prompt.
46
47
48#### Example
49
50```javascript
51inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
52inquirer.prompt([{
53 type: 'autocomplete',
54 name: 'from',
55 message: 'Select a state to travel from',
56 source: function(answersSoFar, input) {
57 return myApi.searchStates(input);
58 }
59}]).then(function(answers) {
60 //etc
61});
62```
63
64See also [example.js](https://github.com/mokkabonna/inquirer-autocomplete-prompt/blob/master/example.js) for a working example.
65
66I recommend using this package with [fuzzy](https://www.npmjs.com/package/fuzzy) if you want fuzzy search. Again, see the example for a demonstration of this.
67
68![Autocomplete prompt](./inquirer.gif)
69
70## Credits
71[Martin Hansen](https://github.com/mokkabonna/)
72
73## License
74
75ISC