Sha256: 3251135db2661ca2de6b69c42e1c6a98f86764f37e708983c84cbbe52c360869

Contents?: true

Size: 919 Bytes

Versions: 1

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

require "pastel"
require "tty-prompt"

module CobraCommander
  module Output
    # Runs an interactive output printer
    module InteractivePrinter
      pastel = Pastel.new
      SUCCESS = "#{pastel.green("✔")} %s".freeze
      ERROR = "#{pastel.red("✖")} %s".freeze
      BYE = pastel.decorate("👋 Bye!", :white, :on_black, :bold).freeze

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cobra_commander-0.12.0 lib/cobra_commander/output/interactive_printer.rb