The Startup
Published in

The Startup

Tips and Tricks: Making your Ruby CLI application cute!

Bring in the gems!

Command Line Applications aren’t exactly known for their visual design. After all, there’s no CSS, and the interface itself is quite limited. This guide is for those of us still intent on making our CLI applications as appealing and ~cute~ as possible despite the limitations.

Add color with Colorize

Colorize is a Ruby Gem that allows you to add formatting like color, underlining, and a background-fill to your text. Check it out:

It really makes a huge difference in the design and readability of your app… provided that you don’t just throw every single color option on the screen at once. Speaking of, the color options Colorize offers are:

:black, :light_black, :red, :light_red, :green,:light_green, :yellow, :light_yellow, :blue, :light_blue, :light_green, :yellow, :light_yellow, :blue, :light_blue, :magenta, :light_magenta, :cyan, :light_cyan, :white, :light_white

Add sound

Bet you didn’t think your command-line can talk? Well, not only can you make it say stuff, you can make it play any audio file you can get your hands on. Here’s how:

To speak:

`say "hello world!"`

To play a music file:

puts `afplay 'lib/music/pokemon_theme_song.mp3'`

That’s it, go crazy with the Youtube-to-MP3 converter (legally, of course)!

Streamline your UI with TTY::Prompt

Less glamorous, but no less important is TTY::Prompt. This gem streamlines how the user interacts with your app. As the name suggests, it’s all about prompting the user — something you’ll likely be doing a lot of in a CLI app.

TTY::Prompt allows the user to scroll through and select options with their keyboard. Making it perfect for creating menus easily. It also offers features like multi-select, multiple choice and many, many more.

TTY::Prompt in action!

This gem also makes it super easy to extract and manipulate user input however you wish. You don’t need to use a bunch of if/else or case statements to get user input ever again (well at least not in your Ruby CLI app).

Tried and true… ASCII Art!

Most people are familiar with ASCII art — it’s art that’s made entirely of ASCII characters. While people do actually treat it as a genuine art form and make their own from scratch, not everyone has the time (or talent) for that. Enter converters:

  • Image to ASCII Converter allows you to convert any image into an ASCII image. It’s pretty great. Keep in mind — because ASCII art depends on characters to create it, it looks better at a larger size. Decreasing the size of an ASCII art image drastically decreases visibility. Major tip: After pasting your ASCII art inside your code editor, press CMD Z, this will undo auto-formatting.
I converted an image of Pikachu for this ASCII art
I used the the Text Converter for my app logo!

Bonus Tip: If you want to keep a logo or piece of art on screen while clearing the terminal, just re-render your ASCII art every time you clear. I recommend creating a clear method that does both, like so:

def self.clear    system "clear"    Ascii.logoend

Resources mentioned — and more:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store