Created
December 16, 2010 17:24
-
-
Save hawx/743687 to your computer and use it in GitHub Desktop.
Add colour to your output.
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
# Usage: | |
# | |
# puts green("I'm green") | |
# puts red("I'm red") | |
# puts bold("I'm bold") | |
# | |
def colour(text, code) | |
"#{code}#{text}\e[0m" | |
end | |
{ | |
"bold" => "1", | |
"underline" => "4", | |
"blink" => "5", | |
"white" => "37", | |
"green" => "32", | |
"red" => "31", | |
"magenta" => "35", | |
"yellow" => "33", | |
"blue" => "34", | |
"grey" => "90" | |
}.each do |name, code| | |
define_method(name) do |text| | |
colour(text, "\e[#{code}m") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment