It's no surprise that a common question on the Textual Discord
server is how to go about producing plots in
the terminal. A popular solution that has been suggested is
Plotext. While Plotext doesn't
directly support Textual, it is easy to use with
and, because of this, we wanted to make it just as easy to use in your
TextArea is the latest widget to be added to Textual's growing collection.
It provides a multi-line space to edit text, and features optional syntax highlighting for a selection of languages.
Adding a TextArea to your Textual app is as simple as adding this to your compose method:
Enabling syntax highlighting for a language is as simple as:
Working on the TextArea widget for Textual taught me a lot about Python and my general
approach to software engineering. It gave me an appreciation for the subtle functionality behind
the editors we use on a daily basis — features we may not even notice, despite
some engineer spending hours perfecting it to provide a small boost to our development experience.
The Rich library has a few functions that are admittedly a little out of scope for a terminal color library. One such function is inspect which is so useful you may want to pip install rich just for this feature.
A (reasonable) criticism of async is that it tends to proliferate in your code. In order to await something, your functions must be async all the way up the call-stack. This tends to result in you making things async just to support that one call that needs it or, worse, adding async just-in-case. Given that going from def to async def is a breaking change there is a strong incentive to go straight there.
Before you know it, you have adopted a policy of "async all the things".
Every widget in Textual, be it a button, tree view, or a text input, runs an asyncio task. There is even a task for scrollbar corners (the little space formed when horizontal and vertical scrollbars meet).