Sean Zicari gave a good presentation discussing the terminal, ncurses and python and how to write a program to get random quotes and display them in your terminal. Of particular interest to me was building a UI in ncurses. ncurses is a very low level interface that allows you to do cursor positioning, text colour changes etc. but I was interested in programming at a slightly higher level than that. Sean demonstrates how the urwid python library can be used to take care of all the hard work.
In the video below there is a refactoring of the “fetch quote” code done using urwid for the ncurses layout. The code supplied in the video is not linked via the comments or description on YouTube so I have typed it out and it follows beneath the video.
Go make some cool stuff!
urwid implementation of quote fetcher:
You can see this script in action here - in particular note how urwid takes care of redrawing the screen when the font-size is increased resulting in less space to render the content. The words even wrap for you automatically.