How can I make the puts commands I output from a commandline based ruby program colour? I would appreciated any references to how I call each different colour also.
Lets say we start with this..
puts "The following word is blue.. Im Blue!"
puts "The following word is green.. Im Green!"
puts "The following word is red.. Im Red!"
And I get different text I want in different colours I want, You get the idea.
Im using Ubuntu, would I need to change my approach so that the program outputs correctly in diff os?
My suggestion: The paint gem. It does not enforce string extensions and supports 256-colors (with fall-back mode for non-256-color terminals).
Usage:
I found this article describing a very easy way to write coloured texts to the console. The article describes this little example which seems to do the trick (I took the liberty to improve it slightly):
Best seems to define some of the colours. You can extent the example when you need also different background colours (see bottom of article).
When using Window XP, the author mentions the requirement of a gem called win32console.
Check out the cli-colorize gem: http://github.com/stjohncj/cli-colorize/blob/master/README.rdoc
I find the Colored gem to be the easiest and cleanest to use.