3.0.1 • Published 7 months ago

inquirer-autocomplete-prompt v3.0.1

Weekly downloads
686,223
License
ISC
Repository
github
Last release
7 months ago

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

@serverless/components@telusdigital/shippy-cli@blahblahblueblack/chatgpt-api@instructure/cz-lerna-changelog@architect-io/cli@saasxx/cli-common@harvestr-api/cli@captalys-platform/apollion-clisqldumpgenlicenselicensar@greendjango/blih_cliwaque-plusydd-buildreact-static-juroshcinepolifyvideo_ad_spywte@captalys-platform/cli@mcesystems/mce-sdk-cli@rock-kit/cz-lerna-changeloguhh-ts@kibalabs/react-static@tzero/csm-clitest-algolia20test-algolia22glicensesdumptoolsterminal-db@bidalgo/liquifastqoros-gitmoji-clisy-craftpp-assistortest-dsm-github-harmonizer@cbim/create-cbim-appwrm-troubleshooting-poc@temporg/cz-lerna-changelogdiscord-js-creator@lexialearning/tool-branch-batch-bitbucketlaboris-cliattheme-better-cli@kaviar/terminal-bundlequantconnect-clicreate-myhtmlprojectcreate-myhtmlproject-app@zrf9018/marvel-cli@zrf9018/marvel-mock-serverxzt-cli@ccontour/home-cli@bybit/marvel-cli@bybit/marvel-mock-servernitin-shippy-clicli-shippydidaweb-cli@sheba/cz-conventionsub-tvtoggl-node-cli@infinitebrahmanuniverse/nolb-inqcz-ly-emojicz-gamedevnetlify-cli@everything-registry/sub-chunk-1916repositories_utils@imoka/imoka-clidiirdaycooldecova-gotcharri-cbrdocker-compose-helperdockerizedis-composerdockerizedis-nanodockerizedis-redisdockerizedis-rubydll-clidevdocs-clidevops-promptdevtodevtoclidotnetplicatedoor-clidomapic-controllerdoriadeviceframecz-cactuscz-cccz-ccglscz-coenvencionalcz-commit-emojicz-ah-commitcz-emojicz-emoji-azotcz-emoji-chinesecz-emoji-conventional-changelogcz-emoji-darkdevcz-emoji-habitcz-emoji-japanesecz-configurationcz-vinylcz-gitmoji-customizecz-jira-emoji
2.0.1

7 months ago

3.0.1

7 months ago

3.0.0

2 years ago

2.0.0

2 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.12.2

6 years ago

0.12.1

6 years ago

0.12.0

6 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

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.4.0

7 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago