Class: CqlRuby::ConsolePrinter

Inherits:
AbstractPrinter show all
Defined in:
lib/cql_ruby/console_printer.rb

Overview

Prints to console.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConsolePrinter

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

Parameters:

  • value

    the value to set the attribute color_on to.



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

Parameters:

  • value

    the value to set the attribute file_on to.



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

Parameters:

  • value

    the value to set the attribute source_on to.



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

Parameters:

  • value

    the value to set the attribute surrounding_lines to.



11
12
13
# File 'lib/cql_ruby/console_printer.rb', line 11

def surrounding_lines=(value)
  @surrounding_lines = value
end

Instance Method Details

Parameters:



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