IF you ever wanted to build rich User Interfaces that work in the terminal with mouse support written in Python, then Textual is the Library for you.
The framework is completely written in Python and supports CSS for styling. You can use the mouse or shortcut keys for navigation.
You may be asking why would you need a UI framework for the terminal, well to me here are some of the benefits:
- UI Applications that can be accessed through SSH
- Single point of maintenance similar to web applications
- No GUI dependencies
Yet it is still a work in progress according to the creator of Textual Will McGugan, so lets look at some examples of what can be done with Textual so far.
First lets install Textual using pip:
pip3 install textual
Once installed we can try out some examples which can be found in the Textual github repository (https://github.com/Textualize/textual). So let's clone the repo:
git clone https://github.com/Textualize/textual.git
Once cloned lets run some examples like the Calculator app:
cd textual/examples/ python3 calculator.py
You can either use your numpad/keyboard to enter in numbers or use your mouse by pointing and clicking right in your terminal. You will also notice that as you resize your terminal window the whole app adjusts to fit the screen size.
How about something a little more complicated like a code viewer:
Select the file you would like to view from the left-side file browser by clicking on it, you will then see the preview on the right-side. On the bottom bar you can either use your keyboard for the shortcut keys or click on the required function.
As you can see the potential with Textual is endless, your imagination is the limit. For inspiring ideas or to see some use-cases of Textual you can visit the Textual gallery