MCPcopy
hub / github.com/Textualize/rich / Rule

Class Rule

rich/rule.py:12–114  ·  view source on GitHub ↗

A console renderable to draw a horizontal rule (line). Args: title (Union[str, Text], optional): Text to render in the rule. Defaults to "". characters (str, optional): Character(s) used to draw the line. Defaults to "─". style (StyleType, optional): Style of Rule. Defau

Source from the content-addressed store, hash-verified

10
11
12class Rule(JupyterMixin):
13 """A console renderable to draw a horizontal rule (line).
14
15 Args:
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".
21 """
22
23 def __init__(
24 self,
25 title: Union[str, Text] = "",
26 *,
27 characters: str = "─",
28 style: Union[str, Style] = "rule.line",
29 end: str = "\n",
30 align: AlignMethod = "center",
31 ) -> None:
32 if cell_len(characters) < 1:
33 raise ValueError(
34 "'characters' argument must have a cell width of at least 1"
35 )
36 if align not in ("left", "center", "right"):
37 raise ValueError(
38 f'invalid value for align, expected "left", "center", "right" (not {align!r})'
39 )
40 self.title = title
41 self.characters = characters
42 self.style = style
43 self.end = end
44 self.align = align
45
46 def __repr__(self) -> str:
47 return f"Rule({self.title!r}, {self.characters!r})"
48
49 def __rich_console__(
50 self, console: Console, options: ConsoleOptions
51 ) -> RenderResult:
52 width = options.max_width
53
54 characters = (
55 "-"
56 if (options.ascii_only and not self.characters.isascii())
57 else self.characters
58 )
59
60 chars_len = cell_len(characters)
61 if not self.title:
62 yield self._rule_line(chars_len, width)
63 return
64
65 if isinstance(self.title, Text):
66 title_text = self.title
67 else:
68 title_text = console.render_str(self.title, style="rule.text")
69

Callers 13

test_rule_in_ratio_tableFunction · 0.90
test_spinner_updateFunction · 0.90
test_ruleFunction · 0.90
test_charactersFunction · 0.90
test_reprFunction · 0.90
test_errorFunction · 0.90
progress.pyFile · 0.85
rule.pyFile · 0.85
ruleMethod · 0.85
live.pyFile · 0.85

Calls

no outgoing calls

Tested by 8

test_rule_in_ratio_tableFunction · 0.72
test_spinner_updateFunction · 0.72
test_ruleFunction · 0.72
test_charactersFunction · 0.72
test_reprFunction · 0.72
test_errorFunction · 0.72