Skip to content
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

Merged
merged 1 commit into from
Sep 19, 2018
Merged

Conversation

lavoiesl
Copy link
Contributor

@lavoiesl lavoiesl commented Sep 14, 2018

Returns an array of all selected options, potentially empty

image

Verified with scrolling, "Done" moves up.
image


Edit: Changed icons and style:
image

@lavoiesl lavoiesl force-pushed the seb/multiple_prompt branch 2 times, most recently from 91300f5 to 6c02ea3 Compare September 14, 2018 15:28
@lavoiesl
Copy link
Contributor Author

@@ -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 ↑ ↓ ⏎"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toggle

Copy link
Contributor Author

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 => "⬢" }
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The box is a little small though:
image

What do you think?

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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. 😛

Copy link
Contributor Author

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.

Copy link
Contributor

@jules2689 jules2689 left a 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

@lugray
Copy link
Contributor

lugray commented Sep 19, 2018

🎩 ❌
When the full set of options don't fit on screen (with multiple: true):

NoMethodError: undefined method `-' for nil:NilClass
	from /Users/lisaugray/src/github.com/Shopify/cli-ui/lib/cli/ui/prompt/interactive_options.rb:254:in `block in render_options'
	from /Users/lisaugray/src/github.com/Shopify/cli-ui/lib/cli/ui/prompt/interactive_options.rb:253:in `each'
	from /Users/lisaugray/src/github.com/Shopify/cli-ui/lib/cli/ui/prompt/interactive_options.rb:253:in `render_options'
	from /Users/lisaugray/src/github.com/Shopify/cli-ui/lib/cli/ui/prompt/interactive_options.rb:57:in `call'
	from /Users/lisaugray/src/github.com/Shopify/cli-ui/lib/cli/ui/prompt/interactive_options.rb:23:in `call'
	from /Users/lisaugray/src/github.com/Shopify/cli-ui/lib/cli/ui/prompt.rb:163:in `interactive_prompt'
	from /Users/lisaugray/src/github.com/Shopify/cli-ui/lib/cli/ui/prompt.rb:136:in `ask_interactive'
	from /Users/lisaugray/src/github.com/Shopify/cli-ui/lib/cli/ui/prompt.rb:80:in `ask'
	from (irb):14
	from bin/console:14:in `<main>'

@lavoiesl
Copy link
Contributor Author

I had tested it, but I broke it during a refactor :(
Good catch, fixed.

Copy link
Contributor

@lugray lugray left a 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
@lavoiesl lavoiesl merged commit 721e9fc into master Sep 19, 2018
@lavoiesl lavoiesl deleted the seb/multiple_prompt branch September 19, 2018 14:36
@sander-m
Copy link

👀 This is really cool

@lugray lugray temporarily deployed to production November 9, 2018 18:39 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants