Path 1: 15 calls (0.58)

Console (15)

ConsoleOptions (15)

Segment (232) None (15)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        align = self.align
5        width = console.measure(self.renderable, options=options).maximum
6        rendered = console.render(
7            Constrain(
8                self.renderable, width if self.width is None else min(width, self.width)
9            ),
10            options.update(height=None),
11        )
12        lines = list(Segment.split_lines(rendered))
13        width, height = Segment.get_shape(lines)
14        lines = Segment.set_shape(lines, width, height)
15        new_line = Segment.line()
16        excess_space = options.max_width - width
17        style = console.get_style(self.style) if self.style is not None else None
18
19        def generate_segments() -> Iterable[Segment]:
20            if excess_space <= 0:
21                # Exact fit
22                for line in lines:
23                    yield from line
24                    yield new_line
25
26            elif align == "left":
27                # Pad on the right
28                pad = Segment(" " * excess_space, style) if self.pad else None
29                for line in lines:
30                    yield from line
31                    if pad:
32                        yield pad
33                    yield new_line
34
35            elif align == "center":
36                # Pad left and right
37                left = excess_space // 2
38                pad = Segment(" " * left, style)
39                pad_right = (
40                    Segment(" " * (excess_space - left), style) if self.pad else None
41                )
42                for line in lines:
43                    if left:
44                        yield pad
45                    yield from line
46                    if pad_right:
47                        yield pad_right
48                    yield new_line
49
50            elif align == "right":
51                # Padding on left
52                pad = Segment(" " * excess_space, style)
53                for line in lines:
54                    yield pad
55                    yield from line
56                    yield new_line
57
58        blank_line = (
59            Segment(f"{' ' * (self.width or options.max_width)}\n", style)
60            if self.pad
61            else Segment("\n")
62        )
63
64        def blank_lines(count: int) -> Iterable[Segment]:
65            if count > 0:
66                for _ in range(count):
67                    yield blank_line
68
69        vertical_height = self.height or options.height
70        iter_segments: Iterable[Segment]
71        if self.vertical and vertical_height is not None:
72            if self.vertical == "top":
73                bottom_space = vertical_height - height
74                iter_segments = chain(generate_segments(), blank_lines(bottom_space))
75            elif self.vertical == "middle":
76                top_space = (vertical_height - height) // 2
77                bottom_space = vertical_height - top_space - height
78                iter_segments = chain(
79                    blank_lines(top_space),
80                    generate_segments(),
81                    blank_lines(bottom_space),
82                )
83            else:  #  self.vertical == "bottom":
84                top_space = vertical_height - height
85                iter_segments = chain(blank_lines(top_space), generate_segments())
86        else:
87            iter_segments = generate_segments()
88        if self.style:
89            style = console.get_style(self.style)
90            iter_segments = Segment.apply_style(iter_segments, style)
91        yield from iter_segments
            

Path 2: 6 calls (0.23)

Console (6)

ConsoleOptions (6)

Segment (53) None (6)

GeneratorExit (4)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        align = self.align
5        width = console.measure(self.renderable, options=options).maximum
6        rendered = console.render(
7            Constrain(
8                self.renderable, width if self.width is None else min(width, self.width)
9            ),
10            options.update(height=None),
11        )
12        lines = list(Segment.split_lines(rendered))
13        width, height = Segment.get_shape(lines)
14        lines = Segment.set_shape(lines, width, height)
15        new_line = Segment.line()
16        excess_space = options.max_width - width
17        style = console.get_style(self.style) if self.style is not None else None
18
19        def generate_segments() -> Iterable[Segment]:
20            if excess_space <= 0:
21                # Exact fit
22                for line in lines:
23                    yield from line
24                    yield new_line
25
26            elif align == "left":
27                # Pad on the right
28                pad = Segment(" " * excess_space, style) if self.pad else None
29                for line in lines:
30                    yield from line
31                    if pad:
32                        yield pad
33                    yield new_line
34
35            elif align == "center":
36                # Pad left and right
37                left = excess_space // 2
38                pad = Segment(" " * left, style)
39                pad_right = (
40                    Segment(" " * (excess_space - left), style) if self.pad else None
41                )
42                for line in lines:
43                    if left:
44                        yield pad
45                    yield from line
46                    if pad_right:
47                        yield pad_right
48                    yield new_line
49
50            elif align == "right":
51                # Padding on left
52                pad = Segment(" " * excess_space, style)
53                for line in lines:
54                    yield pad
55                    yield from line
56                    yield new_line
57
58        blank_line = (
59            Segment(f"{' ' * (self.width or options.max_width)}\n", style)
60            if self.pad
61            else Segment("\n")
62        )
63
64        def blank_lines(count: int) -> Iterable[Segment]:
65            if count > 0:
66                for _ in range(count):
67                    yield blank_line
68
69        vertical_height = self.height or options.height
70        iter_segments: Iterable[Segment]
71        if self.vertical and vertical_height is not None:
72            if self.vertical == "top":
73                bottom_space = vertical_height - height
74                iter_segments = chain(generate_segments(), blank_lines(bottom_space))
75            elif self.vertical == "middle":
76                top_space = (vertical_height - height) // 2
77                bottom_space = vertical_height - top_space - height
78                iter_segments = chain(
79                    blank_lines(top_space),
80                    generate_segments(),
81                    blank_lines(bottom_space),
82                )
83            else:  #  self.vertical == "bottom":
84                top_space = vertical_height - height
85                iter_segments = chain(blank_lines(top_space), generate_segments())
86        else:
87            iter_segments = generate_segments()
88        if self.style:
89            style = console.get_style(self.style)
90            iter_segments = Segment.apply_style(iter_segments, style)
91        yield from iter_segments
            

Path 3: 2 calls (0.08)

Console (2)

ConsoleOptions (2)

Segment (5) None (2)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        align = self.align
5        width = console.measure(self.renderable, options=options).maximum
6        rendered = console.render(
7            Constrain(
8                self.renderable, width if self.width is None else min(width, self.width)
9            ),
10            options.update(height=None),
11        )
12        lines = list(Segment.split_lines(rendered))
13        width, height = Segment.get_shape(lines)
14        lines = Segment.set_shape(lines, width, height)
15        new_line = Segment.line()
16        excess_space = options.max_width - width
17        style = console.get_style(self.style) if self.style is not None else None
18
19        def generate_segments() -> Iterable[Segment]:
20            if excess_space <= 0:
21                # Exact fit
22                for line in lines:
23                    yield from line
24                    yield new_line
25
26            elif align == "left":
27                # Pad on the right
28                pad = Segment(" " * excess_space, style) if self.pad else None
29                for line in lines:
30                    yield from line
31                    if pad:
32                        yield pad
33                    yield new_line
34
35            elif align == "center":
36                # Pad left and right
37                left = excess_space // 2
38                pad = Segment(" " * left, style)
39                pad_right = (
40                    Segment(" " * (excess_space - left), style) if self.pad else None
41                )
42                for line in lines:
43                    if left:
44                        yield pad
45                    yield from line
46                    if pad_right:
47                        yield pad_right
48                    yield new_line
49
50            elif align == "right":
51                # Padding on left
52                pad = Segment(" " * excess_space, style)
53                for line in lines:
54                    yield pad
55                    yield from line
56                    yield new_line
57
58        blank_line = (
59            Segment(f"{' ' * (self.width or options.max_width)}\n", style)
60            if self.pad
61            else Segment("\n")
62        )
63
64        def blank_lines(count: int) -> Iterable[Segment]:
65            if count > 0:
66                for _ in range(count):
67                    yield blank_line
68
69        vertical_height = self.height or options.height
70        iter_segments: Iterable[Segment]
71        if self.vertical and vertical_height is not None:
72            if self.vertical == "top":
73                bottom_space = vertical_height - height
74                iter_segments = chain(generate_segments(), blank_lines(bottom_space))
75            elif self.vertical == "middle":
76                top_space = (vertical_height - height) // 2
77                bottom_space = vertical_height - top_space - height
78                iter_segments = chain(
79                    blank_lines(top_space),
80                    generate_segments(),
81                    blank_lines(bottom_space),
82                )
83            else:  #  self.vertical == "bottom":
84                top_space = vertical_height - height
85                iter_segments = chain(blank_lines(top_space), generate_segments())
86        else:
87            iter_segments = generate_segments()
88        if self.style:
89            style = console.get_style(self.style)
90            iter_segments = Segment.apply_style(iter_segments, style)
91        yield from iter_segments
            

Path 4: 1 calls (0.04)

Console (1)

ConsoleOptions (1)

Segment (7) None (1)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        align = self.align
5        width = console.measure(self.renderable, options=options).maximum
6        rendered = console.render(
7            Constrain(
8                self.renderable, width if self.width is None else min(width, self.width)
9            ),
10            options.update(height=None),
11        )
12        lines = list(Segment.split_lines(rendered))
13        width, height = Segment.get_shape(lines)
14        lines = Segment.set_shape(lines, width, height)
15        new_line = Segment.line()
16        excess_space = options.max_width - width
17        style = console.get_style(self.style) if self.style is not None else None
18
19        def generate_segments() -> Iterable[Segment]:
20            if excess_space <= 0:
21                # Exact fit
22                for line in lines:
23                    yield from line
24                    yield new_line
25
26            elif align == "left":
27                # Pad on the right
28                pad = Segment(" " * excess_space, style) if self.pad else None
29                for line in lines:
30                    yield from line
31                    if pad:
32                        yield pad
33                    yield new_line
34
35            elif align == "center":
36                # Pad left and right
37                left = excess_space // 2
38                pad = Segment(" " * left, style)
39                pad_right = (
40                    Segment(" " * (excess_space - left), style) if self.pad else None
41                )
42                for line in lines:
43                    if left:
44                        yield pad
45                    yield from line
46                    if pad_right:
47                        yield pad_right
48                    yield new_line
49
50            elif align == "right":
51                # Padding on left
52                pad = Segment(" " * excess_space, style)
53                for line in lines:
54                    yield pad
55                    yield from line
56                    yield new_line
57
58        blank_line = (
59            Segment(f"{' ' * (self.width or options.max_width)}\n", style)
60            if self.pad
61            else Segment("\n")
62        )
63
64        def blank_lines(count: int) -> Iterable[Segment]:
65            if count > 0:
66                for _ in range(count):
67                    yield blank_line
68
69        vertical_height = self.height or options.height
70        iter_segments: Iterable[Segment]
71        if self.vertical and vertical_height is not None:
72            if self.vertical == "top":
73                bottom_space = vertical_height - height
74                iter_segments = chain(generate_segments(), blank_lines(bottom_space))
75            elif self.vertical == "middle":
76                top_space = (vertical_height - height) // 2
77                bottom_space = vertical_height - top_space - height
78                iter_segments = chain(
79                    blank_lines(top_space),
80                    generate_segments(),
81                    blank_lines(bottom_space),
82                )
83            else:  #  self.vertical == "bottom":
84                top_space = vertical_height - height
85                iter_segments = chain(blank_lines(top_space), generate_segments())
86        else:
87            iter_segments = generate_segments()
88        if self.style:
89            style = console.get_style(self.style)
90            iter_segments = Segment.apply_style(iter_segments, style)
91        yield from iter_segments
            

Path 5: 1 calls (0.04)

Console (1)

ConsoleOptions (1)

Segment (7) None (1)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        align = self.align
5        width = console.measure(self.renderable, options=options).maximum
6        rendered = console.render(
7            Constrain(
8                self.renderable, width if self.width is None else min(width, self.width)
9            ),
10            options.update(height=None),
11        )
12        lines = list(Segment.split_lines(rendered))
13        width, height = Segment.get_shape(lines)
14        lines = Segment.set_shape(lines, width, height)
15        new_line = Segment.line()
16        excess_space = options.max_width - width
17        style = console.get_style(self.style) if self.style is not None else None
18
19        def generate_segments() -> Iterable[Segment]:
20            if excess_space <= 0:
21                # Exact fit
22                for line in lines:
23                    yield from line
24                    yield new_line
25
26            elif align == "left":
27                # Pad on the right
28                pad = Segment(" " * excess_space, style) if self.pad else None
29                for line in lines:
30                    yield from line
31                    if pad:
32                        yield pad
33                    yield new_line
34
35            elif align == "center":
36                # Pad left and right
37                left = excess_space // 2
38                pad = Segment(" " * left, style)
39                pad_right = (
40                    Segment(" " * (excess_space - left), style) if self.pad else None
41                )
42                for line in lines:
43                    if left:
44                        yield pad
45                    yield from line
46                    if pad_right:
47                        yield pad_right
48                    yield new_line
49
50            elif align == "right":
51                # Padding on left
52                pad = Segment(" " * excess_space, style)
53                for line in lines:
54                    yield pad
55                    yield from line
56                    yield new_line
57
58        blank_line = (
59            Segment(f"{' ' * (self.width or options.max_width)}\n", style)
60            if self.pad
61            else Segment("\n")
62        )
63
64        def blank_lines(count: int) -> Iterable[Segment]:
65            if count > 0:
66                for _ in range(count):
67                    yield blank_line
68
69        vertical_height = self.height or options.height
70        iter_segments: Iterable[Segment]
71        if self.vertical and vertical_height is not None:
72            if self.vertical == "top":
73                bottom_space = vertical_height - height
74                iter_segments = chain(generate_segments(), blank_lines(bottom_space))
75            elif self.vertical == "middle":
76                top_space = (vertical_height - height) // 2
77                bottom_space = vertical_height - top_space - height
78                iter_segments = chain(
79                    blank_lines(top_space),
80                    generate_segments(),
81                    blank_lines(bottom_space),
82                )
83            else:  #  self.vertical == "bottom":
84                top_space = vertical_height - height
85                iter_segments = chain(blank_lines(top_space), generate_segments())
86        else:
87            iter_segments = generate_segments()
88        if self.style:
89            style = console.get_style(self.style)
90            iter_segments = Segment.apply_style(iter_segments, style)
91        yield from iter_segments
            

Path 6: 1 calls (0.04)

Console (1)

ConsoleOptions (1)

Segment (3) None (1)

1def __rich_console__(
2        self, console: "Console", options: "ConsoleOptions"
3    ) -> "RenderResult":
4        align = self.align
5        width = console.measure(self.renderable, options=options).maximum
6        rendered = console.render(
7            Constrain(
8                self.renderable, width if self.width is None else min(width, self.width)
9            ),
10            options.update(height=None),
11        )
12        lines = list(Segment.split_lines(rendered))
13        width, height = Segment.get_shape(lines)
14        lines = Segment.set_shape(lines, width, height)
15        new_line = Segment.line()
16        excess_space = options.max_width - width
17        style = console.get_style(self.style) if self.style is not None else None
18
19        def generate_segments() -> Iterable[Segment]:
20            if excess_space <= 0:
21                # Exact fit
22                for line in lines:
23                    yield from line
24                    yield new_line
25
26            elif align == "left":
27                # Pad on the right
28                pad = Segment(" " * excess_space, style) if self.pad else None
29                for line in lines:
30                    yield from line
31                    if pad:
32                        yield pad
33                    yield new_line
34
35            elif align == "center":
36                # Pad left and right
37                left = excess_space // 2
38                pad = Segment(" " * left, style)
39                pad_right = (
40                    Segment(" " * (excess_space - left), style) if self.pad else None
41                )
42                for line in lines:
43                    if left:
44                        yield pad
45                    yield from line
46                    if pad_right:
47                        yield pad_right
48                    yield new_line
49
50            elif align == "right":
51                # Padding on left
52                pad = Segment(" " * excess_space, style)
53                for line in lines:
54                    yield pad
55                    yield from line
56                    yield new_line
57
58        blank_line = (
59            Segment(f"{' ' * (self.width or options.max_width)}\n", style)
60            if self.pad
61            else Segment("\n")
62        )
63
64        def blank_lines(count: int) -> Iterable[Segment]:
65            if count > 0:
66                for _ in range(count):
67                    yield blank_line
68
69        vertical_height = self.height or options.height
70        iter_segments: Iterable[Segment]
71        if self.vertical and vertical_height is not None:
72            if self.vertical == "top":
73                bottom_space = vertical_height - height
74                iter_segments = chain(generate_segments(), blank_lines(bottom_space))
75            elif self.vertical == "middle":
76                top_space = (vertical_height - height) // 2
77                bottom_space = vertical_height - top_space - height
78                iter_segments = chain(
79                    blank_lines(top_space),
80                    generate_segments(),
81                    blank_lines(bottom_space),
82                )
83            else:  #  self.vertical == "bottom":
84                top_space = vertical_height - height
85                iter_segments = chain(blank_lines(top_space), generate_segments())
86        else:
87            iter_segments = generate_segments()
88        if self.style:
89            style = console.get_style(self.style)
90            iter_segments = Segment.apply_style(iter_segments, style)
91        yield from iter_segments