module TestBench::Bootstrap::Output

Attributes

indentation[W]

Public Instance Methods

indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block) click to toggle source
# File lib/test_bench/bootstrap.rb, line 165
def indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block)
  device ||= $stdout

  unless text.nil?
    sgr_codes = Array(sgr_codes)
    unless sgr_code.nil?
      sgr_codes << sgr_code
    end

    unless sgr_codes.empty?
      sgr_codes.map! do |sgr_code|
        sgr_code.to_s(16)
      end

      text = "\e[#{sgr_codes.join(';')}m#{text}\e[0m"
    end

    text = "#{"\t" if tab_indent}#{'  ' * indentation}#{text}"

    device.puts(text)
  end

  return if block.nil?

  self.indentation += 1 unless text.nil?

  begin
    block.()
  ensure
    self.indentation -= 1 unless text.nil?
  end
end
indentation() click to toggle source
# File lib/test_bench/bootstrap.rb, line 198
def indentation
  @indentation ||= 0
end
write(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil) click to toggle source
# File lib/test_bench/bootstrap.rb, line 161
def write(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil)
  indent(text, device: device, sgr_code: sgr_code, sgr_codes: sgr_codes, tab_indent: tab_indent)
end