Skip to content

Instantly share code, notes, and snippets.

@michaelminter
Created October 19, 2012 15:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelminter/3918696 to your computer and use it in GitHub Desktop.
Save michaelminter/3918696 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment