Module: Crosstest::OutputHelper

Included in:
Psychic::Script
Defined in:
lib/crosstest/output_helper.rb

Defined Under Namespace

Classes: StringShell

Instance Method Summary collapse

Instance Method Details

#build_stringObject


28
29
30
31
32
33
34
# File 'lib/crosstest/output_helper.rb', line 28

def build_string
  old_cli = @cli
  new_cli = @cli = StringShell.new
  yield
  @cli = old_cli
  new_cli.string
end

#cliObject


24
25
26
# File 'lib/crosstest/output_helper.rb', line 24

def cli
  @cli ||= Thor::Base.shell.new
end

#color_pad(string) ⇒ Object


80
81
82
# File 'lib/crosstest/output_helper.rb', line 80

def color_pad(string)
  string + colorize('', :white)
end

#colorize(string, *args) ⇒ Object


74
75
76
77
78
# File 'lib/crosstest/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

#indentObject


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/crosstest/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

TODO: Reporters for different formats


69
70
71
72
# File 'lib/crosstest/output_helper.rb', line 69

def print_table(*args)
  # @reporter.print_table(*args)
  cli.print_table(*args)
end

#reformat(string) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/crosstest/output_helper.rb', line 36

def reformat(string)
  return if string.nil? || string.empty?

  indent do
    string.gsub(/^/, indent)
  end
end

#say(msg) ⇒ Object


56
57
58
# File 'lib/crosstest/output_helper.rb', line 56

def say(msg)
  cli.say msg if msg
end

#status(status, msg = nil, color = :cyan, colwidth = 50) ⇒ Object


60
61
62
63
64
65
66
# File 'lib/crosstest/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