Fixed overlong filename w/ terminal width

This commit is contained in:
jpk 2019-09-01 18:55:02 +02:00
parent 6831c64cc4
commit 5c8a529fb7
2 changed files with 9 additions and 5 deletions

View File

@ -3,7 +3,8 @@ from setuptools import setup, find_namespace_packages
setup(
name="sbeam",
version="0.1",
description="",
version="0.3",
author="JayPiKay",
author_email="jpk+python@goatpr0n.de",
url='https://git.goatpr0n.de/',

View File

@ -83,14 +83,17 @@ def receive(host, destination):
headers={'User-Agent': 'sbeam'}) as response:
assert response.status_code == 200
with click.progressbar(filelist, label='Receiving',
bar_template='%(label)s %(info)s:') as bar:
with click.progressbar(filelist, label='Receiving') as bar:
for rawinfo in bar:
if not rawinfo:
break
filename, filesize, filepath, timestamp = rawinfo.split('||')
# TODO fix when filename to long
bar.bar_template = f'%(label)s %(info)s: {filename}'
width, height = click.get_terminal_size()
term_space = 70 + len(filename)
printname = filename
if term_space > width:
printname = filename[:-1*(term_space-width-4)]
bar.bar_template = f'%(label)s [%(bar)s] %(info)s: {printname}'
fullpath = os.path.join(destination, filepath[1:])
os.makedirs(fullpath, exist_ok=True)