rich-format


Namerich-format JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/pom11/rich_format
SummaryFormat rich Text
upload_time2023-04-25 13:25:04
maintainer
docs_urlNone
authorpom11
requires_python>=3.6
licenseMIT license
keywords rich
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # rich_format
[![PyPI](https://img.shields.io/pypi/v/rich_format.svg)](https://pypi.org/project/rich_format/) [![PyPI](https://img.shields.io/pypi/pyversions/rich_format.svg)](https://img.shields.io/pypi/pyversions/rich_format.svg)

`rich_format` replicates python string formatting for rich `Text` instances adding the possibility to substitute also with `Text`.

```python
>>> 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](https://github.com/pom11/rich_format/blob/main/rich_format/test.py).


## Usage
First you need to import `Text` from rich so that `rich_format` works.
```python
from rich.text import Text
import rich_format
```

### Textual
You can use `rich_format` in `textual` to format easier `reactive` in custom widgets

`rich_format.demo`

```python
from textual.reactive import reactive
from textual.app import App, ComposeResult
from textual.widgets import Footer
from textual.widgets import Static
from rich.text import Text
import rich_format
import random

city = [
    Text.from_markup("from [blue on red]London[/]"),
    Text.from_markup("from [magenta on blue]New York[/]"),
    Text.from_markup("from [green]Bucharest[/]"),
    Text.from_markup("from [red on white]Tokyo[/]")
]

class CustomHeader(Static):
    banner : Text = reactive(Text(""))
    world : str = reactive("")

    def __init__(self, template: str) -> None:
        self.template = template
        super().__init__()

    def watch_banner(self, banner: Text) -> None:
        self.update(banner)

    def watch_world(self, world: str) -> None:
        self.banner = Text(self.template).format(world=world)

class DemoApp(App):

    BINDINGS = [
    ("q","quit","Quit"),
    ("h", "toggle_header", "Random header")
    ]

    def compose(self) -> ComposeResult:
        yield CustomHeader(template="Hello {world}")
        yield Footer()

    def action_toggle_header(self) -> None:
        widget = self.query_one(CustomHeader)
        widget.world = random.choice(city)


if __name__ == "__main__":
    app = DemoApp()
    app.run()
```

## Installation
### Stable release - pypi
To install `rich_format` run this command in your terminal
```bash
pip install rich_format
```
### From sources
The sources for rich_format can be downloaded from [Github](https://github.com/pom11/rich_format)
* clone the public repository
```bash
git clone https://github.com/pom11/rich_format
```
* install from source
```bash
python setup.py install
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pom11/rich_format",
    "name": "rich-format",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "rich",
    "author": "pom11",
    "author_email": "office@parsecom.ro",
    "download_url": "https://files.pythonhosted.org/packages/19/e8/931829637bf9d01e6d7edf4aed8a03592c80c3ceb01a6eec8d11f98ee460/rich_format-0.0.4.tar.gz",
    "platform": null,
    "description": "# rich_format\n[![PyPI](https://img.shields.io/pypi/v/rich_format.svg)](https://pypi.org/project/rich_format/) [![PyPI](https://img.shields.io/pypi/pyversions/rich_format.svg)](https://img.shields.io/pypi/pyversions/rich_format.svg)\n\n`rich_format` replicates python string formatting for rich `Text` instances adding the possibility to substitute also with `Text`.\n\n```python\n>>> from rich.console import Console\n>>> from rich.text import Text\n>>> import rich_format\n>>> console = Console()\n>>> text = Text(\"Hello {name}\",style=\"red on white\")\n>>> formatted_text = t.format(name=Text(\"pom11\"))\n>>> console.print(text)\nHello {name}\n>>> console.print(formatted_text)\nHello pom11\n```\nSee more examples running `rich_format.test`  or inspect [this](https://github.com/pom11/rich_format/blob/main/rich_format/test.py).\n\n\n## Usage\nFirst you need to import `Text` from rich so that `rich_format` works.\n```python\nfrom rich.text import Text\nimport rich_format\n```\n\n### Textual\nYou can use `rich_format` in `textual` to format easier `reactive` in custom widgets\n\n`rich_format.demo`\n\n```python\nfrom textual.reactive import reactive\nfrom textual.app import App, ComposeResult\nfrom textual.widgets import Footer\nfrom textual.widgets import Static\nfrom rich.text import Text\nimport rich_format\nimport random\n\ncity = [\n    Text.from_markup(\"from [blue on red]London[/]\"),\n    Text.from_markup(\"from [magenta on blue]New York[/]\"),\n    Text.from_markup(\"from [green]Bucharest[/]\"),\n    Text.from_markup(\"from [red on white]Tokyo[/]\")\n]\n\nclass CustomHeader(Static):\n    banner : Text = reactive(Text(\"\"))\n    world : str = reactive(\"\")\n\n    def __init__(self, template: str) -> None:\n        self.template = template\n        super().__init__()\n\n    def watch_banner(self, banner: Text) -> None:\n        self.update(banner)\n\n    def watch_world(self, world: str) -> None:\n        self.banner = Text(self.template).format(world=world)\n\nclass DemoApp(App):\n\n    BINDINGS = [\n    (\"q\",\"quit\",\"Quit\"),\n    (\"h\", \"toggle_header\", \"Random header\")\n    ]\n\n    def compose(self) -> ComposeResult:\n        yield CustomHeader(template=\"Hello {world}\")\n        yield Footer()\n\n    def action_toggle_header(self) -> None:\n        widget = self.query_one(CustomHeader)\n        widget.world = random.choice(city)\n\n\nif __name__ == \"__main__\":\n    app = DemoApp()\n    app.run()\n```\n\n## Installation\n### Stable release - pypi\nTo install `rich_format` run this command in your terminal\n```bash\npip install rich_format\n```\n### From sources\nThe sources for rich_format can be downloaded from [Github](https://github.com/pom11/rich_format)\n* clone the public repository\n```bash\ngit clone https://github.com/pom11/rich_format\n```\n* install from source\n```bash\npython setup.py install\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Format rich Text",
    "version": "0.0.4",
    "split_keywords": [
        "rich"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ccbf51320ab70b12cc862ac45ee0f24936d08c44aa48c344fa2a5283a79aa9b",
                "md5": "015ac88acf8338c812153bb114637e61",
                "sha256": "f4739bfb55f0c0d8bc247a8301c67d8f4eb59ad44b59a00633baa1372d05dff4"
            },
            "downloads": -1,
            "filename": "rich_format-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "015ac88acf8338c812153bb114637e61",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7019,
            "upload_time": "2023-04-25T13:24:57",
            "upload_time_iso_8601": "2023-04-25T13:24:57.680670Z",
            "url": "https://files.pythonhosted.org/packages/6c/cb/f51320ab70b12cc862ac45ee0f24936d08c44aa48c344fa2a5283a79aa9b/rich_format-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19e8931829637bf9d01e6d7edf4aed8a03592c80c3ceb01a6eec8d11f98ee460",
                "md5": "fe2885c8240d2c8da4804df51485e15e",
                "sha256": "907a2de05c96e741d8bdf9a33cdfc477e94611422a1a89ef7bf8796e2b34a4a5"
            },
            "downloads": -1,
            "filename": "rich_format-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "fe2885c8240d2c8da4804df51485e15e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5781,
            "upload_time": "2023-04-25T13:25:04",
            "upload_time_iso_8601": "2023-04-25T13:25:04.826203Z",
            "url": "https://files.pythonhosted.org/packages/19/e8/931829637bf9d01e6d7edf4aed8a03592c80c3ceb01a6eec8d11f98ee460/rich_format-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-25 13:25:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "pom11",
    "github_project": "rich_format",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rich-format"
}
        
Elapsed time: 0.07252s