# frozen_string_literal: truerequire'cucumber/platform'require'cucumber/term/ansicolor'ifCucumber::WINDOWS_MRIunlessENV['ANSICON']STDERR.puts%{*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansicon/) to get coloured output on Windows}Cucumber::Term::ANSIColor.coloring=falseendendCucumber::Term::ANSIColor.coloring=falseif!STDOUT.tty?&&!ENV.key?('AUTOTEST')moduleCucumbermoduleFormatter# Defines aliases for coloured output. You don't invoke any methods from this# module directly, but you can change the output colours by defining# a <tt>CUCUMBER_COLORS</tt> variable in your shell, very much like how you can# tweak the familiar POSIX command <tt>ls</tt> with# <a href="http://mipsisrisc.com/rambling/2008/06/27/lscolorsls_colors-now-with-linux-support/">$LSCOLORS/$LS_COLORS</a>## The colours that you can change are:## * <tt>undefined</tt> - defaults to <tt>yellow</tt># * <tt>pending</tt> - defaults to <tt>yellow</tt># * <tt>pending_param</tt> - defaults to <tt>yellow,bold</tt># * <tt>failed</tt> - defaults to <tt>red</tt># * <tt>failed_param</tt> - defaults to <tt>red,bold</tt># * <tt>passed</tt> - defaults to <tt>green</tt># * <tt>passed_param</tt> - defaults to <tt>green,bold</tt># * <tt>outline</tt> - defaults to <tt>cyan</tt># * <tt>outline_param</tt> - defaults to <tt>cyan,bold</tt># * <tt>skipped</tt> - defaults to <tt>cyan</tt># * <tt>skipped_param</tt> - defaults to <tt>cyan,bold</tt># * <tt>comment</tt> - defaults to <tt>grey</tt># * <tt>tag</tt> - defaults to <tt>cyan</tt>## For instance, if your shell has a black background and a green font (like the# "Homebrew" settings for OS X' Terminal.app), you may want to override passed# steps to be white instead of green.## Although not listed, you can also use <tt>grey</tt>.## Examples: (On Windows, use SET instead of export.)## export CUCUMBER_COLORS="passed=white"# export CUCUMBER_COLORS="passed=white,bold:passed_param=white,bold,underline"## To see what colours and effects are available, just run this in your shell:## ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Cucumber::Term::ANSIColor.attributes"#moduleANSIColorincludeCucumber::Term::ANSIColorALIASES=Hash.newdo|h,k|h[Regexp.last_match(1)]+',bold'ifk.to_s=~/(.*)_param/end.merge('undefined'=>'yellow','pending'=>'yellow','flaky'=>'yellow','failed'=>'red','passed'=>'green','outline'=>'cyan','skipped'=>'cyan','comment'=>'grey','tag'=>'cyan')ifENV['CUCUMBER_COLORS']# Example: export CUCUMBER_COLORS="passed=red:failed=yellow"ENV['CUCUMBER_COLORS'].split(':').eachdo|pair|a=pair.split('=')ALIASES[a[0]]=a[1]endend# Eval to define the color-named methods required by Term::ANSIColor.## Examples:## def failed(string=nil, &proc)# red(string, &proc)# end## def failed_param(string=nil, &proc)# red(bold(string, &proc)) + red# endALIASES.each_keydo|method_name|nextifmethod_name=~/.*_param/code=<<-COLOR
def #{method_name}(string=nil, &proc)
#{ALIASES[method_name].split(',').join('(')+'(string, &proc'+')'*ALIASES[method_name].split(',').length}
end
# This resets the colour to the non-param colour
def #{method_name}_param(string=nil, &proc)
#{ALIASES[method_name+'_param'].split(',').join('(')+'(string, &proc'+')'*ALIASES[method_name+'_param'].split(',').length} + #{ALIASES[method_name].split(',').join(' + ')}
end
COLOReval(code)# rubocop:disable Security/Evalenddefself.define_grey#:nodoc:gem'genki-ruby-terminfo'require'terminfo'caseTermInfo.default_object.tigetnum('colors')when0raise"Your terminal doesn't support colours."when1::Cucumber::Term::ANSIColor.coloring=falsealias_method:grey,:whitewhen2..8alias_method:grey,:white# rubocop:disable Lint/DuplicateMethodselsedefine_real_greyendrescueException=>e# rubocop:disable Lint/RescueExceptionife.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,:whiteelsedefine_real_greyendenddefself.define_real_grey#:nodoc:define_method:greydo|string|::Cucumber::Term::ANSIColor.coloring??"\e[90m#{string}\e[0m":stringendenddefine_greydefcukes(n)('(::) '*n).stripenddefgreen_cukes(n)blink(green(cukes(n)))enddefred_cukes(n)blink(red(cukes(n)))enddefyellow_cukes(n)blink(yellow(cukes(n)))endendendend