[rspec-devel] --colour with progress bar

KAKUTANI Shintaro shintaro at kakutani.com
Thu Oct 5 07:07:22 EDT 2006


Hello, everyone.

Thaks for RSpec 0.6.4 release and its '--color' option is great!!
(I'm a grren bar lover.)

I want to see colorized texts not only on summary line but on progress bar.
Following patch represents what I want to :

Index: progress_bar_formatter.rb
===================================================================
--- progress_bar_formatter.rb	(revision 855)
+++ progress_bar_formatter.rb	(working copy)
@@ -8,12 +8,26 @@
         end
       
         def spec_failed(name, counter, failure)
-          @output << 'F'
+          prompt = 'F'
+          if @colour && @output == STDOUT
+            colour_prefix = "\e[31m"
+            colour_postfix = "\e[0m"
+          else
+            colour_prefix = colour_postfix = ""
+          end
+          @output << "#{colour_prefix}#{prompt}#{colour_postfix}"
           @output.flush
         end
       
         def spec_passed(name)
-          @output << '.'
+          prompt = '.'
+          if @colour && @output == STDOUT
+            colour_prefix = "\e[32m"
+            colour_postfix = "\e[0m"
+          else
+            colour_prefix = colour_postfix = ""
+          end
+          @output << "#{colour_prefix}#{prompt}#{colour_postfix}"          
           @output.flush
         end
       
@@ -24,4 +38,4 @@
       end
     end
   end
-end
\ No newline at end of file
+end


More information about the rspec-devel mailing list