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

list of colors in colortheme :

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs