Skip to content

Commit

Permalink
add an example for #272
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jul 26, 2023
1 parent 6f3decc commit f655aaf
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/autocomplete/option-accept-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const { AutoComplete } = require('enquirer');

const fakeChoice = input => ({ value: input, message: '', name: input });

const prompt = new AutoComplete({
type: 'autocomplete',
name: 'flavor',
message: 'Pick your favorite flavor',
suggest(typed, choices) {
const maches = choices.filter(choice => choice.message.includes(typed));
return maches.length ? maches : [fakeChoice(typed)];
},
choices: [
'almond',
'apple',
'banana'
]
});

prompt.run()
.then(output => console.log({ output }))
.catch(console.log);

0 comments on commit f655aaf

Please sign in to comment.