How to Create Curses-Based CLI Apps With Python
Introduction
I’ve been writing a lot of CLI-based Python apps lately, but they rely on ‘print’ statements and ‘input’ statements. This means there’s lots of scrolling. If you’ve ever used CLI programs before such as vi or nano, you don’t see that sort of scrolling: the cursor just moves around the screen cleanly. That’s because they’re written with a library called curses, or maybe ncurses. Understanding this dark magic will allow you to write similar applications that look a bit more professional than the scrolly ones that I make.
Installation
I’m starting off with the curses tutorial by DevDungeon found here.
It tells me that on Windows I need to install the curses library by doing this:
That was easy enough.
Basic Curses Script
This is the most basic curses script that the tutorial uses:
All this does is show a blank window for a few seconds, but it’s a start!