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

#indentation ⇒ Object



246
247
248
# File 'lib/test_bench/bootstrap.rb', line 246

def indentation
  @indentation ||= 0
end

Instance Method Details

#device ⇒ Object



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

def device
  @device ||= Defaults.output_device
end

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



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/test_bench/bootstrap.rb', line 209

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

#newline ⇒ Object



205
206
207
# File 'lib/test_bench/bootstrap.rb', line 205

def newline
  write('')
end

#raw_write(text, device = nil) ⇒ Object



240
241
242
243
244
# File 'lib/test_bench/bootstrap.rb', line 240

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



201
202
203
# File 'lib/test_bench/bootstrap.rb', line 201

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