Class: SimplecovCovview::CovView::Srcfile::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov_covview/color.rb

Constant Summary collapse

COLOR_8 =

8 colors colorscheme

{
  covered: {
    color: :white, 
    background: :green
  },
  missed: {
    color: :white, 
    background: :red
  },
}
COLOR_256 =

256 colors colorscheme

{
  covered: {
    color: :black, 
    background: :lightgreen
  },
  missed: {
    color: :black, 
    background: :lightpink
  },
}

Instance Method Summary collapse

Constructor Details

#initialize(status, contents) ⇒ Color

Colorize the source file detail view

Parameters:

  • status (Array)

    @src_files_line

  • contents (Array)

    @src_files_line



37
38
39
40
41
42
# File 'lib/simplecov_covview/color.rb', line 37

def initialize(status, contents)
  @status = status
  @contents = contents
  @colorscheme = {}
  set_colorscheme
end

Instance Method Details

#colorizeObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/simplecov_covview/color.rb', line 75

def colorize
  return @contents unless (use_8colors? || use_256colors?)

  case @status
  when "covered"
    out_str = Rainbow(@contents).color(covered_color).bg(covered_background)
  when "missed"
    out_str = Rainbow(@contents).color(missed_color).bg(missed_background)
  else
    out_str = @contents
  end

  out_str
end

#covered_backgroundObject



63
64
65
# File 'lib/simplecov_covview/color.rb', line 63

def covered_background
  @colorscheme[:covered][:background]
end

#covered_colorObject



59
60
61
# File 'lib/simplecov_covview/color.rb', line 59

def covered_color
  @colorscheme[:covered][:color]
end

#missed_backgroundObject



71
72
73
# File 'lib/simplecov_covview/color.rb', line 71

def missed_background
  @colorscheme[:missed][:background]
end

#missed_colorObject



67
68
69
# File 'lib/simplecov_covview/color.rb', line 67

def missed_color
  @colorscheme[:missed][:color]
end

#set_colorschemeObject



54
55
56
57
# File 'lib/simplecov_covview/color.rb', line 54

def set_colorscheme
  @colorscheme = COLOR_8 if use_8colors?
  @colorscheme = COLOR_256 if use_256colors?
end

#use_256colors?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/simplecov_covview/color.rb', line 49

def use_256colors?
  SimpleCov::Formatter::CovView.use_256color ||= false
end

#use_8colors?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/simplecov_covview/color.rb', line 45

def use_8colors?
  SimpleCov::Formatter::CovView.use_8color ||= false
end