JEG2 / highline

A higher level command-line oriented interface.
Other
1.29k stars 137 forks source link

Possible to accept multiple selections with `.in` and `.default`? #246

Closed Joshfindit closed 1 year ago

Joshfindit commented 4 years ago

Currently I have

# trimmed: puts menu items

cli.ask("Which number? (0 or <Enter> to skip): ", Integer) { |q|
  q.in = 0..(possibleSelections.length)
  q.default = 0
}

This is awesome for choosing multiple items from a list, such as:


1. TEST1.png
2. TEST2.png
3. TEST3.png
4. TEST4.png
5. TEST5.png
6. TEST6.png
7. TEST7.png

Which number? (0 or <Enter> to skip): 12
Your answer isn't within the expected range (included in 0..7).
?

What I would like to extend to is this:

Which number(s)? (0 or <Enter> to skip): 1, 2, 5
Success

and

Which number(s)? (0 or <Enter> to skip): 1, 2, 5, 12
Your answer isn't within the expected range (included in 0..7).
?

Thanks!

abinoam commented 4 years ago

Dear @Joshfindit,

Sorry, for the late answer.

I'm not sure I could understand the problem you have stated correctly. Could you please clarify it? (Note that I'm not a native english speaker)

Best regards

abinoam commented 4 years ago

Perhaps it would be easier for me to understand if you provide a complete code snipped that I could try to run on my machine things.

rubyFeedback commented 3 years ago

If I understand it correctly he wants to be able to do multiple input on the same line?

not sure if I understood it but the sample he showed was e. g.:

"1, 2, 5, 12"

Can't say so far as I usually have only single selections. :D But this may be what he is aiming for. In that case probably just a convenience feature to avoid several newlines for multiple guesses, I suppose?

abinoam commented 1 year ago

Hi @Joshfindit

Are you still interested in this feature. I tried to accomplish it with minimum code change. I'll open a PR tomorrow.

Joshfindit commented 1 year ago

Are you still interested in this feature.

I don’t personally have a need for it any more. I still do think there’s general benefit for others.