Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
48.12k stars 1.69k forks source link

[REQUEST] Allow console.status(transient=False) to keep it in the console #1797

Open zerothi opened 2 years ago

zerothi commented 2 years ago

How would you improve Rich?

It would be great if one could allow the Status spinners to remain in the console when printing. Currently the transient=True is hard-coded in the Status.__init__ method. Instead one could pass down the transient argument to the Live class instantiation. This would allow the status report to remain.

What problem does it solve for you?

It allows me to have the entire thing in the prompt. Something that would make it easier for end-users since every step is maintained in the output.

I would be happy to make a PR if you agree this would be nice, something like this would work:

class Status(JupyterMixin):
    """Displays a status indicator with a 'spinner' animation.

    Args:
        status (RenderableType): A status renderable (str or Text typically).
        console (Console, optional): Console instance to use, or None for global console. Defaults to None.
        spinner (str, optional): Name of spinner animation (see python -m rich.spinner). Defaults to "dots".
        spinner_style (StyleType, optional): Style of spinner. Defaults to "status.spinner".
        speed (float, optional): Speed factor for spinner animation. Defaults to 1.0.
        refresh_per_second (float, optional): Number of refreshes per second. Defaults to 12.5.
    """

    def __init__(
        self,
        status: RenderableType,
        *,
        console: Optional[Console] = None,
        spinner: str = "dots",
        spinner_style: StyleType = "status.spinner",
        speed: float = 1.0,
        refresh_per_second: float = 12.5,
        transient: bool = True
    ):
        self.status = status
        self.spinner_style = spinner_style
        self.speed = speed
        self._spinner = Spinner(spinner, text=status, style=spinner_style, speed=speed)
        self._live = Live(
            self.renderable,
            console=console,
            refresh_per_second=refresh_per_second,
            transient=transient,
        )
    ....
willmcgugan commented 2 years ago

Not convinced we really need this. You can always print something after the spinner has disappeared.

zerothi commented 2 years ago

Not convinced we really need this. You can always print something after the spinner has disappeared.

Yes, but I wanted the spinner and text of the spinner to stay in the output.