Module: Turn::Colorize
Overview
Provides a uniform interface for colorizing Turn output.
Constant Summary collapse
- COLORLESS_TERMINALS =
['dumb']
- PASS =
pass('PASS')
- FAIL =
fail('FAIL')
- ERROR =
error('ERROR')
- SKIP =
skip('SKIP')
Class Method Summary collapse
- .blue(string) ⇒ Object
- .bold(string) ⇒ Object
- .color_supported? ⇒ Boolean
- .colorize? ⇒ Boolean
- .error(string) ⇒ Object
- .fail(string) ⇒ Object
- .green(string) ⇒ Object
- .magenta(string) ⇒ Object
- .pass(string) ⇒ Object
- .red(string) ⇒ Object
- .skip(string) ⇒ Object
Instance Method Summary collapse
Class Method Details
.blue(string) ⇒ Object
48 49 50 |
# File 'lib/turn/colorize.rb', line 48 def self.blue(string) colorize? ? ::ANSI::Code.blue{ string } : string end |
.bold(string) ⇒ Object
56 57 58 |
# File 'lib/turn/colorize.rb', line 56 def self.bold(string) colorize? ? ::ANSI::Code.bold{ string } : string end |
.color_supported? ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/turn/colorize.rb', line 32 def self.color_supported? return false unless defined?(::ANSI::Code) return false unless $stdout.tty? return true if ENV.has_key?('TERM') && !COLORLESS_TERMINALS.include?(ENV['TERM']) return true if ::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ && ENV.has_key?('ANSICON') return false end |
.colorize? ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/turn/colorize.rb', line 21 def self.colorize? @colorize ||= ( ansi = Turn.config.ansi? if ansi.nil? color_supported? else Turn.config.ansi? end ) end |
.error(string) ⇒ Object
68 69 70 71 |
# File 'lib/turn/colorize.rb', line 68 def self.error(string) #colorize? ? ::ANSI::Code.white_on_red{ string } : string colorize? ? ::ANSI::Code.yellow{ string } : string end |
.fail(string) ⇒ Object
64 65 66 |
# File 'lib/turn/colorize.rb', line 64 def self.fail(string) colorize? ? ::ANSI::Code.red{ string } : string end |
.green(string) ⇒ Object
44 45 46 |
# File 'lib/turn/colorize.rb', line 44 def self.green(string) colorize? ? ::ANSI::Code.green{ string } : string end |
.magenta(string) ⇒ Object
52 53 54 |
# File 'lib/turn/colorize.rb', line 52 def self.magenta(string) colorize? ? ::ANSI::Code.magenta{ string } : string end |
.pass(string) ⇒ Object
60 61 62 |
# File 'lib/turn/colorize.rb', line 60 def self.pass(string) colorize? ? ::ANSI::Code.green{ string } : string end |
.red(string) ⇒ Object
40 41 42 |
# File 'lib/turn/colorize.rb', line 40 def self.red(string) colorize? ? ::ANSI::Code.red{ string } : string end |
.skip(string) ⇒ Object
73 74 75 |
# File 'lib/turn/colorize.rb', line 73 def self.skip(string) colorize? ? ::ANSI::Code.cyan{ string } : string end |