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