Permalink
Browse files

Merge pull request #22 from hron/introduce-optional-colors

Introduce reflection on --color option.
  • Loading branch information...
2 parents 3b7a27e + fa6ae7c commit 62f8e426690f52237f0738f5014657e4aa3496c6 @nashby nashby committed Aug 5, 2012
Showing with 18 additions and 7 deletions.
  1. +18 −7 lib/cucumber/formatter/fuubar.rb
@@ -1,4 +1,5 @@
require 'cucumber/formatter/console'
+require 'cucumber/formatter/ansicolor'
require 'cucumber/formatter/io'
require 'ruby-progressbar'
@@ -17,9 +18,9 @@ def initialize(step_mother, path_or_io, options)
def after_features(features)
@state = :red if step_mother.scenarios(:failed).any?
- @io.print COLORS[state]
- @progress_bar.finish
- @io.print "\e[0m"
+ with_colors(COLORS[state]) do
+ @progress_bar.finish
+ end
@io.puts
@io.puts
print_summary(features)
@@ -42,7 +43,7 @@ def after_step_result(keyword, step_match, multiline_arg, status, exception, sou
return if @in_background || status == :skipped
@state = :red if status == :failed
if exception and [:failed, :undefined].include? status
- @io.print "\e[K"
+ @io.print "\e[K" if colors_enabled?
@issues_count += 1
@io.puts
@io.puts "#{@issues_count})"
@@ -87,9 +88,9 @@ def print_summary(features)
COLORS = { :green => "\e[32m", :yellow => "\e[33m", :red => "\e[31m" }
def progress(status = 'passed', count = 1)
- @io.print COLORS[state]
- @progress_bar.progress += count
- @io.print "\e[0m"
+ with_colors(COLORS[state]) do
+ @progress_bar.progress += count
+ end
end
def get_step_count(features)
@@ -122,6 +123,16 @@ def get_step_count(features)
end
return count
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

0 comments on commit 62f8e42

Please sign in to comment.