"""Slices AI CLI."""

import os

from rich.console import Console

VERBOSITY_TRACE = 3
VERBOSITY_DEBUG = 2
VERBOSITY_INFO = 1


def make_console(*, log_path: bool = True, stderr: bool = False) -> Console:
    """Make a rich console.

    Includes workaround for special case of python via shell process inside a notebook.
    """

    res = Console(log_path=log_path, stderr=stderr)
    if not res.is_jupyter and os.getenv("JPY_SESSION_NAME") is not None:
        # We are running in a `!` shell process inside a notebook.
        # This is a special case.
        #    - This "terminal" looks interactive, but is not.
        #    - This "terminal" understand color codes, but not terminal control codes to move the cursor etc
        # We force rich to see the terminal as DUMB and non-interactive
        # Also, we make sure we don't revert to default dumb terminal size,
        #    which is very small, so we set fallbacks for LINES and COLUMNS
        os.environ["TERM"] = "DUMB"
        return Console(
            log_path=log_path,
            stderr=stderr,
            force_interactive=False,
            width=int(os.getenv("COLUMNS") or 140),
            height=int(os.getenv("LINES") or 30),
        )
    return res


console = make_console(log_path=False)
err_console = make_console(stderr=True)
