Created
October 19, 2012 15:03
-
-
Save michaelminter/3918696 to your computer and use it in GitHub Desktop.
Ruby globals for working with terminal ANSI color codes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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