Class: CqlRuby::ConsolePrinter
- Inherits:
-
AbstractPrinter
- Object
- AbstractPrinter
- CqlRuby::ConsolePrinter
- Defined in:
- lib/cql_ruby/console_printer.rb
Overview
Prints to console.
Instance Attribute Summary collapse
-
#color_on ⇒ Object
writeonly
Sets the attribute color_on.
-
#file_on ⇒ Object
writeonly
Sets the attribute file_on.
-
#source_on ⇒ Object
writeonly
Sets the attribute source_on.
-
#surrounding_lines ⇒ Object
writeonly
Sets the attribute surrounding_lines.
Instance Method Summary collapse
-
#initialize ⇒ ConsolePrinter
constructor
A new instance of ConsolePrinter.
- #print(crumb) ⇒ Object
Constructor Details
#initialize ⇒ ConsolePrinter
Returns a new instance of ConsolePrinter.
13 14 15 16 17 18 19 20 21 |
# File 'lib/cql_ruby/console_printer.rb', line 13 def initialize super @color_on = true @file_on = true @source_on = true @surrounding_lines = 0 @counter = 0 end |
Instance Attribute Details
#color_on=(value) ⇒ Object (writeonly)
Sets the attribute color_on
8 9 10 |
# File 'lib/cql_ruby/console_printer.rb', line 8 def color_on=(value) @color_on = value end |
#file_on=(value) ⇒ Object (writeonly)
Sets the attribute file_on
9 10 11 |
# File 'lib/cql_ruby/console_printer.rb', line 9 def file_on=(value) @file_on = value end |
#source_on=(value) ⇒ Object (writeonly)
Sets the attribute source_on
10 11 12 |
# File 'lib/cql_ruby/console_printer.rb', line 10 def source_on=(value) @source_on = value end |
#surrounding_lines=(value) ⇒ Object (writeonly)
Sets the attribute surrounding_lines
11 12 13 |
# File 'lib/cql_ruby/console_printer.rb', line 11 def surrounding_lines=(value) @surrounding_lines = value end |
Instance Method Details
#print(crumb) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cql_ruby/console_printer.rb', line 26 def print(crumb) parts = "##{color(97)}#{@counter}#{decor_reset}" parts += " #{color(94)}#{crumb.file_name}#{decor_reset}:#{color(33)}#{crumb.line_no}#{decor_reset} #{color(93)}#{crumb.type}#{decor_reset}" if @file_on if @source_on && @surrounding_lines.positive? parts_visible_len = parts.gsub(/\e\[\d+m/, '').size + 1 indent = ' ' * parts_visible_len (-@surrounding_lines).upto(-1).each { |offs| puts "#{indent}#{crumb.surrounding_line(offs)}" } end parts += ' ' + decorate_source_line(crumb) if @source_on puts parts if @source_on && @surrounding_lines.positive? 1.upto(@surrounding_lines).each { |offs| puts "#{indent}#{crumb.surrounding_line(offs)}" } puts '--' end @counter += 1 end |