Module: RSpec::Core::Formatters::ConsoleCodes

Defined in:
lib/rspec/core/formatters/console_codes.rb

Constant Summary

VT100_CODES =
{
  :black   => 30,
  :red     => 31,
  :green   => 32,
  :yellow  => 33,
  :blue    => 34,
  :magenta => 35,
  :cyan    => 36,
  :white   => 37,
  :bold    => 1,
}
VT100_CODE_VALUES =
VT100_CODES.invert

Class Method Summary (collapse)

Class Method Details

+ (Object) console_code_for(code_or_symbol)

21
22
23
24
25
26
27
28
29
# File 'lib/rspec/core/formatters/console_codes.rb', line 21
def console_code_for(code_or_symbol)
  if VT100_CODE_VALUES.has_key?(code_or_symbol)
    code_or_symbol
  else
    VT100_CODES.fetch(code_or_symbol) do
      console_code_for(:white)
    end
  end
end

+ (Object) wrap(text, code_or_symbol)

31
32
33
34
35
36
37
# File 'lib/rspec/core/formatters/console_codes.rb', line 31
def wrap(text, code_or_symbol)
  if RSpec.configuration.color_enabled?
    "\e[#{console_code_for(code_or_symbol)}m#{text}\e[0m"
  else
    text
  end
end