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



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

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

.bold(string) ⇒ Object



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

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

.color_supported?Boolean

Does the system support color?

Returns:

  • (Boolean)


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

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)


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

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

.error(string) ⇒ Object



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

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

.fail(string) ⇒ Object



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

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

.green(string) ⇒ Object



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

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

.included(base) ⇒ Object



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

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



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

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

.mark(string) ⇒ Object



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

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

.pass(string) ⇒ Object



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

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

.red(string) ⇒ Object



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

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

.skip(string) ⇒ Object



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

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

Instance Method Details

#colorize?Boolean

Returns:

  • (Boolean)


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

def colorize?
  Colorize.colorize?
end