DEV Community

Cover image for Vamp up your CLI app with these!
Ellaine Tolentino
Ellaine Tolentino

Posted on • Updated on

Vamp up your CLI app with these!

Welcome! Are you looking into adding your own style into your CLI application? I found these resources you can use to add pizzaz to your project!

I stumbled upon these while I was looking into features I can add to upgrade my old CLI app project after graduating from Flatiron School. I have built this project with a classmate for our Phase 1 pair-programming project.

If you're curious about how I've used these to update the app, here's a demo video of the project called FootballFanatic!

If you've seen the demo, the first feature you'll notice that I added to my CLI app is the welcome banner.

ASCII Art

You can generate your very own banner by using some ASCII Art Generator.

gif showing ASCII generator

See other sources below can also generate some cool ASCII text art and designs!

ASCII Art Archives
TAAG - Patorjk
Christopher Johnson's ASCII Art Collection

Once you picked one, or multiple arts you like, you can directly place it on your code as a string just like this:

puts "
    █▀▀ █▀█ █▀█ ▀█▀ █▄▄ ▄▀█ █░░ █░░ █▀▀ ▄▀█ █▄░█ ▄▀█ ▀█▀ █ █▀▀
    █▀░ █▄█ █▄█ ░█░ █▄█ █▀█ █▄▄ █▄▄ █▀░ █▀█ █░▀█ █▀█ ░█░ █ █▄▄"
Enter fullscreen mode Exit fullscreen mode

Background music

YES! You can add a cool background music of your choice into your CLI app!

The one I chose for mines is William Rosati's "Floating Also"
But definitely, you can choose any audio you like as your background music. Download it into your local machine and save it into your project. In my case, I saved it into my lib file.Alt Text

Now we have the audio, how do we play it?

We need to use an audio player command!

Now you add this piece of code to a function. Location matters since you want this triggered on a certain part of the application. With mine, I added it just right before the banner.

fork{ exec ‘afplay’, “file_path” }
Enter fullscreen mode Exit fullscreen mode

It should look something like this...
code for audio play

Since we now know how to start the music, we have to know how to stop it too! Well, you're in luck!

We can just add a 'kill all audio' command using this line of code!

fork{ exec ‘killall’, “afplay” }
Enter fullscreen mode Exit fullscreen mode

I placed this code inside the function that get's triggered when the user exits the app.
In code, this is what it looks like...
code for stopping audio

If you want to know more about audio manipulation using your CLI application, here are some links to check out.

Guide to manipulate audio

Manipulating audio on your Mac terminal

Voice

DID YOU KNOW YOU CAN MAKE YOUR TERMINAL SPEAK?

You've heard that voice from the demo that when I booted up the app it said "Welcome to Football Fanatic" right? Yes! It is also fairly easy to do since it is one of the built-in commands of a Mac terminal!
This line of code will do the trick!

`say Welcome to Football Fanatic`
Enter fullscreen mode Exit fullscreen mode

The command 'say' is a built-in function on your Mac that converts text to speech.
For Windows, you can look into PTTS, this GitHub repo, or this [stackoverflow] post that suggests one-line solutions(https://stackoverflow.com/questions/1040655/ms-speech-from-command-line)

In code, it should look like this if it's inside of my welcome function..

code sample

You see that "-v 'princess'" in that line of code?
YOU CAN ALSO CHANGE THE VOICE TO MALE OR FEMALE!

That's right! Mac has accessibility features that let you choose a different voice!

  • Go to System Preference
  • Click Accessibility
  • Click Speech
  • Click the dropdown where it says System Voice
    Alt Text

  • You can download more type of voice and use them on your CLI app;
    Alt Text

So if you wanted to use 'Samantha' as the voice..

`say -v 'samantha' Hello`
Enter fullscreen mode Exit fullscreen mode

More details on different tricks your system voice can do can be found on this blog

Colored text

The last thing I used on my project is the Colorize gem
Very easy to use just install the gem, and add the command after every string you want to be colored.
Just like this;

"Hello world!".colorize(:green)
Enter fullscreen mode Exit fullscreen mode

Here's what it looks like in my code:
code sample about colorize gem

And that is it!
That is all I used to add some upgrades to my CLI app!

Thank you for taking your time to read my blog!
Until the next!

MORE RESOURCES:
FootballFanatic repo
FootballFanatic's Beta Version

Top comments (0)