terkelg/prompts

Show and accept number input too for select input type

ucarbehlul opened this issue · 1 comments

Is your feature request related to a problem?

If you are using the select prompt, it sometimes takes lots of key presses to go to the choice you want, especially if you are going through lots of forms.

Describe the solution you'd like

The select prompt type can show number next to each option and if number is typed and entered it can accept that choice.
If tab is pressed after a number, it can jump to the closest option to that and show the list from that position.
That would improve user experience in long lists.

Seems like a use case for autocomplete. If you have a lot of choices, consider doing something like this:

const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
const doubleColors = colors.reduce((doubles, prefix) => {
  colors.forEach((color) => doubles.push(`${prefix}-${color}`));
  return doubles;
}, []);

await prompts({
  type: 'autocomplete',
  name: 'color',
  message: 'Pick your favorite color.',
  choices: doubleColors.map(color => {return {title: color}}),
});