Skip to content

Commit b0ec087

Browse files
committed
README + examples
1 parent 6f3d665 commit b0ec087

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,47 @@ Currently this is just proof of concept. I will likely add to this over time.
3535

3636
# Examples
3737
See `examples` directory for examples of using this.
38+
39+
One of the fundamental aspects of this library is the ability to preload your own custom styles from a dictionary, like so:
40+
```python
41+
from rich.console import Console
42+
from src.string_builder import RichStyles
43+
44+
console = Console()
45+
46+
my_styles = {
47+
"alert": "blink yellow",
48+
"headers": {
49+
"main": "bold",
50+
"sub": "#4196D6"
51+
}
52+
}
53+
rs = RichStyles(my_styles)
54+
console.print(rs.custom.alert("WARNING!")) # '[blink yellow]WARNING![/blink yellow]'
55+
```
56+
57+
Though you are able to combine these styles ad-hoc:
58+
59+
```python
60+
bright_blue = rs.Styles.bright + rs.Colors.blue
61+
console.print(bright_blue("Coldkey")) # '[bright blue]Coldkey[/bright blue]'
62+
```
63+
64+
Say you have a complicated custom style, and you wish to only remove an element or two and reuse it:
65+
```python
66+
my_styles = {
67+
"foo": "blink bright yellow"
68+
}
69+
rs = RichStyles(my_styles)
70+
console.print((rs.custom.foo - "blink")("Hello!")) # '[bright yellow]Hello![/bright yellow]'
71+
# or define a new type:
72+
bar = rs.custom.foo - "blink"
73+
console.print(bar("Hello!")) # '[bright yellow]Hello![/bright yellow]'
74+
```
75+
76+
77+
# Who is this for?
78+
I am personally colourblind. It's nice to have someone who is not colourblind define a colour palette, and I simply
79+
build from this. While colourblind people are not the only intended users, I think it will help them (us) substantially
80+
in terms of readability of the styles.
81+
It's also very helpful for keeping easier track of your styles and reusability.

examples/combinations.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from src.string_builder import RichStyles
2+
3+
4+
def combinations():
5+
rs = RichStyles()
6+
bright_yellow = rs.Styles.bright + rs.Colors.yellow
7+
expected = "[bright yellow]Hello, World![/bright yellow]"
8+
actual = bright_yellow("Hello, World!")
9+
assert actual == expected

0 commit comments

Comments
 (0)