mirror of
https://github.com/verigak/progress.git
synced 2025-12-08 19:33:24 +00:00
Do not use ANSI to clear line
This commit is contained in:
@@ -47,15 +47,14 @@ class Infinite(object):
|
|||||||
for key, val in kwargs.items():
|
for key, val in kwargs.items():
|
||||||
setattr(self, key, val)
|
setattr(self, key, val)
|
||||||
|
|
||||||
self._width = 0
|
self._max_width = 0
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
if self.file and self.is_tty():
|
if self.file and self.is_tty():
|
||||||
if self.hide_cursor:
|
if self.hide_cursor:
|
||||||
print(HIDE_CURSOR, end='', file=self.file)
|
print(HIDE_CURSOR, end='', file=self.file)
|
||||||
atexit.register(self.finish)
|
atexit.register(self.finish)
|
||||||
print(self.message, end='', file=self.file)
|
self.writeln('')
|
||||||
self.file.flush()
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
if key.startswith('_'):
|
if key.startswith('_'):
|
||||||
@@ -87,14 +86,15 @@ class Infinite(object):
|
|||||||
def start(self):
|
def start(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def clearln(self):
|
|
||||||
if self.file and self.is_tty():
|
|
||||||
print('\r\x1b[K', end='', file=self.file)
|
|
||||||
|
|
||||||
def writeln(self, line):
|
def writeln(self, line):
|
||||||
if self.file and self.is_tty():
|
if self.file and self.is_tty():
|
||||||
self.clearln()
|
width = len(line)
|
||||||
print(line, end='', file=self.file)
|
if width < self._max_width:
|
||||||
|
# Add padding to cover previous contents
|
||||||
|
line += ' ' * (self._max_width - width)
|
||||||
|
else:
|
||||||
|
self._max_width = width
|
||||||
|
print('\r' + line, end='', file=self.file)
|
||||||
self.file.flush()
|
self.file.flush()
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ for bar_cls in (IncrementalBar, PixelBar, ShadyBar):
|
|||||||
sleep()
|
sleep()
|
||||||
|
|
||||||
for spin in (Spinner, PieSpinner, MoonSpinner, LineSpinner, PixelSpinner):
|
for spin in (Spinner, PieSpinner, MoonSpinner, LineSpinner, PixelSpinner):
|
||||||
for i in spin(spin.__name__ + ' %(index) 3d ').iter(range(100)):
|
for i in spin(spin.__name__ + ' %(index)d ').iter(range(100)):
|
||||||
sleep()
|
sleep()
|
||||||
|
|
||||||
for singleton in (Counter, Countdown, Stack, Pie):
|
for singleton in (Counter, Countdown, Stack, Pie):
|
||||||
|
|||||||
Reference in New Issue
Block a user