From 7671eddb8cd0f93df485c35f7d636516326cd5cf Mon Sep 17 00:00:00 2001 From: Yuxin Wang Date: Wed, 26 Sep 2018 23:24:49 -0400 Subject: [PATCH] Implement progressbar. --- p2pfs/ui/terminal.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/p2pfs/ui/terminal.py b/p2pfs/ui/terminal.py index 37bfe7c..cb62f29 100644 --- a/p2pfs/ui/terminal.py +++ b/p2pfs/ui/terminal.py @@ -58,7 +58,17 @@ class PeerTerminal(cmd.Cmd): filename, destionation, *_ = arg.split(' ') def progress(current, total): - print('{} / {}, {}%'.format(current, total, int(current * 100 / total))) + # TODO: add speed display + import sys + percent = current / total + progress_count = int(percent * 30) + dot_count = 30 - progress_count - 1 + sys.stdout.write('Downloading {} '.format(filename)) + sys.stdout.write('[' + progress_count * '=' + '>' + + dot_count * '.' + '] ' + '{: >3d}'.format(int(percent * 100)) + '%\r') + sys.stdout.flush() + if current == total: + print('Downloading {} ['.format(filename) + 30 * '=' + '>] 100%') self._peer.download(filename, destionation, progress)