free_mutant/lib/mutant/color.rb

52 lines
823 B
Ruby
Raw Normal View History

2012-08-16 12:02:03 -04:00
module Mutant
# Class to colorize strings
class Color
2013-12-31 23:07:09 -05:00
include Adamantium::Flat, Concord.new(:code)
2012-08-16 12:02:03 -04:00
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]
# the argument string
2012-08-16 13:26:15 -04:00
#
# @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