command line - How to output my ruby commandline text in different colours -
how can make puts commands output commandline based ruby program colour? appreciated references how call each different colour also.
lets start this..
puts "the following word blue.. im blue!" puts "the following word green.. im green!" puts "the following word red.. im red!"
and different text want in different colours want, idea.
im using ubuntu, need change approach program outputs correctly in diff os?
i found this article describing easy way write coloured texts console. article describes little example seems trick (i took liberty improve slightly):
def colorize(text, color_code) "\e[#{color_code}m#{text}\e[0m" end def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end # actual example puts 'importing categories [ ' + green('done') + ' ]' puts 'importing tags [' + red('failed') + ']'
best seems define of colours. can extent example when need different background colours (see bottom of article).
when using window xp, author mentions requirement of gem called win32console.
Comments
Post a Comment