Sha256: bdba97df2d6c13e93c832a0558aa3283fed502a8259a87d129d4cd8d4f139db7

Contents?: true

Size: 1.36 KB

Versions: 67

Compression:

Stored size: 1.36 KB

Contents

require 'cli/ui'
require "tty-prompt"

class KuberKit::UI::Interactive
  include KuberKit::Import[
    "tools.logger",
  ]

  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)
    logger.debug(text)
  end

  def print_debug(title, text)
    logger.debug(text)
  end

  def print_result(message, data = {})
    print_debug("Result", "---------------------------")
    print_debug("Result", message)
    print_debug("Result", "---------------------------")
  end

  def prompt(text, options, &callback)
    prompt = TTY::Prompt.new
    prompt.select(text, options, filter: true, per_page: 10)
  rescue  TTY::Reader::InputInterrupt
    raise KuberKit::Error.new("Selection cancelled.")
  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

67 entries across 67 versions & 1 rubygems

Version Path
kuber_kit-1.3.8 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.3.7 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.1.8 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.3.6 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.1.7 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.3.5 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.3.4 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.1.6 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.3.3 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.3.2 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.1.5 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.3.1 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.3.0 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.1.4 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.2.7 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.2.6 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.2.5 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.2.4 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.2.2 lib/kuber_kit/ui/interactive.rb
kuber_kit-1.1.2 lib/kuber_kit/ui/interactive.rb