class ChefApply::UI::Terminal

Attributes

location[RW]

To support matching in test

Public Class Methods

get_multispinner() click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 84
def get_multispinner
  ChefApply::Config.dev.spinner ? TTY::Spinner::Multi : PlainTextHeader
end
get_spinner() click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 88
def get_spinner
  ChefApply::Config.dev.spinner ? TTY::Spinner : PlainTextElement
end
init(location) click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 32
def init(location)
  @location = location
end
output(msg) click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 40
def output(msg)
  @location.puts msg
end
render_job(initial_msg, job) click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 69
def render_job(initial_msg, job)
  # TODO why do we have to pass prefix to both the spinner and the reporter?
  spinner = get_spinner.new(spinner_prefix(job.prefix), output: @location, hide_cursor: true)
  reporter = StatusReporter.new(spinner, prefix: job.prefix, key: :status)
  reporter.update(initial_msg)
  spinner.auto_spin
  job.run(reporter)
end
render_parallel_jobs(header, jobs) click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 44
def render_parallel_jobs(header, jobs)
  # Do not indent the topmost 'parent' spinner, but do indent child spinners
  indent_style = { top: "",
                   middle: TTY::Spinner::Multi::DEFAULT_INSET[:middle],
                   bottom: TTY::Spinner::Multi::DEFAULT_INSET[:bottom] }
  # @option options [Hash] :style
  #   keys :top :middle and :bottom can contain Strings that are used to
  #   indent the spinners. Ignored if message is blank
  multispinner = get_multispinner.new("[:spinner] #{header}",
    output: @location,
    hide_cursor: true,
    style: indent_style)
  jobs.each do |job|
    multispinner.register(spinner_prefix(job.prefix), hide_cursor: true) do |spinner|
      reporter = StatusReporter.new(spinner, prefix: job.prefix, key: :status)
      job.run(reporter)
    end
  end
  multispinner.auto_spin
ensure
  # Spinners hide the cursor for better appearance, so we need to make sure
  # we always bring it back
  show_cursor
end
show_cursor() click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 92
def show_cursor
  TTY::Cursor.show
end
spinner_prefix(prefix) click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 78
def spinner_prefix(prefix)
  spinner_msg = "[:spinner] "
  spinner_msg += ":prefix " unless prefix.empty?
  spinner_msg + ":status"
end
write(msg) click to toggle source
# File lib/chef_apply/ui/terminal.rb, line 36
def write(msg)
  @location.write(msg)
end