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

nimacpp

Nima

Posted on September 23, 2022

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

list of colors in colortheme :

A pie chart showing 40% responded
and we have light colors in version [1.5]

💖 💪 🙅 🚩
nimacpp
Nima

Posted on September 23, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related