Have you heard of rich?
Honestly, I don’t remember how long I’ve been following Will’s work,
but I find it very interesting and educational. Among Will’s work are
rich and textual, both projects designed to extend the
use of the terminal.
One thing you can see in Will’s work is the modular design. On one hand,
there’s rich, which basically gives you the necessary tools to format console
output to your liking, making the console output clearer and more attractive.
Then we have textual, a framework for making TUIs (terminal user
interfaces) that depends on rich. The value of textual is not only
being able to create TUIs in Python easily and elegantly, but also that the TUI
you develop could run in a web browser! The same application can run in the
terminal or in the browser. This is music to the ears of many backends.
Textual apps running in a browser!
— Will McGugan (@willmcgugan) August 12, 2023
I intentionally obscured the address bar, as I'm not quite ready to share the dev URL. pic.twitter.com/7ztn7r8G0o
The most immediate use I can think of is that I could write many internal applications easily that I can share with the team, regardless of the hacking skills of my team members.
The Textual web service signup dialog is looking good. Now to implement the backend. pic.twitter.com/2z2wqRQi54
— Will McGugan (@willmcgugan) August 15, 2023
What do you use rich for?
rich has a series of ready-to-use functions that you can take advantage of
without having to build anything additionally.
Better print
rich has made me love using print again. I no longer use the built-in
print, but use rich’s:
| |
For example, print(my_json) with rich, the output is much more elegant and
readable than using pprint. Other examples are print(my_list),
print(my_dict), etc.
Better Logging
| |
Better Traceback
| |
DIY
Then you have a series of objects with which you can build really useful and
beautiful console outputs, such as columns, tables, layouts, etc.
In the documentation, you have everything you need to get started.
Just try it, you will enjoy the output.