Path 1: 19 calls (0.29)

Console (19)

ConsoleOptions (19)

Segment (2957) None (19)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        _padding = Padding.unpack(self.padding)
5        renderable = (
6            Padding(self.renderable, _padding) if any(_padding) else self.renderable
7        )
8        style = console.get_style(self.style)
9        border_style = style + console.get_style(self.border_style)
10        width = (
11            options.max_width
12            if self.width is None
13            else min(options.max_width, self.width)
14        )
15
16        safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
17        box = self.box.substitute(options, safe=safe_box)
18
19        def align_text(
20            text: Text, width: int, align: str, character: str, style: Style
21        ) -> Text:
22            """Gets new aligned text.
23
24            Args:
25                text (Text): Title or subtitle text.
26                width (int): Desired width.
27                align (str): Alignment.
28                character (str): Character for alignment.
29                style (Style): Border style
30
31            Returns:
32                Text: New text instance
33            """
34            text = text.copy()
35            text.truncate(width)
36            excess_space = width - cell_len(text.plain)
37            if excess_space:
38                if align == "left":
39                    return Text.assemble(
40                        text,
41                        (character * excess_space, style),
42                        no_wrap=True,
43                        end="",
44                    )
45                elif align == "center":
46                    left = excess_space // 2
47                    return Text.assemble(
48                        (character * left, style),
49                        text,
50                        (character * (excess_space - left), style),
51                        no_wrap=True,
52                        end="",
53                    )
54                else:
55                    return Text.assemble(
56                        (character * excess_space, style),
57                        text,
58                        no_wrap=True,
59                        end="",
60                    )
61            return text
62
63        title_text = self._title
64        if title_text is not None:
65            title_text.stylize_before(border_style)
66
67        child_width = (
68            width - 2
69            if self.expand
70            else console.measure(
71                renderable, options=options.update_width(width - 2)
72            ).maximum
73        )
74        child_height = self.height or options.height or None
75        if child_height:
76            child_height -= 2
77        if title_text is not None:
78            child_width = min(
79                options.max_width - 2, max(child_width, title_text.cell_len + 2)
80            )
81
82        width = child_width + 2
83        child_options = options.update(
84            width=child_width, height=child_height, highlight=self.highlight
85        )
86        lines = console.render_lines(renderable, child_options, style=style)
87
88        line_start = Segment(box.mid_left, border_style)
89        line_end = Segment(f"{box.mid_right}", border_style)
90        new_line = Segment.line()
91        if title_text is None or width <= 4:
92            yield Segment(box.get_top([width - 2]), border_style)
93        else:
94            title_text = align_text(
95                title_text,
96                width - 4,
97                self.title_align,
98                box.top,
99                border_style,
100            )
101            yield Segment(box.top_left + box.top, border_style)
102            yield from console.render(title_text, child_options.update_width(width - 4))
103            yield Segment(box.top + box.top_right, border_style)
104
105        yield new_line
106        for line in lines:
107            yield line_start
108            yield from line
109            yield line_end
110            yield new_line
111
112        subtitle_text = self._subtitle
113        if subtitle_text is not None:
114            subtitle_text.stylize_before(border_style)
115
116        if subtitle_text is None or width <= 4:
117            yield Segment(box.get_bottom([width - 2]), border_style)
118        else:
119            subtitle_text = align_text(
120                subtitle_text,
121                width - 4,
122                self.subtitle_align,
123                box.bottom,
124                border_style,
125            )
126            yield Segment(box.bottom_left + box.bottom, border_style)
127            yield from console.render(
128                subtitle_text, child_options.update_width(width - 4)
129            )
130            yield Segment(box.bottom + box.bottom_right, border_style)
131
132        yield new_line
            

Path 2: 18 calls (0.27)

Console (18)

ConsoleOptions (18)

Segment (1539) None (18)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        _padding = Padding.unpack(self.padding)
5        renderable = (
6            Padding(self.renderable, _padding) if any(_padding) else self.renderable
7        )
8        style = console.get_style(self.style)
9        border_style = style + console.get_style(self.border_style)
10        width = (
11            options.max_width
12            if self.width is None
13            else min(options.max_width, self.width)
14        )
15
16        safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
17        box = self.box.substitute(options, safe=safe_box)
18
19        def align_text(
20            text: Text, width: int, align: str, character: str, style: Style
21        ) -> Text:
22            """Gets new aligned text.
23
24            Args:
25                text (Text): Title or subtitle text.
26                width (int): Desired width.
27                align (str): Alignment.
28                character (str): Character for alignment.
29                style (Style): Border style
30
31            Returns:
32                Text: New text instance
33            """
34            text = text.copy()
35            text.truncate(width)
36            excess_space = width - cell_len(text.plain)
37            if excess_space:
38                if align == "left":
39                    return Text.assemble(
40                        text,
41                        (character * excess_space, style),
42                        no_wrap=True,
43                        end="",
44                    )
45                elif align == "center":
46                    left = excess_space // 2
47                    return Text.assemble(
48                        (character * left, style),
49                        text,
50                        (character * (excess_space - left), style),
51                        no_wrap=True,
52                        end="",
53                    )
54                else:
55                    return Text.assemble(
56                        (character * excess_space, style),
57                        text,
58                        no_wrap=True,
59                        end="",
60                    )
61            return text
62
63        title_text = self._title
64        if title_text is not None:
65            title_text.stylize_before(border_style)
66
67        child_width = (
68            width - 2
69            if self.expand
70            else console.measure(
71                renderable, options=options.update_width(width - 2)
72            ).maximum
73        )
74        child_height = self.height or options.height or None
75        if child_height:
76            child_height -= 2
77        if title_text is not None:
78            child_width = min(
79                options.max_width - 2, max(child_width, title_text.cell_len + 2)
80            )
81
82        width = child_width + 2
83        child_options = options.update(
84            width=child_width, height=child_height, highlight=self.highlight
85        )
86        lines = console.render_lines(renderable, child_options, style=style)
87
88        line_start = Segment(box.mid_left, border_style)
89        line_end = Segment(f"{box.mid_right}", border_style)
90        new_line = Segment.line()
91        if title_text is None or width <= 4:
92            yield Segment(box.get_top([width - 2]), border_style)
93        else:
94            title_text = align_text(
95                title_text,
96                width - 4,
97                self.title_align,
98                box.top,
99                border_style,
100            )
101            yield Segment(box.top_left + box.top, border_style)
102            yield from console.render(title_text, child_options.update_width(width - 4))
103            yield Segment(box.top + box.top_right, border_style)
104
105        yield new_line
106        for line in lines:
107            yield line_start
108            yield from line
109            yield line_end
110            yield new_line
111
112        subtitle_text = self._subtitle
113        if subtitle_text is not None:
114            subtitle_text.stylize_before(border_style)
115
116        if subtitle_text is None or width <= 4:
117            yield Segment(box.get_bottom([width - 2]), border_style)
118        else:
119            subtitle_text = align_text(
120                subtitle_text,
121                width - 4,
122                self.subtitle_align,
123                box.bottom,
124                border_style,
125            )
126            yield Segment(box.bottom_left + box.bottom, border_style)
127            yield from console.render(
128                subtitle_text, child_options.update_width(width - 4)
129            )
130            yield Segment(box.bottom + box.bottom_right, border_style)
131
132        yield new_line
            

Path 3: 10 calls (0.15)

Console (10)

ConsoleOptions (10)

Segment (128) None (10)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        _padding = Padding.unpack(self.padding)
5        renderable = (
6            Padding(self.renderable, _padding) if any(_padding) else self.renderable
7        )
8        style = console.get_style(self.style)
9        border_style = style + console.get_style(self.border_style)
10        width = (
11            options.max_width
12            if self.width is None
13            else min(options.max_width, self.width)
14        )
15
16        safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
17        box = self.box.substitute(options, safe=safe_box)
18
19        def align_text(
20            text: Text, width: int, align: str, character: str, style: Style
21        ) -> Text:
22            """Gets new aligned text.
23
24            Args:
25                text (Text): Title or subtitle text.
26                width (int): Desired width.
27                align (str): Alignment.
28                character (str): Character for alignment.
29                style (Style): Border style
30
31            Returns:
32                Text: New text instance
33            """
34            text = text.copy()
35            text.truncate(width)
36            excess_space = width - cell_len(text.plain)
37            if excess_space:
38                if align == "left":
39                    return Text.assemble(
40                        text,
41                        (character * excess_space, style),
42                        no_wrap=True,
43                        end="",
44                    )
45                elif align == "center":
46                    left = excess_space // 2
47                    return Text.assemble(
48                        (character * left, style),
49                        text,
50                        (character * (excess_space - left), style),
51                        no_wrap=True,
52                        end="",
53                    )
54                else:
55                    return Text.assemble(
56                        (character * excess_space, style),
57                        text,
58                        no_wrap=True,
59                        end="",
60                    )
61            return text
62
63        title_text = self._title
64        if title_text is not None:
65            title_text.stylize_before(border_style)
66
67        child_width = (
68            width - 2
69            if self.expand
70            else console.measure(
71                renderable, options=options.update_width(width - 2)
72            ).maximum
73        )
74        child_height = self.height or options.height or None
75        if child_height:
76            child_height -= 2
77        if title_text is not None:
78            child_width = min(
79                options.max_width - 2, max(child_width, title_text.cell_len + 2)
80            )
81
82        width = child_width + 2
83        child_options = options.update(
84            width=child_width, height=child_height, highlight=self.highlight
85        )
86        lines = console.render_lines(renderable, child_options, style=style)
87
88        line_start = Segment(box.mid_left, border_style)
89        line_end = Segment(f"{box.mid_right}", border_style)
90        new_line = Segment.line()
91        if title_text is None or width <= 4:
92            yield Segment(box.get_top([width - 2]), border_style)
93        else:
94            title_text = align_text(
95                title_text,
96                width - 4,
97                self.title_align,
98                box.top,
99                border_style,
100            )
101            yield Segment(box.top_left + box.top, border_style)
102            yield from console.render(title_text, child_options.update_width(width - 4))
103            yield Segment(box.top + box.top_right, border_style)
104
105        yield new_line
106        for line in lines:
107            yield line_start
108            yield from line
109            yield line_end
110            yield new_line
111
112        subtitle_text = self._subtitle
113        if subtitle_text is not None:
114            subtitle_text.stylize_before(border_style)
115
116        if subtitle_text is None or width <= 4:
117            yield Segment(box.get_bottom([width - 2]), border_style)
118        else:
119            subtitle_text = align_text(
120                subtitle_text,
121                width - 4,
122                self.subtitle_align,
123                box.bottom,
124                border_style,
125            )
126            yield Segment(box.bottom_left + box.bottom, border_style)
127            yield from console.render(
128                subtitle_text, child_options.update_width(width - 4)
129            )
130            yield Segment(box.bottom + box.bottom_right, border_style)
131
132        yield new_line
            

Path 4: 9 calls (0.14)

Console (9)

ConsoleOptions (9)

Segment (294) None (9)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        _padding = Padding.unpack(self.padding)
5        renderable = (
6            Padding(self.renderable, _padding) if any(_padding) else self.renderable
7        )
8        style = console.get_style(self.style)
9        border_style = style + console.get_style(self.border_style)
10        width = (
11            options.max_width
12            if self.width is None
13            else min(options.max_width, self.width)
14        )
15
16        safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
17        box = self.box.substitute(options, safe=safe_box)
18
19        def align_text(
20            text: Text, width: int, align: str, character: str, style: Style
21        ) -> Text:
22            """Gets new aligned text.
23
24            Args:
25                text (Text): Title or subtitle text.
26                width (int): Desired width.
27                align (str): Alignment.
28                character (str): Character for alignment.
29                style (Style): Border style
30
31            Returns:
32                Text: New text instance
33            """
34            text = text.copy()
35            text.truncate(width)
36            excess_space = width - cell_len(text.plain)
37            if excess_space:
38                if align == "left":
39                    return Text.assemble(
40                        text,
41                        (character * excess_space, style),
42                        no_wrap=True,
43                        end="",
44                    )
45                elif align == "center":
46                    left = excess_space // 2
47                    return Text.assemble(
48                        (character * left, style),
49                        text,
50                        (character * (excess_space - left), style),
51                        no_wrap=True,
52                        end="",
53                    )
54                else:
55                    return Text.assemble(
56                        (character * excess_space, style),
57                        text,
58                        no_wrap=True,
59                        end="",
60                    )
61            return text
62
63        title_text = self._title
64        if title_text is not None:
65            title_text.stylize_before(border_style)
66
67        child_width = (
68            width - 2
69            if self.expand
70            else console.measure(
71                renderable, options=options.update_width(width - 2)
72            ).maximum
73        )
74        child_height = self.height or options.height or None
75        if child_height:
76            child_height -= 2
77        if title_text is not None:
78            child_width = min(
79                options.max_width - 2, max(child_width, title_text.cell_len + 2)
80            )
81
82        width = child_width + 2
83        child_options = options.update(
84            width=child_width, height=child_height, highlight=self.highlight
85        )
86        lines = console.render_lines(renderable, child_options, style=style)
87
88        line_start = Segment(box.mid_left, border_style)
89        line_end = Segment(f"{box.mid_right}", border_style)
90        new_line = Segment.line()
91        if title_text is None or width <= 4:
92            yield Segment(box.get_top([width - 2]), border_style)
93        else:
94            title_text = align_text(
95                title_text,
96                width - 4,
97                self.title_align,
98                box.top,
99                border_style,
100            )
101            yield Segment(box.top_left + box.top, border_style)
102            yield from console.render(title_text, child_options.update_width(width - 4))
103            yield Segment(box.top + box.top_right, border_style)
104
105        yield new_line
106        for line in lines:
107            yield line_start
108            yield from line
109            yield line_end
110            yield new_line
111
112        subtitle_text = self._subtitle
113        if subtitle_text is not None:
114            subtitle_text.stylize_before(border_style)
115
116        if subtitle_text is None or width <= 4:
117            yield Segment(box.get_bottom([width - 2]), border_style)
118        else:
119            subtitle_text = align_text(
120                subtitle_text,
121                width - 4,
122                self.subtitle_align,
123                box.bottom,
124                border_style,
125            )
126            yield Segment(box.bottom_left + box.bottom, border_style)
127            yield from console.render(
128                subtitle_text, child_options.update_width(width - 4)
129            )
130            yield Segment(box.bottom + box.bottom_right, border_style)
131
132        yield new_line
            

Path 5: 5 calls (0.08)

Console (5)

ConsoleOptions (5)

Segment (143) None (5)

GeneratorExit (5)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        _padding = Padding.unpack(self.padding)
5        renderable = (
6            Padding(self.renderable, _padding) if any(_padding) else self.renderable
7        )
8        style = console.get_style(self.style)
9        border_style = style + console.get_style(self.border_style)
10        width = (
11            options.max_width
12            if self.width is None
13            else min(options.max_width, self.width)
14        )
15
16        safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
17        box = self.box.substitute(options, safe=safe_box)
18
19        def align_text(
20            text: Text, width: int, align: str, character: str, style: Style
21        ) -> Text:
22            """Gets new aligned text.
23
24            Args:
25                text (Text): Title or subtitle text.
26                width (int): Desired width.
27                align (str): Alignment.
28                character (str): Character for alignment.
29                style (Style): Border style
30
31            Returns:
32                Text: New text instance
33            """
34            text = text.copy()
35            text.truncate(width)
36            excess_space = width - cell_len(text.plain)
37            if excess_space:
38                if align == "left":
39                    return Text.assemble(
40                        text,
41                        (character * excess_space, style),
42                        no_wrap=True,
43                        end="",
44                    )
45                elif align == "center":
46                    left = excess_space // 2
47                    return Text.assemble(
48                        (character * left, style),
49                        text,
50                        (character * (excess_space - left), style),
51                        no_wrap=True,
52                        end="",
53                    )
54                else:
55                    return Text.assemble(
56                        (character * excess_space, style),
57                        text,
58                        no_wrap=True,
59                        end="",
60                    )
61            return text
62
63        title_text = self._title
64        if title_text is not None:
65            title_text.stylize_before(border_style)
66
67        child_width = (
68            width - 2
69            if self.expand
70            else console.measure(
71                renderable, options=options.update_width(width - 2)
72            ).maximum
73        )
74        child_height = self.height or options.height or None
75        if child_height:
76            child_height -= 2
77        if title_text is not None:
78            child_width = min(
79                options.max_width - 2, max(child_width, title_text.cell_len + 2)
80            )
81
82        width = child_width + 2
83        child_options = options.update(
84            width=child_width, height=child_height, highlight=self.highlight
85        )
86        lines = console.render_lines(renderable, child_options, style=style)
87
88        line_start = Segment(box.mid_left, border_style)
89        line_end = Segment(f"{box.mid_right}", border_style)
90        new_line = Segment.line()
91        if title_text is None or width <= 4:
92            yield Segment(box.get_top([width - 2]), border_style)
93        else:
94            title_text = align_text(
95                title_text,
96                width - 4,
97                self.title_align,
98                box.top,
99                border_style,
100            )
101            yield Segment(box.top_left + box.top, border_style)
102            yield from console.render(title_text, child_options.update_width(width - 4))
103            yield Segment(box.top + box.top_right, border_style)
104
105        yield new_line
106        for line in lines:
107            yield line_start
108            yield from line
109            yield line_end
110            yield new_line
111
112        subtitle_text = self._subtitle
113        if subtitle_text is not None:
114            subtitle_text.stylize_before(border_style)
115
116        if subtitle_text is None or width <= 4:
117            yield Segment(box.get_bottom([width - 2]), border_style)
118        else:
119            subtitle_text = align_text(
120                subtitle_text,
121                width - 4,
122                self.subtitle_align,
123                box.bottom,
124                border_style,
125            )
126            yield Segment(box.bottom_left + box.bottom, border_style)
127            yield from console.render(
128                subtitle_text, child_options.update_width(width - 4)
129            )
130            yield Segment(box.bottom + box.bottom_right, border_style)
131
132        yield new_line
            

