Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Enable multiple progressbars be created. #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion clint/textui/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ def show(self, progress, count=None):
self.expected_size, self.etadisp))
STREAM.flush()

def done(self):
def done(self, create_new=False):
if create_new:
return Bar(self.label, self.width, self.hide, self.empty_char,
self.filled_char, self.expected_size, self.every)
self.elapsed = time.time() - self.start
elapsed_disp = self.format_time(self.elapsed)
if not self.hide:
Expand Down
10 changes: 8 additions & 2 deletions examples/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@


if __name__ == '__main__':
with progress.Bar(expected_size=100.) as bar:
for i in range(3):
for i in range(100):
sleep(0.01)
bar.show(i)
bar = bar.done(i is not 3)
for i in progress.bar(range(100)):
sleep(random() * 0.2)

with progress.Bar(label="nonlinear", expected_size=10) as bar:
last_val = 0
for val in (1,2,3,9,10):
for val in (1, 2, 3, 9, 10):
sleep(2 * (val - last_val))
bar.show(val)
last_val = val
Expand Down