| 228 | from IPython.core.formatters import BaseFormatter |
| 229 | |
| 230 | class RichFormatter(BaseFormatter): # type: ignore[misc] |
| 231 | pprint: bool = True |
| 232 | |
| 233 | def __call__(self, value: Any) -> Any: |
| 234 | if self.pprint: |
| 235 | return _ipy_display_hook( |
| 236 | value, |
| 237 | console=console, |
| 238 | overflow=overflow, |
| 239 | indent_guides=indent_guides, |
| 240 | max_length=max_length, |
| 241 | max_string=max_string, |
| 242 | max_depth=max_depth, |
| 243 | expand_all=expand_all, |
| 244 | ) |
| 245 | else: |
| 246 | return repr(value) |
| 247 | |
| 248 | # replace plain text formatter with rich formatter |
| 249 | rich_formatter = RichFormatter() |