terkelg / prompts

❯ Lightweight, beautiful and user-friendly interactive prompts
MIT License
8.88k stars 304 forks source link

Show and accept number input too for select input type #363

Open ucarbehlul opened 2 years ago

ucarbehlul commented 2 years ago

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.

joeykilpatrick commented 1 year ago

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}}),
});