twpayne/chezmoi

promptChoice but allow for selecting multiple choices

Logicer16 opened this issue · 2 comments

Is your feature request related to a problem? Please describe.

There is currently no way to prompt a user to choose multiple item in a list. An example use case includes choosing which programs to install when setting up a new machine.

Describe the solution you'd like

A new template function which allows a user to choose multiple items from a list (i.e. check boxes).

I've seen other terminal programs impliment this by toggling an item's selection when its line number is entered, and then submitting the selection when the entered input is empty. Long lists are sometimes also paginated.

Describe alternatives you've considered

  • Attempting to parse a deliminated input to promptString. This is error prone, clunky to users, and doesn't garuntee the input is from the list.
  • An individual promptBool for each item, which gets long and repetitive quickly.

Additional context

Example from other terminal program

Example screenshot

Why do you need this? A list of N options has 2^N possible subsets of options. Do you really have 2^N different machine configurations on which you want to use chezmoi?

As your screenshot shows, implementing a multi-select in a terminal interface is complex, with complex navigation, paging, line wrapping, etc.

Instead, consider the following options:

  1. Either, group related options together and use promptBool for each one.
  2. Or, present the user with a list of options and get them to enter a comma-separated list of the options they want with promptString.

Both of these ensure that the input is guaranteed to be from the list are quick to use.

I can imagine it probably would be a bit of a headache to implement and maintain.
I’ve done some digging and what I’ll probably end up doing implementing something like this in shell script, which would also give me more control over it.

Thanks for taking the time to respond though.