Vamp up your CLI app with these!
Tags: beginners, cli, codenewbie
Published: 2021-04-04 05:08:40



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!**

{% youtube U66aECUWbTQ %}

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](https://fsymbols.com/text-art/). 

<img src="https://media.giphy.com/media/1ZkipPIGiM7RDB3Cng/giphy.gif" alt="gif showing ASCII generator" />

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

[ASCII Art Archives](https://www.asciiart.eu/)
[TAAG - Patorjk] (https://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20)
[Christopher Johnson's ASCII Art Collection](https://asciiart.website/index.php)

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

``` 
puts "
    █▀▀ █▀█ █▀█ ▀█▀ █▄▄ ▄▀█ █░░ █░░ █▀▀ ▄▀█ █▄░█ ▄▀█ ▀█▀ █ █▀▀
    █▀░ █▄█ █▄█ ░█░ █▄█ █▀█ █▄▄ █▄▄ █▀░ █▀█ █░▀█ █▀█ ░█░ █ █▄▄"
```


##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"](https://www.youtube.com/watch?v=ncR2P6qE04c 
)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ey323qw4yloryuz5kpdy.png)

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” }
``` 
It should look something like this...
![code for audio play](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/loisbacnevhyykisa03l.png)

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” }
```
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hregq2e1pv96u6s83ju.png)

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

[Guide to manipulate audio](https://simplemitch.wordpress.com/2020/02/20/afplay-definitive-guide-to-manipulating-audio-in-your-cli-application-ruby/)

[Manipulating audio on your Mac terminal](https://medium.com/@sedwardscode/manipulating-audio-using-the-mac-terminal-a7b87c516b7a)

##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`
``` 
The command 'say' is a built-in function on your Mac that converts text to speech. 
*For Windows, you can look into [PTTS](https://itectec.com/superuser/os-x-say-command-for-windows/),  this [GitHub](https://github.com/technogeek48/winsay) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2op0oqfjzpdu11gmlta.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvpaexicm6wmhh4yomco.png)

- You can download more type of voice and use them on your CLI app;
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kw9wajbbiwqmgaz7hsq5.png)

So if you wanted to use 'Samantha' as the voice..
```
`say -v 'samantha' Hello`
```
More details on different tricks your system voice can do can be found on this [blog](https://www.lifewire.com/mac-say-command-with-talking-terminal-2260772)
##Colored text##

The last thing I used on my project is the [Colorize gem](https://github.com/fazibear/colorize)
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)
```
Here's what it looks like in my code:
![code sample about colorize gem](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bdymzsyt532pi3z95l22.png)

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](https://github.com/tolentinoel/footballFanatic)
[FootballFanatic's Beta Version](vhttps://github.com/stephenvincentibanez/project1_songkick/tree/master)