Path 6: 2 calls (0.03)

Console (2)

ConsoleOptions (2)

Segment (97) None (2)

GeneratorExit (1)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        _padding = Padding.unpack(self.padding)
5        renderable = (
6            Padding(self.renderable, _padding) if any(_padding) else self.renderable
7        )
8        style = console.get_style(self.style)
9        border_style = style + console.get_style(self.border_style)
10        width = (
11            options.max_width
12            if self.width is None
13            else min(options.max_width, self.width)
14        )
15
16        safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
17        box = self.box.substitute(options, safe=safe_box)
18
19        def align_text(
20            text: Text, width: int, align: str, character: str, style: Style
21        ) -> Text:
22            """Gets new aligned text.
23
24            Args:
25                text (Text): Title or subtitle text.
26                width (int): Desired width.
27                align (str): Alignment.
28                character (str): Character for alignment.
29                style (Style): Border style
30
31            Returns:
32                Text: New text instance
33            """
34            text = text.copy()
35            text.truncate(width)
36            excess_space = width - cell_len(text.plain)
37            if excess_space:
38                if align == "left":
39                    return Text.assemble(
40                        text,
41                        (character * excess_space, style),
42                        no_wrap=True,
43                        end="",
44                    )
45                elif align == "center":
46                    left = excess_space // 2
47                    return Text.assemble(
48                        (character * left, style),
49                        text,
50                        (character * (excess_space - left), style),
51                        no_wrap=True,
52                        end="",
53                    )
54                else:
55                    return Text.assemble(
56                        (character * excess_space, style),
57                        text,
58                        no_wrap=True,
59                        end="",
60                    )
61            return text
62
63        title_text = self._title
64        if title_text is not None:
65            title_text.stylize_before(border_style)
66
67        child_width = (
68            width - 2
69            if self.expand
70            else console.measure(
71                renderable, options=options.update_width(width - 2)
72            ).maximum
73        )
74        child_height = self.height or options.height or None
75        if child_height:
76            child_height -= 2
77        if title_text is not None:
78            child_width = min(
79                options.max_width - 2, max(child_width, title_text.cell_len + 2)
80            )
81
82        width = child_width + 2
83        child_options = options.update(
84            width=child_width, height=child_height, highlight=self.highlight
85        )
86        lines = console.render_lines(renderable, child_options, style=style)
87
88        line_start = Segment(box.mid_left, border_style)
89        line_end = Segment(f"{box.mid_right}", border_style)
90        new_line = Segment.line()
91        if title_text is None or width <= 4:
92            yield Segment(box.get_top([width - 2]), border_style)
93        else:
94            title_text = align_text(
95                title_text,
96                width - 4,
97                self.title_align,
98                box.top,
99                border_style,
100            )
101            yield Segment(box.top_left + box.top, border_style)
102            yield from console.render(title_text, child_options.update_width(width - 4))
103            yield Segment(box.top + box.top_right, border_style)
104
105        yield new_line
106        for line in lines:
107            yield line_start
108            yield from line
109            yield line_end
110            yield new_line
111
112        subtitle_text = self._subtitle
113        if subtitle_text is not None:
114            subtitle_text.stylize_before(border_style)
115
116        if subtitle_text is None or width <= 4:
117            yield Segment(box.get_bottom([width - 2]), border_style)
118        else:
119            subtitle_text = align_text(
120                subtitle_text,
121                width - 4,
122                self.subtitle_align,
123                box.bottom,
124                border_style,
125            )
126            yield Segment(box.bottom_left + box.bottom, border_style)
127            yield from console.render(
128                subtitle_text, child_options.update_width(width - 4)
129            )
130            yield Segment(box.bottom + box.bottom_right, border_style)
131
132        yield new_line
            

