Format rich Text
Project description
rich_format
rich_format
replicates python string formatting for rich Text
instances adding the possibility to substitute also with Text
.
>>> from rich.console import Console
>>> from rich.text import Text
>>> import rich_format
>>> console = Console()
>>> text = Text("Hello {name}",style="red on white")
>>> formatted_text = t.format(name=Text("pom11"))
>>> console.print(text)
Hello {name}
>>> console.print(formatted_text)
Hello pom11
See more examples running rich_format.test
or inspect this.
Usage
First you need to import Text
from rich so that rich_format
works.
from rich.text import Text
import rich_format
Textual
You can use rich_format
in textual
to format easier reactive
in custom widgets
class Footer(Static):
banner : Text = reactive(Text("Hello {world}"))
world : str = reactive("world")
def watch_banner(self, banner: Text) -> None:
self.update(banner)
def watch_world(self, world: str) -> None:
self.banner = self.banner.format(world=world)
Installation
Stable release - pypi
To install rich_format
run this command in your terminal
pip install rich_format
From sources
The sources for rich_format can be downloaded from Github
- clone the public repository
git clone https://github.com/pom11/rich_format
- install from source
python setup.py install
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rich_format-0.0.2.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for rich_format-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 647fd7536401e748f42fa5e7ad49ad4556d214e4be663ff0af0e2f5bb3747d89 |
|
MD5 | fbf0697be534f207d2b10f34d14d0540 |
|
BLAKE2b-256 | a048f995099daec98f6ae0fbb176f6ba2470769161adff4acd625eb8cde02a90 |