Skip to content

Commit

Permalink
Make Progress nop with total=0 (e.g. stdin)
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw authored and anjakefala committed Nov 8, 2017
1 parent 6738b4a commit a91d09c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions visidata/vdtui.py
Expand Up @@ -413,19 +413,25 @@ class Progress:
def __init__(self, iterable=None, total=None):
self.sheet = threading.current_thread().sheet if threading.current_thread().daemon else Sheet('dummy')
self.iterable = iterable
self.thisTotal = total or len(iterable)
if total is None:
self.thisTotal = len(iterable)
else:
self.thisTotal = total
self.thisMade = 0

def __enter__(self):
self.sheet.progressTotal += self.thisTotal
if self.thisTotal:
self.sheet.progressTotal += self.thisTotal
return self

def addProgress(self, n):
self.sheet.progressMade += n
self.thisMade += n
if self.thisTotal:
self.sheet.progressMade += n
self.thisMade += n

def __exit__(self, exc_type, exc_val, tb):
self.sheet.progressMade += self.thisTotal-self.thisMade
if self.thisTotal:
self.sheet.progressMade += self.thisTotal-self.thisMade

def __iter__(self):
with self as prog:
Expand Down

0 comments on commit a91d09c

Please sign in to comment.