TTY Toolkit- A CLI App’s Best Friend
As an aspiring software developer, I always assumed that CLI applications would inevitably be clunky, aesthetically unappealing, and not very intuitive to use, because of their lack of any graphical user interface.
However, thanks to the TTY gem team, ruby developers are now able to add a little bit of flare and extra functionality to their CLI apps.
Below I have listed a few of my favorite components in the TTY Toolkit, and I hope they can inspire you to create the CLI app of your dreams!
Now, without further ado:
Pastel
First on the list is Pastel, a handy component for adding a flash of color to some of your CLI string outputs.

Add the gem “pastel” to your application’s Gemfile, and install using bundle. This convention of gem “tty-gem-name”, and bundle installing, is consistent throughout the Toolkit library.
gem "pastel"$ bundle
The usage for Pastel is very easy. Simply create a new instance of the Pastel class, set it to a variable, and use Pastel’s various color methods to add color to a string that puts out to your terminal.
pastel = Pastel.new
puts pastel.red("Unicorns!")
Font
Next up is Font, which uses some creative ASCII art to create different fonts for your CLI app landing page.

First initialize the font, passing in symbol argument referring to the font type:
font = TTY::Font.new(:doom)
and then print the text out to your console:
puts font.write("DOOM")
# =>
# ______ _____ _____ ___ ___
# | _ \| _ || _ || \/ |
# | | | || | | || | | || . . |
# | | | || | | || | | || |\/| |
# | |/ / \ \_/ /\ \_/ /| | | |
# |___/ \___/ \___/ \_| |_/
Here is a link to TTY’s complete list of available fonts.
Prompt
TTY:Prompt provides a straightforward and aesthetically pleasing way of receiving user input within the CLI.
Create your first prompt by requiring the gem component, and then initializing with a variable like so:
prompt = TTY::Prompt.new
Then call ask
with the question for simple input:
prompt.ask("What is your name?")
# => What is your name?
Ask questions with a list of options by using select
like so:
prompt.select("What is your star sign?", %w(Aries Taurus Gemini Cancer Leo Virgo Libra Scorpio Sagittarius Capricorn Aquarius Pisces))# =>
# What is your star sign? (Use ↑/↓ arrow keys, press Enter to select)
# ‣ Aries
# Taurus
# Gemini
# Cancer
# Leo
# Virgo
# Libra
# Scorpio
# Sagittarius
# Capricorn
# Aquarius
# Pisces
Pie
For any sort of data analysis CLI application, Pie could be super helpful for printing out your data in a very clear and visually accessible format.
To render a pie chart you need to provide an array of data items:
data = [{ name: "Brooklyn", value: 15, color: :bright_yellow, fill: "*" },{ name: "Queens", value: 8, color: :bright_green, fill: "x" },{ name: "Manhattan", value: 5, color: :bright_magenta, fill: "@" },{ name: "Bronx", value: 2, color: :bright_cyan, fill: "+" },{ name: "Jersey", value: 7, color: :bright_white, fill: "+" }]##Data gathered from a Flatiron School poll:
"Which borough do you live in?"
Then pass data to TTY::Pie instance with a given radius:
pie_chart = TTY::Pie.new(data: data, radius: 7)
and print the pie chart in your terminal window:

Hopefully a cursory overview of these 4 helpful TTY components will inspire you to dig deeper into the TTY Toolkit and make your own CLI applications more engaging, accessible, and fun for your users!
Of course, a huge thanks to Piotr Murach and the whole TTY Toolkit team for their tireless efforts and innovative coding!
Sources: