class Kontena::LightPrompt

Attributes

prompt[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/kontena/light_prompt.rb, line 44
def initialize(options={})
  @prompt = TTY::Prompt.new(options)
end

Public Instance Methods

method_missing(meth, *args) click to toggle source
# File lib/kontena/light_prompt.rb, line 95
def method_missing(meth, *args)
  prompt.send(meth, *args)
end
multi_select(*args) { |choice_collector| ... } click to toggle source
# 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
respond_to_missing?(meth, privates = false) click to toggle source
# File lib/kontena/light_prompt.rb, line 99
def respond_to_missing?(meth, privates = false)
  prompt.respond_to?(meth, privates)
end
select(*args) { |choice_collector| ... } click to toggle source
# File lib/kontena/light_prompt.rb, line 48
def select(*args, &block)
  choice_collector = Menu.new
  yield choice_collector

  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
end