Command Line programs are something that every aspiring software developer has to get hands dirty with, almost without an exception. Then are some who go on to write more CLI programs.
In last few days I’ve been attempting to make CLI programs in Ruby and here are some tricks that I have learned that I think will immediately improve the experience of end users of anyone’s cli program if it’s implemented with even minimum thought.
Making Command Line Less Ugly
One of the things that have almost always bothered me about command line is how linearly interaction takes place. Everything regardless of how important something is gets scrolled up every every output. This results in either user to retype the command over and over again just to see what has gone too far up or simply two side by side terminals.
Yesterday, I found out that there is a way for CLI apps developers to tackle this problem. UI/UX deals with human interaction, it’s a part, in a chain, of such importance that if it fails then no matter how great the rest of app is, it’s destined to be life of mediocrity.
Clear command line to mimic GUI applications
What you do is that you tell Ruby to tell terminal to clear itself after every put by using code like this:
Show progress by updating existing line and not printing new line
At lots of occasions there are times when progress needs to be shown in some form,
however printing stream of everything that’s happening makes for dizzying user experience.
I found that
resets the “cursor” to front of the line and everything you type will overwrite the existing output..
Colorize Output appropriately
There are also ways to colorize output messages in terminal. There is a gem called “colorize” that simplifies it greatly. Coloring output is an easy way to give priority to important parts of the output. However, it’s important to understand wider audience not all have white background and black/white or white/black as background and text color makes for highest contrast. High Contrast is good for readability and so on.
puts "some message".red
puts "some message".red.on_yellow
puts "some message".blink