Small demo proposal of integrating PyFiglet with Textual
Project description
A very simple demo of integrating PyFiglet into Textual
This demo was heavily inspired by https://patorjk.com/software/taag/
The key feature is to showcase how the text can actually change size with the terminal dynamically. Despite being ASCII art, the text will re-size and word-wrap with the terminal, just like normal text. It is also possible to change the font while the program is running.
Thanks to the great design of both Textual and PyFiglet, this was actually quite easy to implement.
The trick to this is that:
- It uses the
Staticwidget as a base, and integrates the PyFiglet class - It adds a
change_widthmethod to the widget - It over-rides the
rendermethod
First, use Textual's on_resize event to set the width:
async def on_resize(self, event):
"""Handle the terminal being resized."""
width, height = event.size
self.figlet_static.change_width(width-4) # the minus 4 is for padding
Connects to the change_width method in the widget:
def change_width(self, width: int) -> None:
self.figlet.width = width
Then finally, here is the render over-ride:
def render(self):
text = str(self.renderable)
self.set_styles("width: auto;")
return self.figlet.renderText(text)
Note that although there's only 11 fonts in the program (simple ones I hand picked), There's actually hundreds built in. FIGlet fonts have existed for a long time. Check out https://patorjk.com/software/taag/ for a more full-featured, browser-based Demo.
Thanks to:
https://github.com/pwaller/pyfiglet https://patorjk.com/ (https://github.com/patorjk)
And of course, Textual https://github.com/Textualize/textual
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for textual_pyfiglet_demo-0.1.0.tar.gz
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 2c8b5a9290f3966780a811951a22e72aca5218bf89a57f3e5d4d1d3ed37430f4 |
|
| MD5 | 18041d724ecba05992573bb281f793e2 |
|
| BLAKE2b-256 | 25f06f126ce4ce442e44bb1cdad92185aa8c8edcd87d240fc018dd597d6f6062 |
Hashes for textual_pyfiglet_demo-0.1.0-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | b7318a0eeadbd9c6381726af1aeef866ba6a669981f8d239cc4e25d72e80e56c |
|
| MD5 | 35559395afba24dc2c14a40263f0d704 |
|
| BLAKE2b-256 | 5991b9e061885eabd903e0da42ff00d3b3dad0691773d8bd38404810f889da44 |