Implement progressbar.
This commit is contained in:
parent
e2d130e687
commit
7671eddb8c
1 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue