Module: Turn::Colorize

Included in:
IsoRunner, Reporter
Defined in:
lib/turn/colorize.rb

Overview

Provides a uniform interface for colorizing Turn output.

Constant Summary collapse

COLORLESS_TERMINALS =
['dumb']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blue(string) ⇒ Object



56
57
58
# File 'lib/turn/colorize.rb', line 56

def self.blue(string)
  colorize? ? ::ANSI::Code.blue{ string } : string
end

.bold(string) ⇒ Object



64
65
66
# File 'lib/turn/colorize.rb', line 64

def self.bold(string)
  colorize? ? ::ANSI::Code.bold{ string } : string
end

.color_supported?Boolean

Does the system support color?

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/turn/colorize.rb', line 40

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

Colorize output or not?

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/turn/colorize.rb', line 31

def self.colorize?
  return @colorize unless @colorize.nil?
  @colorize ||= (
    ansi = Turn.config.ansi?
    ansi.nil? ? color_supported? : ansi
  )
end

.error(string) ⇒ Object



80
81
82
83
# File 'lib/turn/colorize.rb', line 80

def self.error(string)
  #colorize? ? ::ANSI::Code.white_on_red{ string } : string
  colorize? ? ::ANSI::Code.yellow{ string } : string
end

.fail(string) ⇒ Object



76
77
78
# File 'lib/turn/colorize.rb', line 76

def self.fail(string)
  colorize? ? ::ANSI::Code.red{ string } : string
end

.green(string) ⇒ Object



52
53
54
# File 'lib/turn/colorize.rb', line 52

def self.green(string)
  colorize? ? ::ANSI::Code.green{ string } : string
end

.included(base) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/turn/colorize.rb', line 19

def self.included(base)
  base.module_eval do
    const_set :PASS,  Colorize.pass('PASS')
    const_set :FAIL,  Colorize.fail('FAIL')
    const_set :ERROR, Colorize.error('ERROR')
    const_set :SKIP,  Colorize.skip('SKIP')
  end
end

.magenta(string) ⇒ Object



60
61
62
# File 'lib/turn/colorize.rb', line 60

def self.magenta(string)
  colorize? ? ::ANSI::Code.magenta{ string } : string
end

.mark(string) ⇒ Object



68
69
70
# File 'lib/turn/colorize.rb', line 68

def self.mark(string)
  colorize? ? ::ANSI::Code.yellow{ string } : string
end

.pass(string) ⇒ Object



72
73
74
# File 'lib/turn/colorize.rb', line 72

def self.pass(string)
  colorize? ? ::ANSI::Code.green{ string } : string
end

.red(string) ⇒ Object



48
49
50
# File 'lib/turn/colorize.rb', line 48

def self.red(string)
  colorize? ? ::ANSI::Code.red{ string } : string
end

.skip(string) ⇒ Object



85
86
87
# File 'lib/turn/colorize.rb', line 85

def self.skip(string)
  colorize? ? ::ANSI::Code.cyan{ string } : string
end

Instance Method Details

#colorize?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/turn/colorize.rb', line 89

def colorize?
  Colorize.colorize?
end