Path 7: 2 calls (0.03)

Console (2)

ConsoleOptions (2)

Segment (43) None (2)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        _padding = Padding.unpack(self.padding)
5        renderable = (
6            Padding(self.renderable, _padding) if any(_padding) else self.renderable
7        )
8        style = console.get_style(self.style)
9        border_style = style + console.get_style(self.border_style)
10        width = (
11            options.max_width
12            if self.width is None
13            else min(options.max_width, self.width)
14        )
15
16        safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
17        box = self.box.substitute(options, safe=safe_box)
18
19        def align_text(
20            text: Text, width: int, align: str, character: str, style: Style
21        ) -> Text:
22            """Gets new aligned text.
23
24            Args:
25                text (Text): Title or subtitle text.
26                width (int): Desired width.
27                align (str): Alignment.
28                character (str): Character for alignment.
29                style (Style): Border style
30
31            Returns:
32                Text: New text instance
33            """
34            text = text.copy()
35            text.truncate(width)
36            excess_space = width - cell_len(text.plain)
37            if excess_space:
38                if align == "left":
39                    return Text.assemble(
40                        text,
41                        (character * excess_space, style),
42                        no_wrap=True,
43                        end="",
44                    )
45                elif align == "center":
46                    left = excess_space // 2
47                    return Text.assemble(
48                        (character * left, style),
49                        text,
50                        (character * (excess_space - left), style),
51                        no_wrap=True,
52                        end="",
53                    )
54                else:
55                    return Text.assemble(
56                        (character * excess_space, style),
57                        text,
58                        no_wrap=True,
59                        end="",
60                    )
61            return text
62
63        title_text = self._title
64        if title_text is not None:
65            title_text.stylize_before(border_style)
66
67        child_width = (
68            width - 2
69            if self.expand
70            else console.measure(
71                renderable, options=options.update_width(width - 2)
72            ).maximum
73        )
74        child_height = self.height or options.height or None
75        if child_height:
76            child_height -= 2
77        if title_text is not None:
78            child_width = min(
79                options.max_width - 2, max(child_width, title_text.cell_len + 2)
80            )
81
82        width = child_width + 2
83        child_options = options.update(
84            width=child_width, height=child_height, highlight=self.highlight
85        )
86        lines = console.render_lines(renderable, child_options, style=style)
87
88        line_start = Segment(box.mid_left, border_style)
89        line_end = Segment(f"{box.mid_right}", border_style)
90        new_line = Segment.line()
91        if title_text is None or width <= 4:
92            yield Segment(box.get_top([width - 2]), border_style)
93        else:
94            title_text = align_text(
95                title_text,
96                width - 4,
97                self.title_align,
98                box.top,
99                border_style,
100            )
101            yield Segment(box.top_left + box.top, border_style)
102            yield from console.render(title_text, child_options.update_width(width - 4))
103            yield Segment(box.top + box.top_right, border_style)
104
105        yield new_line
106        for line in lines:
107            yield line_start
108            yield from line
109            yield line_end
110            yield new_line
111
112        subtitle_text = self._subtitle
113        if subtitle_text is not None:
114            subtitle_text.stylize_before(border_style)
115
116        if subtitle_text is None or width <= 4:
117            yield Segment(box.get_bottom([width - 2]), border_style)
118        else:
119            subtitle_text = align_text(
120                subtitle_text,
121                width - 4,
122                self.subtitle_align,
123                box.bottom,
124                border_style,
125            )
126            yield Segment(box.bottom_left + box.bottom, border_style)
127            yield from console.render(
128                subtitle_text, child_options.update_width(width - 4)
129            )
130            yield Segment(box.bottom + box.bottom_right, border_style)
131
132        yield new_line
            

Path 8: 1 calls (0.02)

Console (1)

ConsoleOptions (1)

Segment (13) None (1)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        _padding = Padding.unpack(self.padding)
5        renderable = (
6            Padding(self.renderable, _padding) if any(_padding) else self.renderable
7        )
8        style = console.get_style(self.style)
9        border_style = style + console.get_style(self.border_style)
10        width = (
11            options.max_width
12            if self.width is None
13            else min(options.max_width, self.width)
14        )
15
16        safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
17        box = self.box.substitute(options, safe=safe_box)
18
19        def align_text(
20            text: Text, width: int, align: str, character: str, style: Style
21        ) -> Text:
22            """Gets new aligned text.
23
24            Args:
25                text (Text): Title or subtitle text.
26                width (int): Desired width.
27                align (str): Alignment.
28                character (str): Character for alignment.
29                style (Style): Border style
30
31            Returns:
32                Text: New text instance
33            """
34            text = text.copy()
35            text.truncate(width)
36            excess_space = width - cell_len(text.plain)
37            if excess_space:
38                if align == "left":
39                    return Text.assemble(
40                        text,
41                        (character * excess_space, style),
42                        no_wrap=True,
43                        end="",
44                    )
45                elif align == "center":
46                    left = excess_space // 2
47                    return Text.assemble(
48                        (character * left, style),
49                        text,
50                        (character * (excess_space - left), style),
51                        no_wrap=True,
52                        end="",
53                    )
54                else:
55                    return Text.assemble(
56                        (character * excess_space, style),
57                        text,
58                        no_wrap=True,
59                        end="",
60                    )
61            return text
62
63        title_text = self._title
64        if title_text is not None:
65            title_text.stylize_before(border_style)
66
67        child_width = (
68            width - 2
69            if self.expand
70            else console.measure(
71                renderable, options=options.update_width(width - 2)
72            ).maximum
73        )
74        child_height = self.height or options.height or None
75        if child_height:
76            child_height -= 2
77        if title_text is not None:
78            child_width = min(
79                options.max_width - 2, max(child_width, title_text.cell_len + 2)
80            )
81
82        width = child_width + 2
83        child_options = options.update(
84            width=child_width, height=child_height, highlight=self.highlight
85        )
86        lines = console.render_lines(renderable, child_options, style=style)
87
88        line_start = Segment(box.mid_left, border_style)
89        line_end = Segment(f"{box.mid_right}", border_style)
90        new_line = Segment.line()
91        if title_text is None or width <= 4:
92            yield Segment(box.get_top([width - 2]), border_style)
93        else:
94            title_text = align_text(
95                title_text,
96                width - 4,
97                self.title_align,
98                box.top,
99                border_style,
100            )
101            yield Segment(box.top_left + box.top, border_style)
102            yield from console.render(title_text, child_options.update_width(width - 4))
103            yield Segment(box.top + box.top_right, border_style)
104
105        yield new_line
106        for line in lines:
107            yield line_start
108            yield from line
109            yield line_end
110            yield new_line
111
112        subtitle_text = self._subtitle
113        if subtitle_text is not None:
114            subtitle_text.stylize_before(border_style)
115
116        if subtitle_text is None or width <= 4:
117            yield Segment(box.get_bottom([width - 2]), border_style)
118        else:
119            subtitle_text = align_text(
120                subtitle_text,
121                width - 4,
122                self.subtitle_align,
123                box.bottom,
124                border_style,
125            )
126            yield Segment(box.bottom_left + box.bottom, border_style)
127            yield from console.render(
128                subtitle_text, child_options.update_width(width - 4)
129            )
130            yield Segment(box.bottom + box.bottom_right, border_style)
131
132        yield new_line