Skip to content

Instantly share code, notes, and snippets.

@eriksk
Created July 14, 2012 14:54
Show Gist options
  • Save eriksk/3111721 to your computer and use it in GitHub Desktop.
Save eriksk/3111721 to your computer and use it in GitHub Desktop.
CLI coloring
# 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
@eriksk
Copy link
Author

eriksk commented Jul 14, 2012

now realize that blue was not part of this example... But you probably get the point eh?
Also check out the colorizer gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment