freqtrade_origin/freqtrade/util/rich_progress.py

26 lines
830 B
Python

from typing import Callable, List, Optional, Union
from rich.console import ConsoleRenderable, Group, RichCast
from rich.progress import Progress
class CustomProgress(Progress):
def __init__(
self,
*args,
cust_objs: Optional[List[ConsoleRenderable]] = None,
cust_callables: Optional[List[Callable[[], ConsoleRenderable]]] = None,
**kwargs,
) -> None:
self._cust_objs = cust_objs or []
self._cust_callables = cust_callables or []
super().__init__(*args, **kwargs)
def get_renderable(self) -> Union[ConsoleRenderable, RichCast, str]:
objs = [obj for obj in self._cust_objs]
for cust_call in self._cust_callables:
objs.append(cust_call())
renderable = Group(*objs, *self.get_renderables())
return renderable