-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multiple selection in prompt #38
Conversation
91300f5
to
6c02ea3
Compare
Icon taken from https://github.com/piotrmurach/tty-prompt |
lib/cli/ui/prompt.rb
Outdated
@@ -131,23 +131,36 @@ def ask_interactive(question, options = nil) | |||
end | |||
|
|||
raise(ArgumentError, 'insufficient options') if options.nil? || options.size < 2 | |||
puts_question("#{question} {{yellow:(choose with ↑ ↓ ⏎)}}") | |||
resp = interactive_prompt(options) | |||
instructions = (multiple ? "Toogle options. " : "") + "Choose with ↑ ↓ ⏎" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toggle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, thanks.
@@ -4,6 +4,9 @@ module CLI | |||
module UI | |||
module Prompt | |||
class InteractiveOptions | |||
DONE = "Done" | |||
CHECKBOX_ICON = { false => "⬡", true => "⬢" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use CHECKBOX_ICON = { false => "☐", true => "☑" }
instead? The hexagons look too much like circles => radio boxes => single selection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not married to that pair in particular - open to other options, but I think it's better than something that looks like single selection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a better option, so I went with the checkbox.
@@ -214,6 +246,7 @@ def render_options | |||
presented_options(recalculate: true).each do |choice, num| | |||
padding = ' ' * (max_num_length - num.to_s.length) | |||
message = " #{num}#{num ? '.' : ' '}#{padding}" | |||
message += " #{CHECKBOX_ICON[@chosen[num - 1]]} " if @multiple && num && num > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add colour as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what's best. Yellow/Green? On the checkbox only or the whole line? Perhaps make the line's text bold only if selected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say whole line, but not super opinionated on how exactly we style it, just that some kind of styling seems like the dev way. 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went for "standard vs bold+cyan", other options looked like a Christmas tree. See screenshot in description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems generally ok. Wouldnt mind comments surrounding the 1 vs 0 in some places, but otherwise lgtm
🎩 ❌
|
I had tested it, but I broke it during a refactor :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎩 🥗
Returns an array of all selected options, potentially empty
3929ad1
to
405b40f
Compare
👀 This is really cool |
Returns an array of all selected options, potentially empty
Verified with scrolling, "Done" moves up.

Edit: Changed icons and style:
