From 124d72a4e341cc62ce7450d577073a9ba08a1a6d Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Fri, 14 Jul 2017 23:17:54 +0800 Subject: [PATCH] Recognize wide characters in description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … by using unicodedata.east_asian_width. Co-authored-by: RedBug312 --- tqdm/std.py | 2 +- tqdm/utils.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tqdm/std.py b/tqdm/std.py index 56d0628d..54336230 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -490,7 +490,7 @@ class tqdm(Comparable): return nobar full_bar = Bar( 0, - max(1, ncols - len(RE_ANSI.sub('', nobar))) if ncols else 10, + max(1, ncols - _text_width(RE_ANSI.sub('', nobar))) if ncols else 10, charset=Bar.BLANK) return bar_format.format(bar=full_bar, **format_dict) else: diff --git a/tqdm/utils.py b/tqdm/utils.py index ee8a8769..17b6aba6 100644 --- a/tqdm/utils.py +++ b/tqdm/utils.py @@ -286,6 +286,7 @@ def _term_move_up(): # pragma: no cover def _text_width(s): # pragma: no cover + # TODO consider using wcswidth third-party package for 0-width characters try: from unicodedata import east_asian_width except ImportError: