-
Notifications
You must be signed in to change notification settings - Fork 1
/
console.py
37 lines (26 loc) · 1.01 KB
/
console.py
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
34
35
36
37
#!/usr/bin/env python
import sys
from .modules import install as install_package
# # thx to https://stackoverflow.com/questions/41678073
# Console = getattr(import_module('rich.console', 'rich'), 'Console')
# Live = getattr(import_module('rich.live', 'rich'), 'Live')
# Progress = getattr(import_module('rich.progress', 'rich'), 'Progress')
try:
from rich.console import Console
from rich.live import Live
from rich.progress import Progress
except ImportError:
install_package('rich')
from rich.console import Console
from rich.live import Live
from rich.progress import Progress
stdout = Console()
stderr = Console(file=sys.stderr)
def new_live_display(console: Console, screen: bool = False, auto_refresh: bool = False) -> Live:
return Live(console=console, screen=screen, auto_refresh=auto_refresh)
def new_progress_display(console: Console) -> Progress:
return Progress(console=console)
def new_quiet_console() -> Console:
return Console(file=sys.stderr, quiet=True)
if __name__ == "__main__":
pass