Module: QuietQuality::Colorize

Defined in:
lib/quiet_quality/colorize.rb

Constant Summary collapse

CODES =
{
  red: "\e[31m",
  green: "\e[32m",
  yellow: "\e[33m",
  light_blue: "\e[94m",
  light_cyan: "\e[96m"
}.freeze
RESET_CODE =
"\e[0m"

Class Method Summary collapse

Class Method Details

.colorize(s, color:) ⇒ Object



13
14
15
16
17
# File 'lib/quiet_quality/colorize.rb', line 13

def self.colorize(s, color:)
  fail(ArgumentError, "Unrecognized color '#{color}'") unless CODES.include?(color.to_sym)
  color_code = CODES.fetch(color.to_sym)
  "#{color_code}#{s}#{RESET_CODE}"
end