Module: CobraCommander::Output::InteractivePrinter

Defined in:
lib/cobra_commander/output/interactive_printer.rb

Overview

Runs an interactive output printer

Constant Summary collapse

SUCCESS =
"#{pastel.green("")} %s".freeze
ERROR =
"#{pastel.red("")} %s".freeze
BYE =
pastel.decorate("👋 Bye!", :white, :on_black, :bold).freeze

Class Method Summary collapse

Class Method Details

.run(contexts, output) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cobra_commander/output/interactive_printer.rb', line 15

def self.run(contexts, output)
  prompt = TTY::Prompt.new
  context_options = contexts.reduce({}) do |options, context|
    template = context.success? ? SUCCESS : ERROR
    options.merge(
      format(template, context.component_name) => context
    )
  end
  loop do
    context = prompt.select("Print output?", context_options)
    output.puts context.output
  end
rescue TTY::Reader::InputInterrupt
  output.puts "\n\n", BYE
end