Created
July 14, 2012 14:54
-
-
Save eriksk/3111721 to your computer and use it in GitHub Desktop.
CLI coloring
This file contains 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
# super simple way of coloring console output with ruby | |
# we extend string so we can simply call the method of the color on string literals, like so: | |
"This text should be blue!".blue | |
# and it will output a blue text string! | |
class String | |
# colorization | |
def colorize(text, color_code) | |
"\e[#{color_code}m#{text}\e[0m" | |
end | |
def red | |
colorize(self, 31) | |
end | |
def green | |
colorize(self, 32) | |
end | |
def yellow | |
colorize(self, 33) | |
end | |
def pink | |
colorize(self, 35) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now realize that blue was not part of this example... But you probably get the point eh?
Also check out the colorizer gem.