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.
Constant Summary
Class Method Summary (collapse)
-
+ (Fixnum) console_code_for(code_or_symbol)
Fetches the correct code for the supplied symbol, or checks that a code is valid.
-
+ (String) wrap(text, code_or_symbol)
Wraps a piece of text in ANSI codes with the supplied code.
Class Method Details
+ (Fixnum) console_code_for(code_or_symbol)
Fetches the correct code for the supplied symbol, or checks that a code is valid. Defaults to white (37).
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rspec/core/formatters/console_codes.rb', line 30 def console_code_for(code_or_symbol) if RSpec.configuration.respond_to?(:#{code_or_symbol}_color") console_code_for configuration_color(code_or_symbol) 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 |
+ (String) wrap(text, code_or_symbol)
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.
49 50 51 52 53 54 55 |
# File 'lib/rspec/core/formatters/console_codes.rb', line 49 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 |