From 5c8a529fb735797722b66c07706f93702389fc93 Mon Sep 17 00:00:00 2001 From: JayPiKay Date: Sun, 1 Sep 2019 18:55:02 +0200 Subject: [PATCH] Fixed overlong filename w/ terminal width --- setup.py | 3 ++- src/sbeam.py | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index aa81115..a4af114 100755 --- a/setup.py +++ b/setup.py @@ -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/', diff --git a/src/sbeam.py b/src/sbeam.py index 2797154..bec7a26 100755 --- a/src/sbeam.py +++ b/src/sbeam.py @@ -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)