Method: Kontena::LightPrompt#multi_select

Defined in:
lib/kontena/light_prompt.rb

#multi_select(*args) {|choice_collector| ... } ⇒ Object

Yields:

  • (choice_collector)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/kontena/light_prompt.rb', line 64

def multi_select(*args, &block)
  choice_collector = Menu.new
  yield choice_collector
  choice_collector.add_quit_choice

  selections = []

  loop do
    choice_collector.remove_choices(selections)

    answer = prompt.enum_select(*args) do |menu|
      choice_collector.calls.each do |meth, args|
        if menu.respond_to?(meth)
          menu.send(meth, *args)
        end
      end
      choice_collector.choices.each do |choice|
        menu.choice choice.first, choice.last
      end
    end

    break if answer == :done
    selections << answer
  end

  selections
end