DEV Community

Nima
Nima

Posted on

How can I use Ruby to colorize the text output to a terminal?

You can use 'colortheme' gem to change the color of the text in Ruby.

install with gem

gem install colortheme
Enter fullscreen mode Exit fullscreen mode

install with git hub

git clone https://github.com/nimacpp/colortheme.git
cd colortheme
gem build colortheme.gemspec
gem install colortheme*.gem
Enter fullscreen mode Exit fullscreen mode

how can use

first include colortheme in your code :

require 'colortheme'
Enter fullscreen mode Exit fullscreen mode

then you can use it like this :

require 'colortheme'
puts "hello world".green 
Enter fullscreen mode Exit fullscreen mode

output :

A pie chart showing 40% responded "Yes", 50% responded "No" and 10% responded "Not sure"

list of colors in colortheme :

A pie chart showing 40% responded "Yes", 50% responded "No" and 10% responded "Not sure"
and we have light colors in version [1.5]

Top comments (0)