1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
# frozen_string_literal: true
module Unparser
# Class to colorize strings
class Color
include Adamantium, Concord.new(:code)
# Format text with color
#
# @param [String] text
#
# @return [String]
def format(text)
"\e[#{code}m#{text}\e[0m"
end
NONE = Class.new(self) do
# Format null color
#
# @param [String] text
#
# @return [String]
# the argument string
def format(text)
text
end
private
# Well rubocop you are static so you do not have a clue here ;)
# rubocop:disable Style/RedundantInitialize
# rubocop:disable Style/MissingSuper
def initialize; end
# rubocop:enable Style/RedundantInitialize
# rubocop:enable Style/MissingSuper
end.new
RED = Color.new(31)
GREEN = Color.new(32)
end # Color
end # Unparser
|