11import asyncio
2- import io
32import sys
43import itertools
54from enum import StrEnum
6- from typing import Dict , Literal
5+ from typing import Dict
76import shutil
87
98
@@ -22,7 +21,7 @@ def __init__(self, line_limit):
2221
2322 def write (self , s : str ):
2423 self .lines .extend (s .removesuffix ("\n " ).splitlines ())
25- self .lines = self .lines [- self .line_limit :]
24+ self .lines = self .lines [- self .line_limit :]
2625
2726 def flush (self ):
2827 pass
@@ -60,15 +59,23 @@ def render(self) -> str:
6059
6160 name_part = f"{ self .name } : "
6261 padding = terminal_width - len (name_part ) - len (right_part )
63- logs = [
64- f" { line } " [:terminal_width ] for line in self .logger .getvalue ().splitlines ()
65- ] if self .status == Status .RUNNING else []
66- return f"\r { name_part } { ' ' * max (0 , padding )} { right_part } " + (f"\n { "\n " .join (logs )} " if logs else "" )
62+ logs = (
63+ [
64+ f" { line } " [:terminal_width ]
65+ for line in self .logger .getvalue ().splitlines ()
66+ ]
67+ if self .status == Status .RUNNING
68+ else []
69+ )
70+ return f"\r { name_part } { ' ' * max (0 , padding )} { right_part } " + (
71+ f"\n { '\n ' .join (logs )} " if logs else ""
72+ )
6773
6874 def get_logger (self , header : str ):
6975 self .logger .header = header
7076 return self .logger
7177
78+
7279class StatusManager :
7380 def __init__ (self ):
7481 self .bars : Dict [str , StatusBar ] = {}
@@ -101,7 +108,10 @@ async def render(self):
101108
102109 self ._last_render_lines = 0
103110 bars = list (self .bars .values ())
104- bars = itertools .groupby (sorted (bars , key = lambda bar : (bar .status , bar .name )), key = lambda bar : bar .status )
111+ bars = itertools .groupby (
112+ sorted (bars , key = lambda bar : (bar .status , bar .name )),
113+ key = lambda bar : bar .status ,
114+ )
105115 for status , bars in bars :
106116 bars = [* bars ]
107117 if status == Status .WAITING :
@@ -113,7 +123,6 @@ async def render(self):
113123 print (rendered )
114124 self ._last_render_lines += len (rendered .splitlines ())
115125
116-
117126 async def mark_with_status (self , name : str , status : Status ):
118127 async with self .lock :
119128 if name in self .bars :
@@ -137,4 +146,3 @@ async def stop(self):
137146
138147 def get_logger (self , name : str , header : str = "" ):
139148 return self .bars [name ].get_logger (header = header )
140-
0 commit comments