Module: TestBench::Bootstrap::Output
Instance Attribute Summary collapse
Instance Method Summary collapse
- #device ⇒ Object
- #indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block) ⇒ Object
- #newline ⇒ Object
- #raw_write(text, device = nil) ⇒ Object
- #write(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil) ⇒ Object
Instance Attribute Details
#indentation ⇒ Object
219 220 221 |
# File 'lib/test_bench/bootstrap.rb', line 219 def indentation @indentation ||= 0 end |
Instance Method Details
#device ⇒ Object
224 225 226 |
# File 'lib/test_bench/bootstrap.rb', line 224 def device @device ||= Defaults.output_device end |
#indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/test_bench/bootstrap.rb', line 182 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
178 179 180 |
# File 'lib/test_bench/bootstrap.rb', line 178 def newline write('') end |
#raw_write(text, device = nil) ⇒ Object
213 214 215 216 217 |
# File 'lib/test_bench/bootstrap.rb', line 213 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
174 175 176 |
# File 'lib/test_bench/bootstrap.rb', line 174 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 |