Yesterday, i read @nish2005karsh 's interesting post on making Python terminal apps look better with ASCII art and progress bars. I first thought about adding a comment with more styling tools, but then figured, 'Why not make it an article?' So, here’s my very first piece, packed with my advice for adding some personality to your terminal applications.
introduction
Terminal applications have always fascinated me. I remember watching 80s sci-fi movies with my parents as a kid; every time the hacker needed to 'breach' a system or crack into something, they’d be hammering away at those almost surreal command-line interfaces, often seen in scientific labs filled with glowing CRT monitors. Think of iconic examples like Ghost in the Shell, Blade Runner, The Matrix, and so on – all those luminous characters on a dark screen just had a certain mystique to me.
So, when I started developing actual CLI apps, I immediately tried to 'juice them up', and I found it surprising how much some easy-to-use libraries can make the entire experience – both the UI and UX – so much more enjoyable and friendly. That's why this article won't just be about visual flair (UI), but also about the overall user experience (UX).
ASCII art
Many apps use ASCII art banners as the very first thing you see when they run – a great way to make an impression. In the post I mentioned before, the author uses pyfiglet and does something like this:
import pyfiglet
# Create an ASCII banner with your app's name
ascii_banner = pyfiglet.figlet_format("Your App Name")
print(ascii_banner)
With pyfiglet, you can also easily change the font style:
print(pyfiglet.figlet_format("text to render", font="slant"))
But sometimes, just creating text banners isn't enough. What if you want to convert an actual image into ASCII art, or perhaps add some stylish borders to your text.
asciiart.eu
A fantastic online tool for this is asciiart.eu. It's excellent for converting both text to ASCII and, images to ASCII. The site offers an incredible array of tools and parameters you can tweak to get just the right look.
survey
Next up is survey. This is a Python toolkit that provides interactive widgets for your CLI, such as sortable and filterable menus, or masked input for passwords. It has several useful features, so the best way to explore them all is to check out the official documentation.
To give you a better idea, here's a glimpse from survey's documentation:
Adding interactive elements like these can make your CLI much more navigable and significantly improves the overall user experience.
glow
Next, let's talk about glow. As its tagline suggests, it's designed to simply "Render markdown on the CLI." This is incredibly useful for displaying formatted text, like README files or documentation, directly in your terminal.
glow is a standalone program that you can typically install using your system's package manager.
For example on arch is :
pacman -S glow
To integrate glow into your Python application and display a Markdown, you can use the os.system call like this:
## make sure glow is available on the machine
if glow_available:
try:
os.system(f'glow "{file_with_markdown_to_display}"')
textwrap
Next, we have Python's built-in textwrap module. As the name suggests, its primary purpose is to wrap text output neatly within the terminal, preventing long lines from overflowing and improving readability.
The great thing about textwrap is that it's part of Python's standard library, so there's no need for any separate installation. You can use it right away:
import textwrap
your_long_string = "This is a very long string that would normally exceed the typical terminal width and look messy if not wrapped properly. Textwrap helps us manage this."
# Wrap the string to a maximum width of 80 characters
wrapped_text = textwrap.fill(your_long_string, width=80)
print(wrapped_text)
rich
rich is so feature-packed that it might even feel like 'overkill' for very simple tasks. However, this extensive capability means you can do almost anything you can imagine with terminal styling and layout.
Given its breadth, the best approach is to explore its excellent documentation and pick out the specific components or features you need for your particular application.
The official documentation includes a cool cheat sheet:
Practical example
To show how these tools can work together effectively and bring some "juice" to a real application, I'd like to share a mini-project I developed a few months ago. It's a command-line interface (CLI) called cj, designed to let you interact with the Gemini AI chat directly from your terminal. It uses glow, and survey, and also alot of os.system('clear')
.
Feel free to explore the source code, see how it's put together, or even install it from its GitHub repository here.
Top comments (1)
Wow, I’m really honored that my post inspired your article! 🙌
I just read it — and it’s packed with awesome tips and style ideas I hadn’t explored yet. The community definitely needs more of this kind of creative energy in terminal apps! 😄
Thanks again for the mention, and looking forward to seeing more from you. !!