adapt formatting to narrow screens, do not crash, fixes #1628

when screen width was too narrow, the {space} placeholder could get negative,
which crashes as it is a width specification.

now we simplify progress output if screen is narrow.
we stop output completely if screen is ridiculously narrow.
This commit is contained in:
Thomas Waldmann 2016-09-23 00:26:04 +02:00
parent 50cef5a768
commit 7e7dd9688d
1 changed files with 7 additions and 3 deletions

View File

@ -223,9 +223,13 @@ class Statistics:
msg = '{0.osize_fmt} O {0.csize_fmt} C {0.usize_fmt} D {0.nfiles} N '.format(self) msg = '{0.osize_fmt} O {0.csize_fmt} C {0.usize_fmt} D {0.nfiles} N '.format(self)
path = remove_surrogates(item[b'path']) if item else '' path = remove_surrogates(item[b'path']) if item else ''
space = columns - len(msg) space = columns - len(msg)
if space < len('...') + len(path): if space < 12:
path = '%s...%s' % (path[:(space // 2) - len('...')], path[-space // 2:]) msg = ''
msg += "{0:<{space}}".format(path, space=space) space = columns - len(msg)
if space >= 8:
if space < len('...') + len(path):
path = '%s...%s' % (path[:(space // 2) - len('...')], path[-space // 2:])
msg += "{0:<{space}}".format(path, space=space)
else: else:
msg = ' ' * columns msg = ' ' * columns
print(msg, file=stream or sys.stderr, end="\r", flush=True) print(msg, file=stream or sys.stderr, end="\r", flush=True)