(
self, console: "Console", options: "ConsoleOptions"
)
| 139 | return None |
| 140 | |
| 141 | def __rich_console__( |
| 142 | self, console: "Console", options: "ConsoleOptions" |
| 143 | ) -> "RenderResult": |
| 144 | _padding = Padding.unpack(self.padding) |
| 145 | renderable = ( |
| 146 | Padding(self.renderable, _padding) if any(_padding) else self.renderable |
| 147 | ) |
| 148 | style = console.get_style(self.style) |
| 149 | border_style = style + console.get_style(self.border_style) |
| 150 | width = ( |
| 151 | options.max_width |
| 152 | if self.width is None |
| 153 | else min(options.max_width, self.width) |
| 154 | ) |
| 155 | |
| 156 | safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box |
| 157 | box = self.box.substitute(options, safe=safe_box) |
| 158 | |
| 159 | def align_text( |
| 160 | text: Text, width: int, align: str, character: str, style: Style |
| 161 | ) -> Text: |
| 162 | """Gets new aligned text. |
| 163 | |
| 164 | Args: |
| 165 | text (Text): Title or subtitle text. |
| 166 | width (int): Desired width. |
| 167 | align (str): Alignment. |
| 168 | character (str): Character for alignment. |
| 169 | style (Style): Border style |
| 170 | |
| 171 | Returns: |
| 172 | Text: New text instance |
| 173 | """ |
| 174 | text = text.copy() |
| 175 | text.truncate(width) |
| 176 | excess_space = width - cell_len(text.plain) |
| 177 | if text.style: |
| 178 | text.stylize(console.get_style(text.style)) |
| 179 | |
| 180 | if excess_space: |
| 181 | if align == "left": |
| 182 | return Text.assemble( |
| 183 | text, |
| 184 | (character * excess_space, style), |
| 185 | no_wrap=True, |
| 186 | end="", |
| 187 | ) |
| 188 | elif align == "center": |
| 189 | left = excess_space // 2 |
| 190 | return Text.assemble( |
| 191 | (character * left, style), |
| 192 | text, |
| 193 | (character * (excess_space - left), style), |
| 194 | no_wrap=True, |
| 195 | end="", |
| 196 | ) |
| 197 | else: |
| 198 | return Text.assemble( |
nothing calls this directly
no test coverage detected