Recognize wide characters in description

… by using unicodedata.east_asian_width.

Co-authored-by: RedBug312 <redbug312@gmail.com>
This commit is contained in:
FichteFoll 2017-07-14 23:17:54 +08:00 committed by Casper da Costa-Luis
parent 825f7dc7ea
commit 124d72a4e3
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
2 changed files with 2 additions and 1 deletions

View File

@ -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:

View File

@ -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: