File size: 882 Bytes
0ad74ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from __future__ import annotations
import time
from types import TracebackType
from typing import Optional
from rich.live import Live
from rich.panel import Panel
class LivePanelDisplay:
def __init__(self, msg: str | None = None) -> None:
self.lines = [msg] if msg else []
self._panel = Live(Panel("\n".join(self.lines)), refresh_per_second=5)
def update(self, msg: str, add_sleep: float | None = None):
self.lines.append(msg)
self._panel.update(Panel("\n".join(self.lines)))
if add_sleep:
time.sleep(add_sleep)
def __enter__(self) -> LivePanelDisplay:
self._panel.__enter__()
return self
def __exit__(
self,
exc_type: Optional[type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> None:
self._panel.stop()
|