From bc1a20a31043b4f3776b9dd80dd8fe595e528385 Mon Sep 17 00:00:00 2001 From: Jim Weirich Date: Fri, 27 Aug 2010 09:25:10 -0400 Subject: [PATCH] Tweeks on the color module --- src/edgecase.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/edgecase.rb b/src/edgecase.rb index 3c9a949..99cefc7 100644 --- a/src/edgecase.rb +++ b/src/edgecase.rb @@ -46,13 +46,20 @@ module EdgeCase module Color #shamelessly stolen (and modified) from redgreen - COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36 } + COLORS = { + :clear => 0, :black => 30, :red => 31, + :green => 32, :yellow => 33, :blue => 34, + :magenta => 35, :cyan => 36, + } + + module_function COLORS.each do |color, value| - class_eval "def self.#{color}(string); colorize(string, #{value}); end" + module_eval "def #{color}(string); colorize(string, #{value}); end" + module_function color end - def self.colorize(string, color_value) + def colorize(string, color_value) if ENV['NO_COLOR'] string else @@ -60,7 +67,7 @@ module EdgeCase end end - def self.color(color_value) + def color(color_value) "\e[#{color_value}m" end end