Support formatted messages to remaining progress types

This is a followup to the changes for #76. We can now remove the write function.
This commit is contained in:
Georgios Verigakis
2020-07-20 12:46:43 +03:00
parent e5c2368c6b
commit d325dab247
2 changed files with 9 additions and 10 deletions

View File

@@ -91,13 +91,6 @@ class Infinite(object):
if self.file and self.is_tty(): if self.file and self.is_tty():
print('\r\x1b[K', end='', file=self.file) print('\r\x1b[K', end='', file=self.file)
def write(self, s):
if self.file and self.is_tty():
line = self.message + s.ljust(self._width)
print('\r' + line, end='', file=self.file)
self._width = max(self._width, len(s))
self.file.flush()
def writeln(self, line): def writeln(self, line):
if self.file and self.is_tty(): if self.file and self.is_tty():
self.clearln() self.clearln()

View File

@@ -20,12 +20,16 @@ from . import Infinite, Progress
class Counter(Infinite): class Counter(Infinite):
def update(self): def update(self):
self.write(str(self.index)) message = self.message % self
line = ''.join([message, str(self.index)])
self.writeln(line)
class Countdown(Progress): class Countdown(Progress):
def update(self): def update(self):
self.write(str(self.remaining)) message = self.message % self
line = ''.join([message, str(self.remaining)])
self.writeln(line)
class Stack(Progress): class Stack(Progress):
@@ -34,7 +38,9 @@ class Stack(Progress):
def update(self): def update(self):
nphases = len(self.phases) nphases = len(self.phases)
i = min(nphases - 1, int(self.progress * nphases)) i = min(nphases - 1, int(self.progress * nphases))
self.write(self.phases[i]) message = self.message % self
line = ''.join([message, self.phases[i]])
self.writeln(line)
class Pie(Stack): class Pie(Stack):