Method: Blufin::Terminal.prompt_multi_select
- Defined in:
- lib/core/terminal.rb
.prompt_multi_select(question, options, help: nil, per_page: 20, cycle: true) ⇒ Object
Select drinks? (Use ↑/↓ arrow keys, press Space to select and Enter to finish)“ ‣ ⬡ vodka
⬡ beer
⬡ wine
⬡ whisky
⬡ bourbon
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/core/terminal.rb', line 466 def self.prompt_multi_select(question, , help: nil, per_page: 20, cycle: true) raise RuntimeError, "Expected Array, instead got #{.class}" unless .is_a?(Array) puts display_prompt_help(help) unless help.nil? prompt = TTY::Prompt.new if [0].is_a?(String) prompt.multi_select(display_prompt_text(question), , per_page: per_page, cycle: cycle) elsif [0].is_a?(Hash) prompt.multi_select(display_prompt_text(question), , per_page: per_page, cycle: cycle) do || .each do |option| raise RuntimeError, "Expected option to be Hash, instead got: (#{option.class}) #{option.inspect}" unless option.is_a?(Hash) raise RuntimeError, 'Option is missing key => :text' unless option.has_key?(:text) raise RuntimeError, 'Option is missing key => :value' unless option.has_key?(:value) raise RuntimeError, "Expected :disabled option to be String, instead got: #{option[:disabled].class}" if option.has_key?(:disabled) && !option[:disabled].is_a?(String) && !option[:disabled].nil? .choice option[:text], option[:value] unless option.has_key?(:disabled) .choice option[:text], option[:value], disabled: "\x1B[38;5;196m#{option[:disabled]}\x1B[0m" if option.has_key?(:disabled) end end else raise RuntimeError, "Expected options Array to consist of either Strings or Hashes, instead got: #{.inspect}" end end |