mirror of
https://github.com/verigak/progress.git
synced 2025-12-08 19:33:24 +00:00
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:
@@ -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()
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user