class Enolib::TerminalReporter
Public Class Methods
new(context)
click to toggle source
Calls superclass method
Enolib::Reporter::new
# File lib/enolib/reporters/terminal_reporter.rb, line 49 def initialize(context) super(context) highest_shown_line_number = @snippet.length @snippet.reverse.each_with_index do |tag, index| if tag && tag != :omission highest_shown_line_number = index + 1 break end end @line_number_padding = [4, highest_shown_line_number.to_s.length].max @header = '' if @context.source @header += "#{BLACK + BRIGHT_RED_BACKGROUND} #{INDICATORS[EMPHASIZE]} #{' '.rjust(@line_number_padding)} #{RESET} #{BOLD}#{@context.source}#{RESET}\n" end end
Public Instance Methods
print_line(line, tag)
click to toggle source
# File lib/enolib/reporters/terminal_reporter.rb, line 69 def print_line(line, tag) if tag == :omission return "#{DIM + BRIGHT_BLACK_BACKGROUND}#{'...'.rjust(@line_number_padding + 2)} #{RESET}" end number = (line + HUMAN_INDEXING).to_s instruction = @index[line] content = '' if instruction if instruction[:type] == :comment || instruction[:type] == :unparsed content = BRIGHT_BLACK + @context.input[instruction[:ranges][:line][RANGE_BEGIN]...instruction[:ranges][:line][RANGE_END]] + RESET else content = @context.input[instruction[:ranges][:line][RANGE_BEGIN]...instruction[:ranges][:line][RANGE_END]] instruction[:ranges].sort_by { |_type, range| range[0] }.reverse_each do |type, range| next if type == :line before = content[0...range[RANGE_BEGIN] - instruction[:ranges][:line][RANGE_BEGIN]] after = content[range[RANGE_END] - instruction[:ranges][:line][RANGE_BEGIN]..-1] # TODO: Here and everywhere: Why is RANGE_BEGIN without anything and like that even working? Check soundness content = before + RANGE_STYLE[type] + @context.input[range[RANGE_BEGIN]...range[RANGE_END]] + RESET + after end end end "#{GUTTER_STYLE[tag]} #{INDICATORS[tag]} #{number.rjust(@line_number_padding)} #{RESET} #{content}" end
Private Instance Methods
print()
click to toggle source
# File lib/enolib/reporters/terminal_reporter.rb, line 101 def print snippet = @snippet.each_with_index.map { |tag, line| print_line(line, tag) if tag }.compact.join("\n") @header + snippet end