Skip to content

Commit bd65917

Browse files
committed
docs(readme): update README with new usage instructions
1 parent 0b8e411 commit bd65917

1 file changed

Lines changed: 101 additions & 44 deletions

File tree

README.md

Lines changed: 101 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,62 @@
66
[![Release Status](https://github.com/m-xim/textcompose/actions/workflows/release.yml/badge.svg)](https://github.com/m-xim/textcompose/actions)
77
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/m-xim/textcompose)
88

9-
**TextCompose** is a Python library for creating dynamic, structured text templates. Inspired by [aiogram-dialog](https://github.com/Tishka17/aiogram_dialog), it provides a flexible and intuitive interface for composing text.
9+
**TextCompose** is a Python library for creating dynamic, structured text templates with an intuitive, component-based approach. Inspired by [aiogram-dialog](https://github.com/Tishka17/aiogram_dialog).
1010

1111
---
1212

1313
## ✨ Features
1414

15-
- Flexible text composition from components
16-
- Conditional rendering support (`when`)
17-
- Grouping and repeating blocks
18-
- Formatting via f-string and Jinja2
19-
- Easily extensible with new components
20-
21-
15+
- 🧱 Flexible text composition from components
16+
- 🔀 Conditional rendering support (`when`)
17+
- 🔁 Grouping and repeating blocks
18+
- 🎨 Formatting via f-string and Jinja2
19+
- 🔌 Easily extensible with new components
2220

2321
## 🚀 Installation
2422

25-
You can install the library in two ways:
26-
27-
### Using `uv`
28-
If you are using the `uv` package manager, you can install it as follows:
2923
```bash
3024
uv add textcompose
31-
```
32-
33-
### Using `pip`
34-
```bash
25+
# or
3526
pip install textcompose
3627
```
3728

29+
## 🧩 Components Overview
3830

39-
## 💻 Usage
40-
41-
### Components Overview
42-
43-
#### General
31+
### General
4432

4533
- `Template` — main class for combining and rendering components
4634

4735

48-
#### Elements
36+
### Elements
4937
`Element` — abstract base class for all element components
5038

51-
- `Text` — outputs static text
52-
- `Format` — dynamic formatting via f-string
53-
- `Jinja` — rendering via Jinja2 templates
39+
- `Text` — static text.
40+
- `Format` — dynamic python f-string formatting
41+
- `Jinja` — Jinja2 template rendering
42+
- [`ProgressBar`](#progressbar) — show progress visually
5443

55-
#### Containers
44+
### Containers
5645
`Container` — abstract base class for all container components
5746

58-
- `Group`groups child components with a separator
59-
- `List`repeats a template for a collection
47+
- `Group`group children with custom separators.
48+
- `List`repeat templates for each item in a collection.
6049

61-
#### Logic Components
50+
### Logic Components
6251
`Logic` — abstract base class for all container components
6352

64-
- `If`conditional rendering (`if_`, `then_`, `else_`)
53+
- `If`conditionally show different blocks (use `if_`, `then_`, `else_`)
6554

66-
---
67-
All components support the `when` parameter — it controls the display of the component and accepts a condition (expression, function or magic_filter).
55+
> [!TIP]
56+
> All components support the `when` parameter for conditional display (value, expression, function, or magic_filter).
6857
69-
## 📝 Example
58+
## ⚡️ How to Use
7059

7160
All usage examples can be found in the [`example`](./example) folder.
7261

62+
### Quick Start
63+
See how easy it is to build structured, interactive text blocks:
64+
7365
```python
7466
from magic_filter import F
7567

@@ -82,21 +74,21 @@ template = Template(
8274
Format("Hello, {name}!"),
8375
Format("Status: {status}"), # or `lambda ctx: f"Status: {ctx['status']}"` with function
8476
If(
85-
F["notifications"] > 0, # `if_` - condition to check if there are notifications
86-
Format("You have {notifications} new notifications."), # `then_` - content to render if condition is True
87-
Format("You not have new notifications."), # `else_` - content to render if condition is False
77+
F["notifications"] > 0, # `if_`: condition to check if there are notifications
78+
Format("You have {notifications} new notifications."), # `then_`: content to render if condition is True
79+
Format("You not have new notifications."), # `else_`: content to render if condition is False
8880
),
8981
Group(
9082
Jinja("\nTotal messages {{ messages|length }}:"),
9183
List(
9284
Format("Time - {item[time]}:"),
9385
Format("- {item[text]}"),
94-
sep="\n", # `sep` - separator between list items
95-
inner_sep="\n", # `inner_sep` - separator between parts of a single item
96-
getter=lambda ctx: ctx["messages"], # `getter` - function or F to extract the list of messages from context
86+
sep="\n", # `sep`: separator between list items
87+
inner_sep="\n", # `inner_sep`: separator between parts of a single item
88+
getter=lambda ctx: ctx["messages"], # `getter`: function or F to extract the list of messages from context
9789
),
98-
sep="\n", # `sep` - separator between children of Group
99-
when=F["messages"].len() > 0, # `when` - show this block only if there are messages
90+
sep="\n", # `sep`: separator between children of Group
91+
when=F["messages"].len() > 0, # `when`: show this block only if there are messages
10092
),
10193
Text("\nThank you for using our service!"), # or "Recent messages:" without class
10294
)
@@ -129,8 +121,73 @@ Time - 18:42:
129121
Thank you for using our service!
130122
```
131123

132-
---
124+
### ProgressBar
133125

134-
## 👨‍💻 Contributing
126+
The `ProgressBar` component renders a textual progress bar. It supports various styles, customizable width, templates, and dynamic values.
127+
128+
#### Usage
129+
130+
```python
131+
from textcompose.elements import ProgressBar
132+
133+
bar = ProgressBar(
134+
current=42, # `current`: Current progress value
135+
total=100, # `total`: Total value for the progress bar
136+
width=20, # `width`: Number of characters in the bar.
137+
style="symbol_square", # `style`: Style (string — built-in style name, or `ProgressBarStyle` object).
138+
)
139+
print(bar.render({}))
140+
```
141+
142+
**Output:**
143+
```
144+
[■■■■■■■■ ] 42%
145+
```
146+
147+
#### Styles
148+
149+
Built-in styles are listed in the `PROGRESS_BAR_STYLES` dictionary (see [`textcompose/styles/progress_bar.py`](./textcompose/styles/progress_bar.py)). Examples:
150+
151+
- `"symbol_square"`: `[■■■■■ ]`
152+
- `"symbol_classic"`: `[#####-----]`
153+
- `"emoj_square"`: `🟩🟩🟩⬜⬜⬜`
154+
- `"emoji_circle"`: `🟢🟢⚪⚪⚪`
155+
156+
You can create a custom style using `ProgressBarStyle`:
157+
158+
```python
159+
from textcompose.styles import ProgressBarStyle
160+
from textcompose.elements import ProgressBar
161+
162+
163+
custom_style = ProgressBarStyle(
164+
left="<", fill="*", empty="-", right=">", template="{percent} {left}{bar}{right}"
165+
)
166+
bar = ProgressBar(current=7, total=10, width=10, style=custom_style)
167+
print(bar.render({}))
168+
```
169+
170+
**Output:**
171+
```
172+
70% <*******--->
173+
```
174+
175+
##### Template
176+
177+
The `template` parameter in the style allows you to customize the output string. Available placeholders:
178+
- `{left}` — left border
179+
- `{bar}` — the bar itself (filled + empty part)
180+
- `{right}` — right border
181+
- `{percent}` — percent complete (e.g., `42%`)
182+
- `{total}` — maximum value
183+
- `{current}` — current value
184+
185+
## 🤝 Contributing
186+
187+
💡 Ideas? Issues? PRs are welcome!<br>
188+
Open an issue or pull request to help TextCompose get even better.
189+
190+
---
135191

136-
Contributions are welcome! If you have suggestions or improvements, please open an issue or submit a pull request.
192+
> **Ready to supercharge your text formatting?<br>**
193+
> **Try TextCompose today and make your bots, reports, and notifications shine! ✨**

0 commit comments

Comments
 (0)