1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)
|