class ChefCore::CLIUX::UI::PlainTextElement

Public Class Methods

new(format, opts) click to toggle source
# File lib/chef_core/cliux/ui/plain_text_element.rb, line 22
def initialize(format, opts)
  @orig_format = format
  @format = format
  @output = opts[:output]
end

Public Instance Methods

auto_spin() click to toggle source
# File lib/chef_core/cliux/ui/plain_text_element.rb, line 75
def auto_spin; end
error() click to toggle source
# File lib/chef_core/cliux/ui/plain_text_element.rb, line 65
def error
  @err = true
  @succ = false
end
run() { || ... } click to toggle source
# File lib/chef_core/cliux/ui/plain_text_element.rb, line 28
def run(&block)
  yield
end
success() click to toggle source
# File lib/chef_core/cliux/ui/plain_text_element.rb, line 70
def success
  @succ = true
  @err = false
end
update(params) click to toggle source
# File lib/chef_core/cliux/ui/plain_text_element.rb, line 32
def update(params)
  # Some of this is particular to our usage -
  # prefix does not cause a text update, but does
  # change the prefix for future messages.
  if params.key?(:prefix)
    @format = @orig_format.gsub(":prefix", params[:prefix])
    return
  end

  if @succ
    ind = "OK"
    @succ = false
    log_method = :info
  elsif @err
    ind = "ERR"
    @err = false
    log_method = :error
  else
    log_method = :debug
    ind = " - "
  end

  # Since this is a generic type, we can replace any component
  # name in this regex - but for now :spinner is the only component
  # we're standing in for.
  msg = @format.gsub(/:spinner/, ind)
  params.each_pair do |k, v|
    msg.gsub!(/:#{k}/, v)
  end
  ChefCore::Log.send(log_method, msg)
  @output.puts(msg)
end