module Psychic::OutputHelper

Public Instance Methods

build_string() { || ... } click to toggle source
# File lib/psychic/output_helper.rb, line 28
def build_string
  old_cli = @cli
  new_cli = @cli = StringShell.new
  yield
  @cli = old_cli
  new_cli.string
end
cli() click to toggle source
# File lib/psychic/output_helper.rb, line 24
def cli
  @cli ||= Thor::Base.shell.new
end
color_pad(string) click to toggle source
# File lib/psychic/output_helper.rb, line 80
def color_pad(string)
  string + colorize('', :white)
end
colorize(string, *args) click to toggle source
# File lib/psychic/output_helper.rb, line 74
def colorize(string, *args)
  return string unless @reporter.respond_to? :set_color
  # @reporter.set_color(string, *args)
  cli.set_color(string, *args)
end
indent() { || ... } click to toggle source
# File lib/psychic/output_helper.rb, line 44
def indent
  @indent_level ||= 0
  if block_given?
    @indent_level += 2
    result = yield
    @indent_level -= 2
    result
  else
    ' ' * @indent_level
  end
end
print_table(*args) click to toggle source

TODO: Reporters for different formats

reformat(string) click to toggle source
# File lib/psychic/output_helper.rb, line 36
def reformat(string)
  return if string.nil? || string.empty?

  indent do
    string.gsub(/^/, indent)
  end
end
say(msg) click to toggle source
# File lib/psychic/output_helper.rb, line 56
def say(msg)
  cli.say msg if msg
end
status(status, msg = nil, color = :cyan, colwidth = 50) { || ... } click to toggle source
# File lib/psychic/output_helper.rb, line 60
def status(status, msg = nil, color = :cyan, colwidth = 50)
  msg = yield if block_given?
  cli.say(indent) if indent.length > 0
  status = cli.set_color("#{status}:", color, true)
  # The built-in say_status is right-aligned, we want left-aligned
  cli.say format("%-#{colwidth}s %s", status, msg).rstrip
end