class TestBench::Output::Writer
Attributes
color[RW]
device[W]
indentation[RW]
level[W]
mutex[R]
Public Class Methods
build(device)
click to toggle source
# File lib/test_bench/output/writer.rb, line 16 def self.build device instance = new instance.device = device instance end
new(level=nil)
click to toggle source
# File lib/test_bench/output/writer.rb, line 10 def initialize level=nil @level = level @indentation = 0 @mutex = Mutex.new end
Public Instance Methods
color?()
click to toggle source
# File lib/test_bench/output/writer.rb, line 22 def color? return color unless color.nil? device.tty? end
decrease_indentation()
click to toggle source
# File lib/test_bench/output/writer.rb, line 27 def decrease_indentation mutex.synchronize do self.indentation -= 1 end end
device()
click to toggle source
# File lib/test_bench/output/writer.rb, line 33 def device @device ||= StringIO.new end
increase_indentation()
click to toggle source
# File lib/test_bench/output/writer.rb, line 37 def increase_indentation mutex.synchronize do self.indentation += 1 end end
level()
click to toggle source
# File lib/test_bench/output/writer.rb, line 43 def level @level ||= :normal end
lower_verbosity()
click to toggle source
# File lib/test_bench/output/writer.rb, line 47 def lower_verbosity if level == :verbose self.level = :normal elsif level == :normal self.level = :quiet end end
normal(prose, **arguments)
click to toggle source
# File lib/test_bench/output/writer.rb, line 55 def normal prose, **arguments arguments[:render] = false if level == :quiet write prose, **arguments end
quiet(prose, **arguments)
click to toggle source
# File lib/test_bench/output/writer.rb, line 60 def quiet prose, **arguments write prose, **arguments end
raise_verbosity()
click to toggle source
# File lib/test_bench/output/writer.rb, line 64 def raise_verbosity if level == :quiet self.level = :normal elsif level == :normal self.level = :verbose end end
verbose(prose, **arguments)
click to toggle source
# File lib/test_bench/output/writer.rb, line 72 def verbose prose, **arguments arguments[:render] = false unless level == :verbose write prose, **arguments end
write(prose, bg: nil, fg: nil, render: nil)
click to toggle source
# File lib/test_bench/output/writer.rb, line 77 def write prose, bg: nil, fg: nil, render: nil render = true if render.nil? if render text = String.new prose indentation = ' ' * self.indentation prose = Palette.apply prose, bg: bg, fg: fg if color? text = "#{indentation}#{prose}#{$INPUT_RECORD_SEPARATOR}" device.write text end end