2012-08-16 12:02:03 -04:00
|
|
|
module Mutant
|
|
|
|
# Class to colorize strings
|
|
|
|
class Color
|
2012-11-02 21:12:33 -04:00
|
|
|
include Adamantium::Flat
|
2012-08-16 12:02:03 -04:00
|
|
|
|
2012-08-16 13:26:15 -04:00
|
|
|
# Initialize color object
|
|
|
|
#
|
|
|
|
# @param [Fixnum] code
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 12:02:03 -04:00
|
|
|
def initialize(code)
|
|
|
|
@code = code
|
|
|
|
end
|
|
|
|
|
2012-08-16 13:26:15 -04:00
|
|
|
# Format text with color
|
|
|
|
#
|
|
|
|
# @param [String] text
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 12:02:03 -04:00
|
|
|
def format(text)
|
|
|
|
"\e[#{@code}m#{text}\e[0m"
|
|
|
|
end
|
|
|
|
|
|
|
|
NONE = Class.new(self) do
|
2012-08-16 13:26:15 -04:00
|
|
|
# Format null color
|
|
|
|
#
|
|
|
|
# @param [String] text
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
# returns the argument string
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 12:02:03 -04:00
|
|
|
def format(text)
|
|
|
|
text
|
|
|
|
end
|
2012-08-28 05:16:23 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Initialize null color
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(*)
|
|
|
|
end
|
|
|
|
|
2012-08-16 12:02:03 -04:00
|
|
|
end.new.freeze
|
|
|
|
|
|
|
|
RED = Color.new(31)
|
|
|
|
GREEN = Color.new(32)
|
|
|
|
BLUE = Color.new(34)
|
|
|
|
end
|
|
|
|
end
|