1. inquirer-list-search-prompt
Autocomplete prompt for inquirer
inquirer-list-search-prompt
Package: inquirer-list-search-prompt
Created by: mamoruuu
Last modified: Thu, 05 May 2022 23:19:58 GMT
Version: 1.0.2
License: ISC
Downloads: 3,574
Repository: https://github.com/mamoruuu/inquirer-autocomplete-prompt

Install

npm install inquirer-list-search-prompt
yarn add inquirer-list-search-prompt

inquirer-list-search-prompt

This is the fork of the mokkabonna's inquirer-autocomplete-prompt plugin.

This package fixes the issue with an empty string answer.

Greenkeeper badge

Autocomplete prompt for inquirer

build status
dependency status

Installation

npm install --save inquirer-autocomplete-prompt

Usage

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

 inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
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[, pageSize, filter, when, suggestOnly, validate]

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

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 only active when suggestOnly is set to true. It behaves like validate for the input prompt.

Example

 inquirer.registerPrompt(
  'autocomplete',
  require('inquirer-autocomplete-prompt')
);
inquirer
  .prompt([
    {
      type: 'autocomplete',
      name: 'from',
      message: 'Select a state to travel from',
      source: function(answersSoFar, input) {
        return myApi.searchStates(input);
      },
    },
  ])
  .then(function(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 - the original creator

Alexander Bolotskov

License

ISC

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code