Sha256: 1b108e44acfe1664eb5ad966915ec8ef9b94c9cc742e19747dbf5e047a05cdf7

Contents?: true

Size: 989 Bytes

Versions: 16

Compression:

Stored size: 989 Bytes

Contents

require 'cli/ui'

class KuberKit::UI::Interactive
  class TaskGroup < CLI::UI::SpinGroup
  end

  def create_task_group
    init_if_needed
    TaskGroup.new
  end

  def create_task(title, &block)
    init_if_needed
    CLI::UI::Spinner.spin(title, &block)
  end

  def print_info(title, text)
    print_in_frame(title, text, color: :blue)
  end

  def print_error(title, text)
    print_in_frame(title, text, color: :red)
  end

  def print_warning(title, text)
    print_in_frame(title, text, color: :yellow)
  end

  def prompt(text, options, &callback)
    CLI::UI::Prompt.ask(text) do |handler|
      options.each do |option|
        handler.option(option, &callback)
      end
    end
  end

  private
    def init
      @initialized = true
      ::CLI::UI::StdoutRouter.enable
    end

    def init_if_needed
      init unless @initialized
    end

    def print_in_frame(title, text, color:)
      CLI::UI::Frame.open(title, color: color) do
        puts text
      end
    end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
kuber_kit-0.3.5 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.3.4 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.3.3 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.3.2 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.3.1 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.3.0 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.9 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.8 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.7 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.6 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.5 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.4 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.3 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.2 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.1 lib/kuber_kit/ui/interactive.rb
kuber_kit-0.2.0 lib/kuber_kit/ui/interactive.rb