mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Tweeks on the color module
This commit is contained in:
@@ -46,13 +46,20 @@ module EdgeCase
|
|||||||
|
|
||||||
module Color
|
module Color
|
||||||
#shamelessly stolen (and modified) from redgreen
|
#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|
|
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
|
end
|
||||||
|
|
||||||
def self.colorize(string, color_value)
|
def colorize(string, color_value)
|
||||||
if ENV['NO_COLOR']
|
if ENV['NO_COLOR']
|
||||||
string
|
string
|
||||||
else
|
else
|
||||||
@@ -60,7 +67,7 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.color(color_value)
|
def color(color_value)
|
||||||
"\e[#{color_value}m"
|
"\e[#{color_value}m"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user