Module: SimpleCov::Color
| Relationships & Source Files | |
| Defined in: | lib/simplecov/color.rb |
Overview
ANSI colorization for stderr diagnostics. Thresholds mirror the HTML formatter (>= 90 green, >= 75 yellow, otherwise red) so a team's mental model of "what's the cutoff" is the same whether they're reading the terminal output or the HTML report.
Color precedence, highest first:
SimpleCov.color = true/false(programmatic override, wins over everything; default is:autowhich falls through)NO_COLORenv var (any non-empty value) → off (see no-color.org)FORCE_COLORenv var (any non-empty value) → onstream.tty?fallback
NO_COLOR wins over FORCE_COLOR if both env vars are set.
Constant Summary
-
ANSI =
# File 'lib/simplecov/color.rb', line 22{ red: "\e[31m", yellow: "\e[33m", green: "\e[32m", reset: "\e[0m" }.freeze -
GREEN_THRESHOLD =
# File 'lib/simplecov/color.rb', line 1990 -
YELLOW_THRESHOLD =
# File 'lib/simplecov/color.rb', line 2075
Class Method Summary
- .colorize(text, color, enabled: enabled?) ) mod_func
-
.colorize_percent(percent, text = nil, enabled: enabled?) )
mod_func
Render
percentas a fixed "NN.NN%" string colored by which threshold band it falls into. -
.enabled?(stream = $stderr) ⇒ Boolean
mod_func
streamis the IO that the colorized text is destined for. - .env_set?(name) ⇒ Boolean mod_func
- .for_percent(percent) mod_func
Class Method Details
.colorize(text, color, enabled: enabled?) ) (mod_func)
.colorize_percent(percent, text = nil, enabled: enabled?) ) (mod_func)
Render percent as a fixed "NN.NN%" string colored by which
threshold band it falls into. Callers that want a different
rendering of the number can pass the pre-rendered text.
# File 'lib/simplecov/color.rb', line 65
def colorize_percent(percent, text = nil, enabled: enabled?) colorize(text || format("%.2f%%", percent), for_percent(percent), enabled: enabled) end
.enabled?(stream = $stderr) ⇒ Boolean (mod_func)
.env_set?(name) ⇒ Boolean (mod_func)
# File 'lib/simplecov/color.rb', line 69
def env_set?(name) value = ENV.fetch(name, nil) value && !value.empty? end
.for_percent(percent) (mod_func)
[ GitHub ]# File 'lib/simplecov/color.rb', line 45
def for_percent(percent) return :green if percent >= GREEN_THRESHOLD return :yellow if percent >= YELLOW_THRESHOLD :red end