Skip to content

handlers

Handlers defined in this file can be imported and used as with context managers.

SimpleSpinner(message='Loading...')

A simple CLI spinner context manager.

Parameters:

Name Type Description Default
message str

The message to display while the spinner is running

'Loading...'

Usage:

with SimpleSpinnner("Your message... "):
    ...
Source code in src/red_utils/ext/context_managers/cli_spinners/handlers.py
@contextmanager
def SimpleSpinner(message: str = "Loading..."):
    """A simple CLI spinner context manager.

    Params:
        message (str): The message to display while the spinner is running

    Usage:

    ``` py linenums="1"
    with SimpleSpinnner("Your message... "):
        ...
    ```
    """
    rich_console: Console = Console()

    try:
        with rich_console.status(message) as status:
            yield status
    except Exception as exc:
        raise Exception(f"Unhandled exception yielding spinner. Details: {exc}")
    finally:
        # rich_console.clear()
        rich_console.clear_live()