1from typing
import Union
3from .align
import AlignMethod
4from .cells
import cell_len, set_cell_size
5from .console
import Console, ConsoleOptions, RenderResult
6from .jupyter
import JupyterMixin
7from .measure
import Measurement
8from .style
import Style
13 """A console renderable to draw a horizontal rule (line).
16 title (Union[str, Text], optional): Text to render in the rule. Defaults to "".
17 characters (str, optional): Character(s) used to draw the line. Defaults to "─".
18 style (StyleType, optional): Style of Rule. Defaults to "rule.line".
19 end (str, optional): Character at end of Rule. defaults to "\\\\n"
20 align (str, optional): How to align the title, one of "left", "center", or "right". Defaults to "center".
25 title: Union[str, Text] =
"",
27 characters: str =
"─",
28 style: Union[str, Style] =
"rule.line",
30 align: AlignMethod =
"center",
32 if cell_len(characters) < 1:
34 "'characters' argument must have a cell width of at least 1"
36 if align
not in (
"left",
"center",
"right"):
38 f
'invalid value for align, expected "left", "center", "right" (not {align!r})'
47 return f
"Rule({self.title!r}, {self.characters!r})"
50 self, console: Console, options: ConsoleOptions
60 chars_len = cell_len(characters)
66 title_text = self.
title
73 required_space = 4
if self.
align ==
"center" else 2
74 truncate_width = max(0, width - required_space)
75 if not truncate_width:
80 if self.
align ==
"center":
83 left =
Text(characters * (side_width // chars_len + 1))
86 right =
Text(characters * (side_width // chars_len + 1))
91 elif self.
align ==
"left":
96 elif self.
align ==
"right":
112 self, console: Console, options: ConsoleOptions
117if __name__ ==
"__main__":
125 text =
"Hello, World"
None __init__(self, Union[str, Text] title="", *str characters="─", Union[str, Style] style="rule.line", str end="\n", AlignMethod align="center")
RenderResult __rich_console__(self, Console console, ConsoleOptions options)
Text _rule_line(self, int chars_len, int width)
Measurement __rich_measure__(self, Console console, ConsoleOptions options)