explore.textmode.art

import sys from pprint import pformat, pprint from typing import Literal, IO, Any from pygments import highlight from pygments.formatter import Formatter from pygments.formatters import get_formatter_by_name from pygments.lexers import PythonLexer __all__ = ( 'xpprint', 'xpp', ) def xpprint( obj: Any, stream: IO[str]|None = None, indent: int = 1, width: int = 80, depth: int|None = None, *, compact: bool = False, sort_dicts: bool = True, underscore_numbers: bool = False, color: Literal['auto', 'always', 'never'] = 'auto', formatter: str|Formatter = 'console', ) -> None: if color == 'always' or (color == 'auto' and (stream or sys.stdout).isatty()): fmt = get_formatter_by_name(formatter) if isinstance(formatter, str) else formatter print(highlight( pformat( obj, indent=indent, width=width, depth=depth, compact=compact, sort_dicts=sort_dicts, underscore_numbers=underscore_numbers, ), PythonLexer(), fmt ), end="", file=stream) else: pprint( obj, stream=stream, indent=indent, width=width, de