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

Method __rich_console__

rich/padding.py:79–123  ·  view source on GitHub ↗
(
        self, console: "Console", options: "ConsoleOptions"
    )

Source from the content-addressed store, hash-verified

77 return f"Padding({self.renderable!r}, ({self.top},{self.right},{self.bottom},{self.left}))"
78
79 def __rich_console__(
80 self, console: "Console", options: "ConsoleOptions"
81 ) -> "RenderResult":
82 style = console.get_style(self.style)
83 if self.expand:
84 width = options.max_width
85 else:
86 width = min(
87 Measurement.get(console, options, self.renderable).maximum
88 + self.left
89 + self.right,
90 options.max_width,
91 )
92 render_options = options.update_width(width - self.left - self.right)
93 if render_options.height is not None:
94 render_options = render_options.update_height(
95 height=render_options.height - self.top - self.bottom
96 )
97 lines = console.render_lines(
98 self.renderable, render_options, style=style, pad=True
99 )
100 _Segment = Segment
101
102 left = _Segment(" " * self.left, style) if self.left else None
103 right = (
104 [_Segment(f'{" " * self.right}', style), _Segment.line()]
105 if self.right
106 else [_Segment.line()]
107 )
108 blank_line: Optional[List[Segment]] = None
109 if self.top:
110 blank_line = [_Segment(f'{" " * width}\n', style)]
111 yield from blank_line * self.top
112 if left:
113 for line in lines:
114 yield left
115 yield from line
116 yield from right
117 else:
118 for line in lines:
119 yield from line
120 yield from right
121 if self.bottom:
122 blank_line = blank_line or [_Segment(f'{" " * width}\n', style)]
123 yield from blank_line * self.bottom
124
125 def __rich_measure__(
126 self, console: "Console", options: "ConsoleOptions"

Callers

nothing calls this directly

Calls 6

get_styleMethod · 0.80
update_widthMethod · 0.80
update_heightMethod · 0.80
render_linesMethod · 0.80
getMethod · 0.45
lineMethod · 0.45

Tested by

no test coverage detected