From cf8c6a92ecbb6a36eaf571b9e5320d120553348e Mon Sep 17 00:00:00 2001 From: MMGen Date: Sat, 26 May 2018 19:31:54 +0000 Subject: [PATCH] Fix CJK padding error --- mmgen/obj.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mmgen/obj.py b/mmgen/obj.py index 6d677278..eba85f40 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -34,13 +34,16 @@ def is_tw_label(s): return TwLabel(s,on_fail='silent') def is_wif(s): return WifKey(s,on_fail='silent') def is_viewkey(s): return ViewKey(s,on_fail='silent') -def truncate_str(s,w): +def truncate_str(s,width): # width = screen width wide_count = 0 - w -= 1 for i in range(len(s)): wide_count += unicodedata.east_asian_width(s[i]) in ('F','W') - if wide_count + i > w: - return s[:i] + if wide_count + i >= width: + return s[:i] + ('',' ')[ + unicodedata.east_asian_width(s[i]) in ('F','W') + and wide_count + i == width] + else: # pad the string to width if necessary + return s + ' '*(width-len(s)-wide_count) class MMGenObject(object):