3.0.0 • Published 2 months ago

inquirer-autocomplete-prompt v3.0.0

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

inquirer-autocomplete-prompt

Autocomplete prompt for inquirer

build status

Installation

npm install inquirer-autocomplete-prompt

inquier v9 and inquirer-autocomplete-prompt v3 and higher are native esm modules, this mean you cannot use the commonjs syntax require('inquirer-autocomplete-prompt') anymore. If you want to learn more about using native esm in Node, I'd recommend reading the following guide. Alternatively, you can rely on an older version until you're ready to upgrade your environment:

npm install inquirer-autocomplete-prompt@^2.0.0

Usage

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

import inquirer from 'inquirer';
import inquirerPrompt from '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

import inquirer from 'inquirer';
import inquirerPrompt from '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

@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-cli@wcfactory/cliattheme-better-cliabcli@kaviar/terminal-bundletyperacerquantconnect-cli@webmethodsio/wmiocli@webscale-oy/bauble@whitecolor/meta@wic/sword-utils@wpk-cli/promptacadyBrosec@yuriazevedo/cz-emoji@zalishchuk/create-react-component@zicenter/open-cli@zicenter/swift-cli@zicenter/zi-cli@xiaojs/cli@xiaojs/generator-cli@xbyorange/mocks-server@xquare/xmojiall-repos-cliakkerisalpha-czalpha-cz-1create-myhtmlprojectcreate-myhtmlproject-app@yffed/cz-changelog@yoko0180/prompt@yancey-inc/lt-cli@yungvenuz/ssh-manager-cli@wya/mp-cli@zoushengda/create-miniapp@zrf9018/marvel-cli@zrf9018/marvel-mock-serveradvance-clixzt-cli@ccontour/home-cli@bybit/marvel-cli@bybit/marvel-mock-servernitin-shippy-clicli-shippydidaweb-cli@sheba/cz-conventionant-gamplify-category-interactionsanime-indiricianime-cliangular2-example-http-login@ezpaarse-project/ezmesure-admin@fand/kao@em-cli/shared@fenwik/togglinear@etclabscore/pristine-cli@eonteam/cli@erriy/collector@egcli/lr@elastictable/cli@eliperelman/netlify-cli@enfo/marvin@enesusta/dclisub-tv@dream2023/itaro@dxatscale/sfp-cli
3.0.0

2 months ago

2.0.0

9 months ago

1.4.0

1 year ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.12.2

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago