Rule¶
The 'Rule` class is based off of the rich.rule.Rule class and is used to define a rule in gradient color and variable thickness.
Usage¶
from rich.console import Console
from rich_gradient.rule import Rule
console = Console()
console.print(
Rule(
"Hello, world!",
)
)
Alignment¶
The Rule class supports the same alignment options as the Rule class.
Left Aligned Rule¶
Right Aligned Rule¶
Center Aligned Rule¶
Note
The default behavior of rich_gradient.rule.Rule is center aligned.
Thickness¶
The Rule class supports configurable thickness. Valid integer values are:
thin(─)double(═)medium(━) (default)thick(█)
Thin Rule¶
Double-line Rule¶
Medium Rule¶
Thick Rule¶
Custom Colored Rule¶
To create a rule with custom colors, simply supply the colors parameter with a list of colors (as CSS color names, 3 or 6 digit hex codes, rich color names, or rgb color codes).
console.print(
Rule(
"This rule has custom colors!",
colors=[
"#f00", # red
"#f90", # orange
"#ff0", # yellow
"#9f0", # yellow-green
]
)
)
Rule(
"This rule has custom colors!",
colors=[
"#f00", # red
"#f90", # orange
"#ff0", # yellow
"#9f0", # yellow-green
]
)
)
Custom Title Style¶
If you would like some distinction between the rule and it's title, simply pass a rich style to the title_style parameter: