michaelminter
10/19/2012 - 3:03 PM

Ruby globals for working with terminal ANSI color codes

Ruby globals for working with terminal ANSI color codes

CLEAR   = "\e[0m"
BOLD    = "\e[1m"

# Colors
BLACK   = "\e[30m"
RED     = "\e[31m"
GREEN   = "\e[32m"
YELLOW  = "\e[33m"
BLUE    = "\e[34m"
MAGENTA = "\e[35m"
CYAN    = "\e[36m"
WHITE   = "\e[37m"

def color(text, color, bold=false)
  return text unless colorize_logging
  color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
  bold  = bold ? BOLD : ""
  "#{bold}#{color}#{text}#{CLEAR}"
end