free_mutant/lib/mutant/color.rb

66 lines
1,009 B
Ruby
Raw Normal View History

# encoding: utf-8
2012-08-16 12:02:03 -04:00
module Mutant
# Class to colorize strings
class Color
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
2013-07-28 14:14:29 -04:00
Mutant.singleton_subclass_instance('NONE', 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
#
2013-07-28 14:14:29 -04:00
def initialize
2012-08-28 05:16:23 -04:00
end
2013-07-28 14:14:29 -04:00
end
2012-08-16 12:02:03 -04:00
RED = Color.new(31)
GREEN = Color.new(32)
BLUE = Color.new(34)
2013-07-28 14:14:29 -04:00
2013-06-14 14:54:02 -04:00
end # Color
end # Mutant