Skip to content

Commit

Permalink
Support formatted messages to remaining progress types
Browse files Browse the repository at this point in the history
This is a followup to the changes for verigak#76. We can now remove the write function.
  • Loading branch information
verigak committed Jul 20, 2020
1 parent e5c2368 commit d325dab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 0 additions & 7 deletions progress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ def clearln(self):
if self.file and self.is_tty():
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):
if self.file and self.is_tty():
self.clearln()
Expand Down
12 changes: 9 additions & 3 deletions progress/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@

class Counter(Infinite):
def update(self):
self.write(str(self.index))
message = self.message % self
line = ''.join([message, str(self.index)])
self.writeln(line)


class Countdown(Progress):
def update(self):
self.write(str(self.remaining))
message = self.message % self
line = ''.join([message, str(self.remaining)])
self.writeln(line)


class Stack(Progress):
Expand All @@ -34,7 +38,9 @@ class Stack(Progress):
def update(self):
nphases = len(self.phases)
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):
Expand Down

0 comments on commit d325dab

Please sign in to comment.