Last active
December 10, 2015 11:08
-
-
Save Eunoia/4425439 to your computer and use it in GitHub Desktop.
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
class String | |
{ | |
:reset => 0, | |
:bold => 1, | |
:dark => 2, | |
:underline => 4, | |
:blink => 5, | |
:negative => 7, | |
:black => 30, | |
:red => 31, | |
:green => 32, | |
:yellow => 33, | |
:blue => 34, | |
:magenta => 35, | |
:cyan => 36, | |
:white => 37, | |
}.each do |key, value| | |
define_method key do | |
"\e[#{value}m" + self + "\e[0m" | |
end | |
end | |
end | |
=begin | |
Color output for the command line. Use this file to print strings in black,red,green,yellow,blue, magent, cyan, white, underlined and more. | |
puts "Hello World".blue.underline | |
Colorization should happen after all processing is done | |
puts "[Howdy]".gsub(/\W/,"").red | |
<br> | |
This won't work right because it removes the control characters that change color. | |
puts "[Howdy]".red.gsub(/\W/,"") | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment