Commit 0f83f45b authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Handle overflow in progress bar

parent fd78c0a5
...@@ -543,24 +543,33 @@ class Progress(object): ...@@ -543,24 +543,33 @@ class Progress(object):
def progress(self, value, total): def progress(self, value, total):
fvalue = self.fmt(value) overflow = value > total
ftotal = self.fmt(total) value = min(value, total)
suffix = '{} / {} {}'.format(fvalue, ftotal, self.label).rstrip()
# arbitrary fallback of 50 columns if # arbitrary fallback of 50 columns if
# terminal width cannot be determined # terminal width cannot be determined
if self.width is None: width = Progress.get_terminal_width(50) if self.width is None: width = Progress.get_terminal_width(50)
else: width = self.width else: width = self.width
width = width - (len(suffix) + 3) fvalue = self.fmt(value)
ftotal = self.fmt(total)
suffix = '{} / {} {}'.format(fvalue, ftotal, self.label).rstrip()
# +5: - square brackets around bar
# - space between bar and tally
# - space+spin in case of overflow
width = width - (len(suffix) + 5)
completed = int(round(width * (value / total))) completed = int(round(width * (value / total)))
remaining = width - completed remaining = width - completed
line = '[{}{}] {}'.format( progress = '[{}{}] {}'.format('#' * completed,
'#' * completed, ' ' * remaining,
' ' * remaining, suffix)
suffix)
printmsg(line, end='\r') printmsg(progress, end='')
if overflow:
printmsg(' ', end='')
self.spin()
printmsg(end='\r')
@staticmethod @staticmethod
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment