Skip to content

Commit

Permalink
Merge pull request #22 from hron/introduce-optional-colors
Browse files Browse the repository at this point in the history
Introduce reflection on --color option.
  • Loading branch information
nashby committed Aug 5, 2012
2 parents 3b7a27e + fa6ae7c commit 62f8e42
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/cucumber/formatter/fuubar.rb
@@ -1,4 +1,5 @@
require 'cucumber/formatter/console' require 'cucumber/formatter/console'
require 'cucumber/formatter/ansicolor'
require 'cucumber/formatter/io' require 'cucumber/formatter/io'
require 'ruby-progressbar' require 'ruby-progressbar'


Expand All @@ -17,9 +18,9 @@ def initialize(step_mother, path_or_io, options)


def after_features(features) def after_features(features)
@state = :red if step_mother.scenarios(:failed).any? @state = :red if step_mother.scenarios(:failed).any?
@io.print COLORS[state] with_colors(COLORS[state]) do
@progress_bar.finish @progress_bar.finish
@io.print "\e[0m" end
@io.puts @io.puts
@io.puts @io.puts
print_summary(features) print_summary(features)
Expand All @@ -42,7 +43,7 @@ def after_step_result(keyword, step_match, multiline_arg, status, exception, sou
return if @in_background || status == :skipped return if @in_background || status == :skipped
@state = :red if status == :failed @state = :red if status == :failed
if exception and [:failed, :undefined].include? status if exception and [:failed, :undefined].include? status
@io.print "\e[K" @io.print "\e[K" if colors_enabled?
@issues_count += 1 @issues_count += 1
@io.puts @io.puts
@io.puts "#{@issues_count})" @io.puts "#{@issues_count})"
Expand Down Expand Up @@ -87,9 +88,9 @@ def print_summary(features)
COLORS = { :green => "\e[32m", :yellow => "\e[33m", :red => "\e[31m" } COLORS = { :green => "\e[32m", :yellow => "\e[33m", :red => "\e[31m" }


def progress(status = 'passed', count = 1) def progress(status = 'passed', count = 1)
@io.print COLORS[state] with_colors(COLORS[state]) do
@progress_bar.progress += count @progress_bar.progress += count
@io.print "\e[0m" end
end end


def get_step_count(features) def get_step_count(features)
Expand Down Expand Up @@ -122,6 +123,16 @@ def get_step_count(features)
end end
return count return count
end end

def with_colors(color, &block)
@io.print color if colors_enabled?
yield
@io.print "\e[0m" if colors_enabled?
end

def colors_enabled?
Cucumber::Term::ANSIColor.coloring?
end
end end
end end
end end

0 comments on commit 62f8e42

Please sign in to comment.