From 71f670ac1d9ca1cf590b394d9ff789630e14e5da Mon Sep 17 00:00:00 2001 From: Jim Weirich Date: Thu, 21 Oct 2010 07:05:06 -0400 Subject: [PATCH] Disabled colored output on windows. --- koans/edgecase.rb | 19 ++++++++++++++++--- src/edgecase.rb | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/koans/edgecase.rb b/koans/edgecase.rb index 658da2e..c024438 100644 --- a/koans/edgecase.rb +++ b/koans/edgecase.rb @@ -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 diff --git a/src/edgecase.rb b/src/edgecase.rb index 658da2e..c024438 100644 --- a/src/edgecase.rb +++ b/src/edgecase.rb @@ -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