Module: RSpec::Core::Formatters::ConsoleCodes
- Defined in:
- lib/rspec/core/formatters/console_codes.rb
Overview
ConsoleCodes provides helpers for formatting console output with ANSI codes, e.g. color's and bold.
Class Method Summary collapse
-
.console_code_for(code_or_symbol) ⇒ Fixnum
Fetches the correct code for the supplied symbol, or checks that a code is valid.
-
.wrap(text, code_or_symbol) ⇒ String
Wraps a piece of text in ANSI codes with the supplied code.
Class Method Details
.console_code_for(code_or_symbol) ⇒ Fixnum
Fetches the correct code for the supplied symbol, or checks that a code is valid. Defaults to white (37).
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rspec/core/formatters/console_codes.rb', line 39 def console_code_for(code_or_symbol) if (config_method = config_colors_to_methods[code_or_symbol]) console_code_for RSpec.configuration.__send__(config_method) elsif VT100_CODE_VALUES.key?(code_or_symbol) code_or_symbol else VT100_CODES.fetch(code_or_symbol) do console_code_for(:white) end end end |
.wrap(text, code_or_symbol) ⇒ String
Wraps a piece of text in ANSI codes with the supplied code. Will
only apply the control code if RSpec.configuration.color_enabled?
returns true.
58 59 60 61 62 63 64 |
# File 'lib/rspec/core/formatters/console_codes.rb', line 58 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 |