Module: TestBench::Bootstrap::Output

Extended by:
Output
Included in:
Output
Defined in:
lib/test_bench/bootstrap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#indentationObject



255
256
257
# File 'lib/test_bench/bootstrap.rb', line 255

def indentation
  @indentation ||= 0
end

Instance Method Details

#deviceObject



260
261
262
# File 'lib/test_bench/bootstrap.rb', line 260

def device
  @device ||= Defaults.output_device
end

#indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/test_bench/bootstrap.rb', line 218

def indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block)
  unless text.nil?
    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}\n"

    raw_write(text, device)
  end

  return if block.nil?

  self.indentation += 1 unless text.nil?

  begin
    block.()
  ensure
    self.indentation -= 1 unless text.nil?
  end
end

#newlineObject



214
215
216
# File 'lib/test_bench/bootstrap.rb', line 214

def newline
  write('')
end

#raw_write(text, device = nil) ⇒ Object



249
250
251
252
253
# File 'lib/test_bench/bootstrap.rb', line 249

def raw_write(text, device=nil)
  device ||= self.device

  device.write(text)
end

#write(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil) ⇒ Object



210
211
212
# File 'lib/test_bench/bootstrap.rb', line 210

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