Disabled colored output on windows.
authorJim Weirich <jim.weirich@gmail.com>
Thu, 21 Oct 2010 11:05:06 +0000 (07:05 -0400)
committerJim Weirich <jim.weirich@gmail.com>
Thu, 21 Oct 2010 11:05:06 +0000 (07:05 -0400)
koans/edgecase.rb
src/edgecase.rb

index 658da2e..c024438 100644 (file)
@@ -93,16 +93,29 @@ module EdgeCase
     end
 
     def colorize(string, color_value)
-      if ENV['NO_COLOR']
-        string
-      else
+      if use_colors?
         color(color_value) + string + color(COLORS[:clear])
+      else
+        string
       end
     end
 
     def color(color_value)
       "\e[#{color_value}m"
     end
+
+    def use_colors?
+      return false if ENV['NO_COLOR']
+      if ENV['ANSI_COLOR'].nil?
+        ! using_windows?
+      else
+        ENV['ANSI_COLOR'] =~ /^(t|y)/i
+      end
+    end
+
+    def using_windows?
+      File::ALT_SEPARATOR
+    end
   end
 
   class Sensei
index 658da2e..c024438 100644 (file)
@@ -93,16 +93,29 @@ module EdgeCase
     end
 
     def colorize(string, color_value)
-      if ENV['NO_COLOR']
-        string
-      else
+      if use_colors?
         color(color_value) + string + color(COLORS[:clear])
+      else
+        string
       end
     end
 
     def color(color_value)
       "\e[#{color_value}m"
     end
+
+    def use_colors?
+      return false if ENV['NO_COLOR']
+      if ENV['ANSI_COLOR'].nil?
+        ! using_windows?
+      else
+        ENV['ANSI_COLOR'] =~ /^(t|y)/i
+      end
+    end
+
+    def using_windows?
+      File::ALT_SEPARATOR
+    end
   end
 
   class Sensei