diff options
Diffstat (limited to 'debian/patches/79_unicode_width.patch')
-rw-r--r-- | debian/patches/79_unicode_width.patch | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/debian/patches/79_unicode_width.patch b/debian/patches/79_unicode_width.patch new file mode 100644 index 0000000..164240d --- /dev/null +++ b/debian/patches/79_unicode_width.patch @@ -0,0 +1,52 @@ +Try to guess the real width of a string, see comment in the patch. + +Without this patch, we'd get something like this: + +01 03:16 我的地盘 (My Territory).: 6.31x [ !] [coding @3.72x done, 133kbit +02 05:26 七里香 (Orange Jasmine): 6.92x [ ] 2% done, ETA: 01:18, 4.03x +03 03:56 借口 (Excuse).........: 7.51x [ ] waiting for encoder. +04 04:46 外婆 (Grandma)........: :DAE: [ > 057812 00 ] == :^D + ^^^^^^^^^^^^^^^^^^^^^^^ + +--- a/jack_ripstuff.py 2007-08-27 13:59:52.000000000 +0200 ++++ b/jack_ripstuff.py 2007-08-29 12:49:41.000000000 +0200 +@@ -19,6 +19,7 @@ + import jack_freedb + + import locale ++import unicodedata + + from jack_globals import * + +@@ -33,6 +34,21 @@ + + raw_space = None # free diskspace + ++# There's currently no good way in Python to obtain the real width a string ++# will take up on the screen since it may e.g. depend on how the terminal ++# displays wide characters. This function is a first attempt to at least ++# get an approximate idea of the width of a string (assuming that wide ++# characters take up two columns on the screen). This is only to be used ++# until there's a real solution in Python. ++def width(s): ++ w = 0 ++ for c in s.decode(locale.getpreferredencoding()): ++ if unicodedata.east_asian_width(c) in ("W", "F"): ++ w += 2 ++ else: ++ w += 1 ++ return w ++ + def gen_printable_names(track_names, todo): + global printable_names + global max_name_len +@@ -69,7 +85,7 @@ + else: + tmp = tmp + track_names[i[NUM]][1] + p_tmp = tmp.encode(locale.getpreferredencoding(), "replace") +- printable_names[i[NUM]] = p_tmp + "." * (max_name_len - len(tmp)) ++ printable_names[i[NUM]] = p_tmp + "." * (max_name_len - width(p_tmp)) + else: + if cf['_show_time']: + printable_names[i[NUM]] = ("%02i " % i[NUM]) + len_tmp + "." * (max_name_len - len(i[NAME]) - 6) + |