free_mutant/lib/mutant/color.rb

54 lines
842 B
Ruby
Raw Normal View History

# encoding: utf-8
2012-08-16 18:02:03 +02:00
module Mutant
# Class to colorize strings
class Color
2014-01-01 05:07:09 +01:00
include Adamantium::Flat, Concord.new(:code)
2012-08-16 18:02:03 +02:00
2012-08-16 19:26:15 +02:00
# Format text with color
#
# @param [String] text
#
# @return [String]
#
# @api private
#
2012-08-16 18:02:03 +02:00
def format(text)
"\e[#{@code}m#{text}\e[0m"
end
2013-07-28 20:14:29 +02:00
Mutant.singleton_subclass_instance('NONE', self) do
2012-08-16 19:26:15 +02:00
# Format null color
#
# @param [String] text
#
# @return [String]
# the argument string
2012-08-16 19:26:15 +02:00
#
# @api private
#
2012-08-16 18:02:03 +02:00
def format(text)
text
end
2012-08-28 11:16:23 +02:00
private
# Initialize null color
#
# @return [undefined]
#
# @api private
#
2013-07-28 20:14:29 +02:00
def initialize
2012-08-28 11:16:23 +02:00
end
2013-07-28 20:14:29 +02:00
end
2012-08-16 18:02:03 +02:00
RED = Color.new(31)
GREEN = Color.new(32)
BLUE = Color.new(34)
2013-07-28 20:14:29 +02:00
2013-06-14 20:54:02 +02:00
end # Color
end # Mutant