@@ -49,16 +49,6 @@ def __init__(self, total: int, c1: RGB = DEFAULT_C1, c2: RGB = DEFAULT_C2):
4949 self .g = list (interp_xyz (c1 , c2 , self .w + 1 ))
5050
5151 self ._iter_pbar = iter (self ._pbar ())
52- # self._initial_bar()
53-
54- def _initial_bar (self ) -> None :
55- "print initial bar in end color"
56- print (
57- f'\x1b [48;2;{ self .c2 .r } ;{ self .c2 .g } ;{ self .c2 .b } m' + ' ' * self .w + '\x1b [0m' ,
58- end = '' ,
59- flush = True ,
60- )
61- print ('\r ' , end = '' , flush = True )
6252
6353 @staticmethod
6454 def randgrad () -> tuple [RGB , RGB ]:
@@ -84,15 +74,25 @@ def __iter__(self) -> PBar:
8474 def _true_colour (rgb : RGB ) -> str :
8575 return f'\x1b [48;2;{ rgb .r } ;{ rgb .g } ;{ rgb .b } m'
8676
87- def __next__ (self ) -> None :
88- s = [f'{ self ._true_colour (rgb )} ' for _ , rgb in next (self ._iter_pbar )]
77+ def _print_bar_chars (self , s : str ) -> None :
8978 _print_to_terminal (
9079 '\x1b 7' # save cursor position
9180 f'\x1b [{ self .h } ;{ self .curr } H' # move to bottom line
92- f'{ "" . join ( s ) } ' # the "bar" characters
81+ f'{ s } ' # the "bar" characters
9382 '\x1b [0m' # reset color
9483 '\x1b 8' # restore cursor position
9584 )
85+
86+ def _initial_bar (self ) -> None :
87+ "print initial bar in end color"
88+ self ._print_bar_chars (
89+ f'\x1b [48;2;{ self .c2 .r } ;{ self .c2 .g } ;{ self .c2 .b } m' + ' ' * self .w + '\x1b [0m'
90+ )
91+
92+ def __next__ (self ) -> None :
93+ s = [f'{ self ._true_colour (rgb )} ' for _ , rgb in next (self ._iter_pbar )]
94+ self ._print_bar_chars ('' .join (s ))
95+
9696 self .curr += len (s )
9797 if self .curr > self .w :
9898 raise StopIteration
@@ -117,6 +117,7 @@ def __enter__(self) -> PBar:
117117 '\x1b 8' # restore cursor position
118118 '\x1b [1A' # move cursor up
119119 )
120+ self ._initial_bar ()
120121 return self
121122
122123 def __exit__ (self , _exc_type : type , _exc_val : BaseException , _exc_tb : type ) -> None :
0 commit comments