Class: SimpleCov::Formatter::Terminal::LinePrinter
- Inherits:
-
Object
- Object
- SimpleCov::Formatter::Terminal::LinePrinter
- Includes:
- MemoWise, BranchCoverage, ColorPrinting
- Defined in:
- lib/simple_cov/formatter/terminal/line_printer.rb
Constant Summary collapse
- LINE_NUMBER_WIDTH =
3
Instance Method Summary collapse
- #colored_line(line, sourcefile) ⇒ Object
-
#initialize(targeted_application_file = nil) ⇒ LinePrinter
constructor
A new instance of LinePrinter.
-
#numbered_line_output(line_number, color, source_code = '', missed_branch_info = nil) ⇒ Object
rubocop:disable Style/StringConcatenation.
Methods included from ColorPrinting
Constructor Details
#initialize(targeted_application_file = nil) ⇒ LinePrinter
Returns a new instance of LinePrinter.
12 13 14 |
# File 'lib/simple_cov/formatter/terminal/line_printer.rb', line 12 def initialize(targeted_application_file = nil) @targeted_application_file = targeted_application_file end |
Instance Method Details
#colored_line(line, sourcefile) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/simple_cov/formatter/terminal/line_printer.rb', line 16 def colored_line(line, sourcefile) colored_source_code = syntax_highlighted_source_lines[line.line_number - 1] line_number = line.line_number case when line.skipped? numbered_line_output(line_number, :white, colored_source_code) when line.coverage == 0 numbered_line_output(line_number, :white_on_red, colored_source_code) when (missed_branch_info = missed_branch_info(line, sourcefile)) numbered_line_output(line_number, :red_on_yellow, colored_source_code, missed_branch_info) when line.coverage.nil? numbered_line_output(line_number, :white, colored_source_code, missed_branch_info) else numbered_line_output(line_number, :green, colored_source_code, missed_branch_info) end end |
#numbered_line_output(line_number, color, source_code = '', missed_branch_info = nil) ⇒ Object
rubocop:disable Style/StringConcatenation
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/simple_cov/formatter/terminal/line_printer.rb', line 35 def numbered_line_output(line_number, color, source_code = '', missed_branch_info = nil) colored_space = case color when :red_on_yellow, :white_on_red then color(' ', color) else color(' ', :white_on_green) end pattern = ENV['SIMPLECOV_TERMINAL_HYPERLINK_PATTERN'].presence link_text = line_number.to_s.rjust(LINE_NUMBER_WIDTH, ' ') line_number_string = if pattern link_target = pattern.sub('%f', absolute_target_path).sub('%l', line_number.to_s) "\e]8;;#{link_target}\e\\#{link_text}\e]8;;\e\\" else link_text end output = colored_space + color(line_number_string, color) + colored_space + ' ' + source_code if missed_branch_info output << " #{color(missed_branch_info, :white_on_red)}" end output end |