How I integrated TTY::Prompt into my first CLI application

Iuliia Saprykina
2 min readApr 25, 2020

I started Software Engineering courses at Flatiron School in March of 2020 in Denver. My husband and I immigrated from Russia last year. I was very excited about these courses because this is my first year in the United States of America. And it is my first experience of any education in the USA.

My partner Lisa and I have been working on it together for the whole week!

Here is our Trail Less Traveled App:

Not too bad, is it?

To add more functionality to our app we decided to integrate TTY::Prompt tool. TTY::Prompt is a beautiful and powerful interactive command line prompt with a robust API for getting and validating complex inputs.

Before you can use this wonderful tool, you should set your gem files. There is a few very simple steps:

1. Add this line to your application’s Gemfile:

gem ‘tty-prompt’

2. Run in your Terminal

$bundle install

That’s it! Very simple!

Next, I put a global variable on the beginning of our cli.rb file, this needs due to we don’t want to write this code over and over again inside every method, where we want to use this tool:

As you see, I set an unusual marker. You can choose any of emoji that you like more, so I chose “Mountain ⛰️” . Just copy/paste the emoji that you like inside the value for the key “marker”.

Next steps: you just verifying this global variable $prompt inside each method where you want to use this tool. I wrote an $prompt.select(), which allows me to select one option from menu:

In the Terminal it looks like this:

You can use any of these different choices on TTY::Prompt. There is really a lot of different options of this cool tool!

So, don’t be afraid, just google it, and keep going!!! This is much easier than we think.

If you want, you can watch our very great presentation of our Trail Less Traveled App. Here is the link, enjoy!

--

--