Skip to content

Instantly share code, notes, and snippets.

@Eunoia
Last active December 10, 2015 11:08
Show Gist options
  • Save Eunoia/4425439 to your computer and use it in GitHub Desktop.
Save Eunoia/4425439 to your computer and use it in GitHub Desktop.
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