From bf00eba1c1d2cbdcc5d512b5d9e17dc80f4189a2 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 18 May 2016 18:32:29 +0200 Subject: [PATCH] use swidth when doing terminal output width computations, fixes #1051 cjk glyphs occupy 2 cells' width on the terminal. --- borg/helpers.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/borg/helpers.py b/borg/helpers.py index 7e783f3eb..9582564a1 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -32,6 +32,7 @@ from . import chunker from .constants import * # NOQA from . import crypto from .compress import COMPR_BUFFER, get_compressor +from .platform import swidth from . import shellpattern import msgpack import msgpack.fallback @@ -214,9 +215,9 @@ class Statistics: if not final: 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 '' - space = columns - len(msg) - if space < len('...') + len(path): - path = '%s...%s' % (path[:(space // 2) - len('...')], path[-space // 2:]) + space = columns - swidth(msg) + if space < swidth('...') + swidth(path): + path = '%s...%s' % (path[:(space // 2) - swidth('...')], path[-space // 2:]) msg += "{0:<{space}}".format(path, space=space) else: msg = ' ' * columns