Module: Cucumber::Formatter::ANSIColor

Includes:
Term::ANSIColor
Included in:
Console
Defined in:
lib/cucumber/formatter/ansicolor.rb

Overview

Constant Summary collapse

ALIASES =
Hash.new do |h, k|
  h[Regexp.last_match(1)] + ',bold' if k.to_s =~ /(.*)_param/
end.merge(
  'undefined' => 'yellow',
  'pending'   => 'yellow',
  'flaky'     => 'yellow',
  'failed'    => 'red',
  'passed'    => 'green',
  'outline'   => 'cyan',
  'skipped'   => 'cyan',
  'comment'   => 'grey',
  'tag'       => 'cyan'
)

Constants included from Term::ANSIColor

Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Term::ANSIColor

attributes, coloring=, coloring?, included, #uncolored

Class Method Details

.define_greyObject

:nodoc:


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/cucumber/formatter/ansicolor.rb', line 103

def self.define_grey #:nodoc:
  gem 'genki-ruby-terminfo'
  require 'terminfo'
  case TermInfo.default_object.tigetnum('colors')
  when 0
    raise "Your terminal doesn't support colours."
  when 1
    ::Cucumber::Term::ANSIColor.coloring = false
    alias_method :grey, :white
  when 2..8
    alias_method :grey, :white # rubocop:disable Lint/DuplicateMethods
  else
    define_real_grey
  end
rescue Exception => e # rubocop:disable Lint/RescueException
  if e.class.name == 'TermInfo::TermInfoError'
    STDERR.puts '*** WARNING ***'
    STDERR.puts "You have the genki-ruby-terminfo gem installed, but you haven't set your TERM variable."
    STDERR.puts 'Try setting it to TERM=xterm-256color to get grey colour in output.'
    STDERR.puts "\n"
    alias_method :grey, :white
  else
    define_real_grey
  end
end

.define_real_greyObject

:nodoc:


129
130
131
132
133
# File 'lib/cucumber/formatter/ansicolor.rb', line 129

def self.define_real_grey #:nodoc:
  define_method :grey do |string|
    ::Cucumber::Term::ANSIColor.coloring? ? "\e[90m#{string}\e[0m" : string
  end
end

Instance Method Details

#cukes(n) ⇒ Object


137
138
139
# File 'lib/cucumber/formatter/ansicolor.rb', line 137

def cukes(n)
  ('(::) ' * n).strip
end

#green_cukes(n) ⇒ Object


141
142
143
# File 'lib/cucumber/formatter/ansicolor.rb', line 141

def green_cukes(n)
  blink(green(cukes(n)))
end

#red_cukes(n) ⇒ Object


145
146
147
# File 'lib/cucumber/formatter/ansicolor.rb', line 145

def red_cukes(n)
  blink(red(cukes(n)))
end

#yellow_cukes(n) ⇒ Object


149
150
151
# File 'lib/cucumber/formatter/ansicolor.rb', line 149

def yellow_cukes(n)
  blink(yellow(cukes(n)))
end