A rich renderable that pretty prints an object. Args: _object (Any): An object to pretty print. highlighter (HighlighterType, optional): Highlighter object to apply to result, or None for ReprHighlighter. Defaults to None. indent_size (int, optional): Number of spaces in
| 251 | |
| 252 | |
| 253 | class Pretty(JupyterMixin): |
| 254 | """A rich renderable that pretty prints an object. |
| 255 | |
| 256 | Args: |
| 257 | _object (Any): An object to pretty print. |
| 258 | highlighter (HighlighterType, optional): Highlighter object to apply to result, or None for ReprHighlighter. Defaults to None. |
| 259 | indent_size (int, optional): Number of spaces in indent. Defaults to 4. |
| 260 | justify (JustifyMethod, optional): Justify method, or None for default. Defaults to None. |
| 261 | overflow (OverflowMethod, optional): Overflow method, or None for default. Defaults to None. |
| 262 | no_wrap (Optional[bool], optional): Disable word wrapping. Defaults to False. |
| 263 | indent_guides (bool, optional): Enable indentation guides. Defaults to False. |
| 264 | max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. |
| 265 | Defaults to None. |
| 266 | max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None. |
| 267 | max_depth (int, optional): Maximum depth of nested data structures, or None for no maximum. Defaults to None. |
| 268 | expand_all (bool, optional): Expand all containers. Defaults to False. |
| 269 | margin (int, optional): Subtrace a margin from width to force containers to expand earlier. Defaults to 0. |
| 270 | insert_line (bool, optional): Insert a new line if the output has multiple new lines. Defaults to False. |
| 271 | """ |
| 272 | |
| 273 | def __init__( |
| 274 | self, |
| 275 | _object: Any, |
| 276 | highlighter: Optional["HighlighterType"] = None, |
| 277 | *, |
| 278 | indent_size: int = 4, |
| 279 | justify: Optional["JustifyMethod"] = None, |
| 280 | overflow: Optional["OverflowMethod"] = None, |
| 281 | no_wrap: Optional[bool] = False, |
| 282 | indent_guides: bool = False, |
| 283 | max_length: Optional[int] = None, |
| 284 | max_string: Optional[int] = None, |
| 285 | max_depth: Optional[int] = None, |
| 286 | expand_all: bool = False, |
| 287 | margin: int = 0, |
| 288 | insert_line: bool = False, |
| 289 | ) -> None: |
| 290 | self._object = _object |
| 291 | self.highlighter = highlighter or ReprHighlighter() |
| 292 | self.indent_size = indent_size |
| 293 | self.justify: Optional["JustifyMethod"] = justify |
| 294 | self.overflow: Optional["OverflowMethod"] = overflow |
| 295 | self.no_wrap = no_wrap |
| 296 | self.indent_guides = indent_guides |
| 297 | self.max_length = max_length |
| 298 | self.max_string = max_string |
| 299 | self.max_depth = max_depth |
| 300 | self.expand_all = expand_all |
| 301 | self.margin = margin |
| 302 | self.insert_line = insert_line |
| 303 | |
| 304 | def __rich_console__( |
| 305 | self, console: "Console", options: "ConsoleOptions" |
| 306 | ) -> "RenderResult": |
| 307 | pretty_str = pretty_repr( |
| 308 | self._object, |
| 309 | max_width=options.max_width - self.margin, |
| 310 | indent_size=self.indent_size, |
no outgoing calls