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]
|
2012-08-16 18:02:03 +02:00
|
|
|
def format(text)
|
2015-11-16 11:40:28 -08:00
|
|
|
"\e[#{code}m#{text}\e[0m"
|
2012-08-16 18:02:03 +02:00
|
|
|
end
|
|
|
|
|
2015-06-13 13:36:32 +00:00
|
|
|
NONE = Class.new(self) do
|
2013-07-28 20:14:29 +02:00
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Format null color
|
|
|
|
#
|
|
|
|
# @param [String] text
|
|
|
|
#
|
|
|
|
# @return [String]
|
2013-09-11 20:48:44 +02:00
|
|
|
# the argument string
|
2012-08-16 18:02:03 +02:00
|
|
|
def format(text)
|
|
|
|
text
|
|
|
|
end
|
2012-08-28 11:16:23 +02:00
|
|
|
|
2016-03-19 12:35:50 -07:00
|
|
|
private # rubocop:disable AccessModifierIndentation
|
2012-08-28 11:16:23 +02:00
|
|
|
|
|
|
|
# Initialize null color
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
2013-07-28 20:14:29 +02:00
|
|
|
def initialize
|
2012-08-28 11:16:23 +02:00
|
|
|
end
|
|
|
|
|
2015-06-13 13:36:32 +00:00
|
|
|
end.new
|
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
|