Method: rich.rule.Rule.__rich_console__
Calls: 29, Exceptions: 0, Paths: 6Back
Path 1: 10 calls (0.34)
Console (10)
ConsoleOptions (10)
Text (10)
None (10)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 width = options.max_width
5
6 # Python3.6 doesn't have an isascii method on str
7 isascii = getattr(str, "isascii", None) or (
8 lambda s: all(ord(c) < 128 for c in s)
9 )
10 characters = (
11 "-"
12 if (options.ascii_only and not isascii(self.characters))
13 else self.characters
14 )
15
16 chars_len = cell_len(characters)
17 if not self.title:
18 yield self._rule_line(chars_len, width)
19 return
20
21 if isinstance(self.title, Text):
22 title_text = self.title
23 else:
24 title_text = console.render_str(self.title, style="rule.text")
25
26 title_text.plain = title_text.plain.replace("\n", " ")
27 title_text.expand_tabs()
28
29 required_space = 4 if self.align == "center" else 2
30 truncate_width = max(0, width - required_space)
31 if not truncate_width:
32 yield self._rule_line(chars_len, width)
33 return
34
35 rule_text = Text(end=self.end)
36 if self.align == "center":
37 title_text.truncate(truncate_width, overflow="ellipsis")
38 side_width = (width - cell_len(title_text.plain)) // 2
39 left = Text(characters * (side_width // chars_len + 1))
40 left.truncate(side_width - 1)
41 right_length = width - cell_len(left.plain) - cell_len(title_text.plain)
42 right = Text(characters * (side_width // chars_len + 1))
43 right.truncate(right_length)
44 rule_text.append(left.plain + " ", self.style)
45 rule_text.append(title_text)
46 rule_text.append(" " + right.plain, self.style)
47 elif self.align == "left":
48 title_text.truncate(truncate_width, overflow="ellipsis")
49 rule_text.append(title_text)
50 rule_text.append(" ")
51 rule_text.append(characters * (width - rule_text.cell_len), self.style)
52 elif self.align == "right":
53 title_text.truncate(truncate_width, overflow="ellipsis")
54 rule_text.append(characters * (width - title_text.cell_len - 1), self.style)
55 rule_text.append(" ")
56 rule_text.append(title_text)
57
58 rule_text.plain = set_cell_size(rule_text.plain, width)
59 yield rule_text
Path 2: 7 calls (0.24)
Console (7)
ConsoleOptions (7)
Text (7) None (7)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 width = options.max_width
5
6 # Python3.6 doesn't have an isascii method on str
7 isascii = getattr(str, "isascii", None) or (
8 lambda s: all(ord(c) < 128 for c in s)
9 )
10 characters = (
11 "-"
12 if (options.ascii_only and not isascii(self.characters))
13 else self.characters
14 )
15
16 chars_len = cell_len(characters)
17 if not self.title:
18 yield self._rule_line(chars_len, width)
19 return
20
21 if isinstance(self.title, Text):
22 title_text = self.title
23 else:
24 title_text = console.render_str(self.title, style="rule.text")
25
26 title_text.plain = title_text.plain.replace("\n", " ")
27 title_text.expand_tabs()
28
29 required_space = 4 if self.align == "center" else 2
30 truncate_width = max(0, width - required_space)
31 if not truncate_width:
32 yield self._rule_line(chars_len, width)
33 return
34
35 rule_text = Text(end=self.end)
36 if self.align == "center":
37 title_text.truncate(truncate_width, overflow="ellipsis")
38 side_width = (width - cell_len(title_text.plain)) // 2
39 left = Text(characters * (side_width // chars_len + 1))
40 left.truncate(side_width - 1)
41 right_length = width - cell_len(left.plain) - cell_len(title_text.plain)
42 right = Text(characters * (side_width // chars_len + 1))
43 right.truncate(right_length)
44 rule_text.append(left.plain + " ", self.style)
45 rule_text.append(title_text)
46 rule_text.append(" " + right.plain, self.style)
47 elif self.align == "left":
48 title_text.truncate(truncate_width, overflow="ellipsis")
49 rule_text.append(title_text)
50 rule_text.append(" ")
51 rule_text.append(characters * (width - rule_text.cell_len), self.style)
52 elif self.align == "right":
53 title_text.truncate(truncate_width, overflow="ellipsis")
54 rule_text.append(characters * (width - title_text.cell_len - 1), self.style)
55 rule_text.append(" ")
56 rule_text.append(title_text)
57
58 rule_text.plain = set_cell_size(rule_text.plain, width)
59 yield rule_text
Path 3: 5 calls (0.17)
Console (5)
ConsoleOptions (5)
Text (5)
None (5)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 width = options.max_width
5
6 # Python3.6 doesn't have an isascii method on str
7 isascii = getattr(str, "isascii", None) or (
8 lambda s: all(ord(c) < 128 for c in s)
9 )
10 characters = (
11 "-"
12 if (options.ascii_only and not isascii(self.characters))
13 else self.characters
14 )
15
16 chars_len = cell_len(characters)
17 if not self.title:
18 yield self._rule_line(chars_len, width)
19 return
20
21 if isinstance(self.title, Text):
22 title_text = self.title
23 else:
24 title_text = console.render_str(self.title, style="rule.text")
25
26 title_text.plain = title_text.plain.replace("\n", " ")
27 title_text.expand_tabs()
28
29 required_space = 4 if self.align == "center" else 2
30 truncate_width = max(0, width - required_space)
31 if not truncate_width:
32 yield self._rule_line(chars_len, width)
33 return
34
35 rule_text = Text(end=self.end)
36 if self.align == "center":
37 title_text.truncate(truncate_width, overflow="ellipsis")
38 side_width = (width - cell_len(title_text.plain)) // 2
39 left = Text(characters * (side_width // chars_len + 1))
40 left.truncate(side_width - 1)
41 right_length = width - cell_len(left.plain) - cell_len(title_text.plain)
42 right = Text(characters * (side_width // chars_len + 1))
43 right.truncate(right_length)
44 rule_text.append(left.plain + " ", self.style)
45 rule_text.append(title_text)
46 rule_text.append(" " + right.plain, self.style)
47 elif self.align == "left":
48 title_text.truncate(truncate_width, overflow="ellipsis")
49 rule_text.append(title_text)
50 rule_text.append(" ")
51 rule_text.append(characters * (width - rule_text.cell_len), self.style)
52 elif self.align == "right":
53 title_text.truncate(truncate_width, overflow="ellipsis")
54 rule_text.append(characters * (width - title_text.cell_len - 1), self.style)
55 rule_text.append(" ")
56 rule_text.append(title_text)
57
58 rule_text.plain = set_cell_size(rule_text.plain, width)
59 yield rule_text
Path 4: 3 calls (0.1)
Console (3)
ConsoleOptions (3)
Text (3) None (3)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 width = options.max_width
5
6 # Python3.6 doesn't have an isascii method on str
7 isascii = getattr(str, "isascii", None) or (
8 lambda s: all(ord(c) < 128 for c in s)
9 )
10 characters = (
11 "-"
12 if (options.ascii_only and not isascii(self.characters))
13 else self.characters
14 )
15
16 chars_len = cell_len(characters)
17 if not self.title:
18 yield self._rule_line(chars_len, width)
19 return
20
21 if isinstance(self.title, Text):
22 title_text = self.title
23 else:
24 title_text = console.render_str(self.title, style="rule.text")
25
26 title_text.plain = title_text.plain.replace("\n", " ")
27 title_text.expand_tabs()
28
29 required_space = 4 if self.align == "center" else 2
30 truncate_width = max(0, width - required_space)
31 if not truncate_width:
32 yield self._rule_line(chars_len, width)
33 return
34
35 rule_text = Text(end=self.end)
36 if self.align == "center":
37 title_text.truncate(truncate_width, overflow="ellipsis")
38 side_width = (width - cell_len(title_text.plain)) // 2
39 left = Text(characters * (side_width // chars_len + 1))
40 left.truncate(side_width - 1)
41 right_length = width - cell_len(left.plain) - cell_len(title_text.plain)
42 right = Text(characters * (side_width // chars_len + 1))
43 right.truncate(right_length)
44 rule_text.append(left.plain + " ", self.style)
45 rule_text.append(title_text)
46 rule_text.append(" " + right.plain, self.style)
47 elif self.align == "left":
48 title_text.truncate(truncate_width, overflow="ellipsis")
49 rule_text.append(title_text)
50 rule_text.append(" ")
51 rule_text.append(characters * (width - rule_text.cell_len), self.style)
52 elif self.align == "right":
53 title_text.truncate(truncate_width, overflow="ellipsis")
54 rule_text.append(characters * (width - title_text.cell_len - 1), self.style)
55 rule_text.append(" ")
56 rule_text.append(title_text)
57
58 rule_text.plain = set_cell_size(rule_text.plain, width)
59 yield rule_text
Path 5: 3 calls (0.1)
Console (3)
ConsoleOptions (3)
Text (3) None (3)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 width = options.max_width
5
6 # Python3.6 doesn't have an isascii method on str
7 isascii = getattr(str, "isascii", None) or (
8 lambda s: all(ord(c) < 128 for c in s)
9 )
10 characters = (
11 "-"
12 if (options.ascii_only and not isascii(self.characters))
13 else self.characters
14 )
15
16 chars_len = cell_len(characters)
17 if not self.title:
18 yield self._rule_line(chars_len, width)
19 return
20
21 if isinstance(self.title, Text):
22 title_text = self.title
23 else:
24 title_text = console.render_str(self.title, style="rule.text")
25
26 title_text.plain = title_text.plain.replace("\n", " ")
27 title_text.expand_tabs()
28
29 required_space = 4 if self.align == "center" else 2
30 truncate_width = max(0, width - required_space)
31 if not truncate_width:
32 yield self._rule_line(chars_len, width)
33 return
34
35 rule_text = Text(end=self.end)
36 if self.align == "center":
37 title_text.truncate(truncate_width, overflow="ellipsis")
38 side_width = (width - cell_len(title_text.plain)) // 2
39 left = Text(characters * (side_width // chars_len + 1))
40 left.truncate(side_width - 1)
41 right_length = width - cell_len(left.plain) - cell_len(title_text.plain)
42 right = Text(characters * (side_width // chars_len + 1))
43 right.truncate(right_length)
44 rule_text.append(left.plain + " ", self.style)
45 rule_text.append(title_text)
46 rule_text.append(" " + right.plain, self.style)
47 elif self.align == "left":
48 title_text.truncate(truncate_width, overflow="ellipsis")
49 rule_text.append(title_text)
50 rule_text.append(" ")
51 rule_text.append(characters * (width - rule_text.cell_len), self.style)
52 elif self.align == "right":
53 title_text.truncate(truncate_width, overflow="ellipsis")
54 rule_text.append(characters * (width - title_text.cell_len - 1), self.style)
55 rule_text.append(" ")
56 rule_text.append(title_text)
57
58 rule_text.plain = set_cell_size(rule_text.plain, width)
59 yield rule_text
Path 6: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Text (1) None (1)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 width = options.max_width
5
6 # Python3.6 doesn't have an isascii method on str
7 isascii = getattr(str, "isascii", None) or (
8 lambda s: all(ord(c) < 128 for c in s)
9 )
10 characters = (
11 "-"
12 if (options.ascii_only and not isascii(self.characters))
13 else self.characters
14 )
15
16 chars_len = cell_len(characters)
17 if not self.title:
18 yield self._rule_line(chars_len, width)
19 return
20
21 if isinstance(self.title, Text):
22 title_text = self.title
23 else:
24 title_text = console.render_str(self.title, style="rule.text")
25
26 title_text.plain = title_text.plain.replace("\n", " ")
27 title_text.expand_tabs()
28
29 required_space = 4 if self.align == "center" else 2
30 truncate_width = max(0, width - required_space)
31 if not truncate_width:
32 yield self._rule_line(chars_len, width)
33 return
34
35 rule_text = Text(end=self.end)
36 if self.align == "center":
37 title_text.truncate(truncate_width, overflow="ellipsis")
38 side_width = (width - cell_len(title_text.plain)) // 2
39 left = Text(characters * (side_width // chars_len + 1))
40 left.truncate(side_width - 1)
41 right_length = width - cell_len(left.plain) - cell_len(title_text.plain)
42 right = Text(characters * (side_width // chars_len + 1))
43 right.truncate(right_length)
44 rule_text.append(left.plain + " ", self.style)
45 rule_text.append(title_text)
46 rule_text.append(" " + right.plain, self.style)
47 elif self.align == "left":
48 title_text.truncate(truncate_width, overflow="ellipsis")
49 rule_text.append(title_text)
50 rule_text.append(" ")
51 rule_text.append(characters * (width - rule_text.cell_len), self.style)
52 elif self.align == "right":
53 title_text.truncate(truncate_width, overflow="ellipsis")
54 rule_text.append(characters * (width - title_text.cell_len - 1), self.style)
55 rule_text.append(" ")
56 rule_text.append(title_text)
57
58 rule_text.plain = set_cell_size(rule_text.plain, width)
59 yield rule_text