From 9fa6ef1f6f248f6aaa24f801bdee14a76e22eb19 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 10 Feb 2016 16:21:39 +0800 Subject: [PATCH] [bar] don't overflow on large files (>1G) https://github.com/soimort/you-get/pull/898#issuecomment-180015169 --- src/you_get/common.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/you_get/common.py b/src/you_get/common.py index 6244c579..83cd3271 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -554,9 +554,11 @@ class SimpleProgressBar: total_pieces_len = len(str(total_pieces)) # 38 is the size of all statically known size in self.bar - self.bar_size = self.term_size - 38 - 2*total_pieces_len - self.bar = '{0:>5}%% ({1:>5}/{2:<5}MB) ├{3:─<%s}┤[{4:>%s}/{5:>%s}] {6}' % ( - self.bar_size, total_pieces_len, total_pieces_len) + total_str = '%5s' % round(self.total_size / 1048576, 1) + total_str_width = max(len(total_str), 5) + self.bar_size = self.term_size - 28 - 2*total_pieces_len - 2*total_str_width + self.bar = '{:>5}%% ({:>%s}/%sMB) ├{:─<%s}┤[{:>%s}/{:>%s}] {}' % ( + total_str_width, total_str, self.bar_size, total_pieces_len, total_pieces_len) def update(self): self.displayed = True @@ -573,7 +575,7 @@ class SimpleProgressBar: else: plus = '' bar = '█' * dots + plus - bar = self.bar.format(percent, round(self.received / 1048576, 1), round(self.total_size / 1048576, 1), bar, self.current_piece, self.total_pieces, self.speed) + bar = self.bar.format(percent, round(self.received / 1048576, 1), bar, self.current_piece, self.total_pieces, self.speed) sys.stdout.write('\r' + bar) sys.stdout.flush()