| 111 | |
| 112 | |
| 113 | def _ipy_display_hook( |
| 114 | value: Any, |
| 115 | console: Optional["Console"] = None, |
| 116 | overflow: "OverflowMethod" = "ignore", |
| 117 | crop: bool = False, |
| 118 | indent_guides: bool = False, |
| 119 | max_length: Optional[int] = None, |
| 120 | max_string: Optional[int] = None, |
| 121 | max_depth: Optional[int] = None, |
| 122 | expand_all: bool = False, |
| 123 | ) -> Union[str, None]: |
| 124 | # needed here to prevent circular import: |
| 125 | from .console import ConsoleRenderable |
| 126 | |
| 127 | # always skip rich generated jupyter renderables or None values |
| 128 | if _safe_isinstance(value, JupyterRenderable) or value is None: |
| 129 | return None |
| 130 | |
| 131 | console = console or get_console() |
| 132 | |
| 133 | with console.capture() as capture: |
| 134 | # certain renderables should start on a new line |
| 135 | if _safe_isinstance(value, ConsoleRenderable): |
| 136 | console.line() |
| 137 | console.print( |
| 138 | ( |
| 139 | value |
| 140 | if _safe_isinstance(value, RichRenderable) |
| 141 | else Pretty( |
| 142 | value, |
| 143 | overflow=overflow, |
| 144 | indent_guides=indent_guides, |
| 145 | max_length=max_length, |
| 146 | max_string=max_string, |
| 147 | max_depth=max_depth, |
| 148 | expand_all=expand_all, |
| 149 | margin=12, |
| 150 | ) |
| 151 | ), |
| 152 | crop=crop, |
| 153 | new_line_start=True, |
| 154 | end="", |
| 155 | ) |
| 156 | # strip trailing newline, not usually part of a text repr |
| 157 | # I'm not sure if this should be prevented at a lower level |
| 158 | return capture.get().rstrip("\n") |
| 159 | |
| 160 | |
| 161 | def _safe_isinstance( |