inquirer-autocomplete-prompt
Autocomplete prompt for inquirer
Last updated 4 years ago by mokkabonna .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install inquirer-autocomplete-prompt 
SYNC missed versions from official npm registry.

inquirer-autocomplete-prompt

Autocomplete prompt for inquirer

build status

Installation

npm install inquirer-autocomplete-prompt

Usage

This prompt is anonymous, meaning you can register this prompt with the type name you please:

const inquirer = require('inquirer');
const inquirerPrompt = require('inquirer-autocomplete-prompt');

inquirer.registerPrompt('autocomplete', inquirerPrompt);
inquirer.prompt({
  type: 'autocomplete',
  ...
})

Change autocomplete to whatever you might prefer.

Options

Note: allowed options written inside square brackets ([]) are optional. Others are required.

type, name, message, source[, default, validate, filter, when, pageSize, prefix, suffix, askAnswered, loop, suggestOnly, searchText, emptyText]

See inquirer readme for meaning of all except source, suggestOnly, searchText and emptyText.

source will be called with previous answers object and the current user input each time the user types, it must return a promise.

source will be called once at at first before the user types anything with undefined 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.

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.

validate is called with the entered text when suggestOnly is set to true. When suggestOnly is false, validate is called with the choice object. In addition it is called with the answers object so far.

searchText Is the text shown when searching. Defaults: Searching...

emptyText Is the text shown if the search returns no results. Defaults: No results...

Example

const inquirer = require('inquirer');
const inquirerPrompt = require('inquirer-autocomplete-prompt');

inquirer.registerPrompt('autocomplete', inquirerPrompt);
inquirer
  .prompt([
    {
      type: 'autocomplete',
      name: 'from',
      message: 'Select a state to travel from',
      source: (answersSoFar, input) => myApi.searchStates(input),
    },
  ])
  .then((answers) => {
    // etc
  });

See also example.js for a working example.

I recommend using this package with fuzzy if you want fuzzy search. Again, see the example for a demonstration of this.

Autocomplete prompt

Credits

Martin Hansen

License

ISC

Current Tags

  • 3.0.1                                ...           latest (a year ago)

28 Versions

  • 0.1.2                                ...           9 years ago
  • 0.1.1                                ...           9 years ago
  • 0.1.0                                ...           9 years ago
  • 2.0.1                                ...           a year ago
  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 1.3.0                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.12.2                                ...           7 years ago
  • 0.12.1                                ...           7 years ago
  • 0.12.0                                ...           7 years ago
  • 0.11.1                                ...           7 years ago
  • 0.11.0                                ...           7 years ago
  • 0.10.0                                ...           7 years ago
  • 0.9.0                                ...           7 years ago
  • 0.8.0                                ...           8 years ago
  • 0.7.0                                ...           8 years ago
  • 0.6.0                                ...           8 years ago
  • 0.4.0                                ...           8 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.3                                ...           9 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (12)

© 2010 - cnpmjs.org x YWFE | Home | YWFE