# Path: clearly/utils/colors.py
# class Colors:
#     BLUE = color_factory('\033[94m')
#     GREEN = color_factory('\033[92m')
#     YELLOW = color_factory('\033[93m')
#     RED = color_factory('\033[91m')
#     MAGENTA = color_factory('\033[95m')
#     CYAN = color_factory('\033[96m')
#     ORANGE = color_factory('\033[38;5;208m')
# 
#     BOLD = color_factory('\033[1m')
#     DIM = color_factory('\033[2m')
# 
#     BLUE_BOLD, BLUE_DIM = BLUE.mix(BOLD, DIM)
#     GREEN_BOLD, GREEN_DIM = GREEN.mix(BOLD, DIM)
#     YELLOW_BOLD, YELLOW_DIM = YELLOW.mix(BOLD, DIM)
#     RED_BOLD, RED_DIM = RED.mix(BOLD, DIM)
#     MAGENTA_BOLD, MAGENTA_DIM = MAGENTA.mix(BOLD, DIM)
#     CYAN_BOLD, CYAN_DIM = CYAN.mix(BOLD, DIM)
#     ORANGE_BOLD, ORANGE_DIM = ORANGE.mix(BOLD, DIM)
# 
# Path: clearly/utils/safe_compiler.py
# NON_PRINTABLE_PATTERN = re.compile('[\x00-\x1f]')
# def safe_compile_text(txt: str, raises: bool = False) -> Any:
#     def _convert(node):
# def _encode_to_hex(match: Match) -> str:


from typing import Any, Callable
from ..utils.colors import Colors
from ..utils.safe_compiler import CallDescriptor
    from pygments.lexers.python import PythonTracebackLexer
    from pygments.formatters.terminal256 import Terminal256Formatter
    from pygments import highlight
DICT_SEPARATOR = Colors.RED(': ')
NONE = Colors.CYAN('None')


def typed_code(p: Any, wrap: bool = True) -> str:
    if p is None:
        return NONE

    if isinstance(p, bool):
        return Colors.CYAN(str(p))

    if isinstance(p, str):
        if "'" in p and '"' not in p:
            escape = '"'
        else:
            escape = "'"
            p = p.replace("'", "\\'")
        return Colors.YELLOW('{c}{p}{c}'.format(p=p, c=escape))

    if isinstance(p, (int, float, complex)):
        return Colors.GREEN(str(p))

    if isinstance(p, CallDescriptor):
        func_args = typed_code(p.args, wrap=False) if p.args else ''
        if p.kwargs:
            if p.args:
                func_args += SEPARATOR
            func_args += typed_code(p.kwargs, wrap=False)
        return '{}({})'.format(p.name, func_args)


# Path: clearly/utils/colors.py
# class Colors:
#     BLUE = color_factory('\033[94m')
#     GREEN = color_factory('\033[92m')
#     YELLOW = color_factory('\033[93m')
#     RED = color_factory('\033[91m')
#     MAGENTA = color_factory('\033[95m')
#     CYAN = color_factory('\033[96m')
#     ORANGE = color_factory('\033[38;5;208m')
# 
#     BOLD = color_factory('\033[1m')
#     DIM = color_factory('\033[2m')
# 
#     BLUE_BOLD, BLUE_DIM = BLUE.mix(BOLD, DIM)
#     GREEN_BOLD, GREEN_DIM = GREEN.mix(BOLD, DIM)
#     YELLOW_BOLD, YELLOW_DIM = YELLOW.mix(BOLD, DIM)
#     RED_BOLD, RED_DIM = RED.mix(BOLD, DIM)
#     MAGENTA_BOLD, MAGENTA_DIM = MAGENTA.mix(BOLD, DIM)
#     CYAN_BOLD, CYAN_DIM = CYAN.mix(BOLD, DIM)
#     ORANGE_BOLD, ORANGE_DIM = ORANGE.mix(BOLD, DIM)
# 
# Path: clearly/utils/safe_compiler.py
# NON_PRINTABLE_PATTERN = re.compile('[\x00-\x1f]')
# def safe_compile_text(txt: str, raises: bool = False) -> Any:
#     def _convert(node):
# def _encode_to_hex(match: Match) -> str:


# Path: clearly/client/code_highlighter.py
from typing import Any, Callable
from ..utils.colors import Colors
from ..utils.safe_compiler import CallDescriptor
    from pygments.lexers.python import PythonTracebackLexer
    from pygments.formatters.terminal256 import Terminal256Formatter
    from pygments import highlight

DICT_SEPARATOR = Colors.RED(': ')
NONE = Colors.CYAN('None')


def typed_code(p: Any, wrap: bool = True) -> str:
    if p is None:
        return NONE

    if isinstance(p, bool):
        return Colors.CYAN(str(p))

    if isinstance(p, str):
        if "'" in p and '"' not in p:
            escape = '"'
        else:
            escape = "'"
            p = p.replace("'", "\\'")
        return Colors.YELLOW('{c}{p}{c}'.format(p=p, c=escape))

    if isinstance(p, (int, float, complex)):
        return Colors.GREEN(str(p))

    if isinstance(p, CallDescriptor):
        func_args = typed_code(p.args, wrap=False) if p.args else ''
        if p.kwargs:
            if p.args:
                func_args += SEPARATOR
            func_args += typed_code(p.kwargs, wrap=False)
        return '{}({})'.format(p.name, func_args)


    if isinstance(p, list):