##// END OF EJS Templates
util: wrap lines with multi-byte characters correctly (issue2943)...
Mads Kiilerich -
r15065:24a6c3f9 stable
parent child Browse files
Show More
@@ -1148,16 +1148,14 b' def MBTextWrapper(**kwargs):'
1148 def __init__(self, **kwargs):
1148 def __init__(self, **kwargs):
1149 textwrap.TextWrapper.__init__(self, **kwargs)
1149 textwrap.TextWrapper.__init__(self, **kwargs)
1150
1150
1151 def _cutdown(self, str, space_left):
1151 def _cutdown(self, ucstr, space_left):
1152 l = 0
1152 l = 0
1153 ucstr = unicode(str, encoding.encoding)
1154 colwidth = unicodedata.east_asian_width
1153 colwidth = unicodedata.east_asian_width
1155 for i in xrange(len(ucstr)):
1154 for i in xrange(len(ucstr)):
1156 l += colwidth(ucstr[i]) in 'WFA' and 2 or 1
1155 l += colwidth(ucstr[i]) in 'WFA' and 2 or 1
1157 if space_left < l:
1156 if space_left < l:
1158 return (ucstr[:i].encode(encoding.encoding),
1157 return (ucstr[:i], ucstr[i:])
1159 ucstr[i:].encode(encoding.encoding))
1158 return ucstr, ''
1160 return str, ''
1161
1159
1162 # overriding of base class
1160 # overriding of base class
1163 def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
1161 def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
@@ -1179,10 +1177,13 b" def wrap(line, width, initindent='', han"
1179 if width <= maxindent:
1177 if width <= maxindent:
1180 # adjust for weird terminal size
1178 # adjust for weird terminal size
1181 width = max(78, maxindent + 1)
1179 width = max(78, maxindent + 1)
1180 line = line.decode(encoding.encoding, encoding.encodingmode)
1181 initindent = initindent.decode(encoding.encoding, encoding.encodingmode)
1182 hangindent = hangindent.decode(encoding.encoding, encoding.encodingmode)
1182 wrapper = MBTextWrapper(width=width,
1183 wrapper = MBTextWrapper(width=width,
1183 initial_indent=initindent,
1184 initial_indent=initindent,
1184 subsequent_indent=hangindent)
1185 subsequent_indent=hangindent)
1185 return wrapper.fill(line)
1186 return wrapper.fill(line).encode(encoding.encoding)
1186
1187
1187 def iterlines(iterator):
1188 def iterlines(iterator):
1188 for chunk in iterator:
1189 for chunk in iterator:
@@ -22,14 +22,14 b' Test alignment of multibyte characters'
22 > cmdtable = {
22 > cmdtable = {
23 > 'showoptlist':
23 > 'showoptlist':
24 > (showoptlist,
24 > (showoptlist,
25 > [('s', 'opt1', '', 'short width', '""" + s + """'),
25 > [('s', 'opt1', '', 'short width' + ' %(s)s' * 8, '%(s)s'),
26 > ('m', 'opt2', '', 'middle width', '""" + m + """'),
26 > ('m', 'opt2', '', 'middle width' + ' %(m)s' * 8, '%(m)s'),
27 > ('l', 'opt3', '', 'long width', '""" + l + """')
27 > ('l', 'opt3', '', 'long width' + ' %(l)s' * 8, '%(l)s')
28 > ],
28 > ],
29 > ""
29 > ""
30 > )
30 > )
31 > }
31 > }
32 > """)
32 > """ % globals())
33 > f.close()
33 > f.close()
34 > EOF
34 > EOF
35 $ S=`cat s`
35 $ S=`cat s`
@@ -52,9 +52,11 b' check alignment of option descriptions i'
52
52
53 options:
53 options:
54
54
55 -s --opt1 \xe7\x9f\xad\xe5\x90\x8d short width (esc)
55 -s --opt1 \xe7\x9f\xad\xe5\x90\x8d short width \xe7\x9f\xad\xe5\x90\x8d \xe7\x9f\xad\xe5\x90\x8d \xe7\x9f\xad\xe5\x90\x8d \xe7\x9f\xad\xe5\x90\x8d \xe7\x9f\xad\xe5\x90\x8d \xe7\x9f\xad\xe5\x90\x8d \xe7\x9f\xad\xe5\x90\x8d \xe7\x9f\xad\xe5\x90\x8d (esc)
56 -m --opt2 MIDDLE_ middle width
56 -m --opt2 MIDDLE_ middle width MIDDLE_ MIDDLE_ MIDDLE_ MIDDLE_ MIDDLE_
57 -l --opt3 \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d long width (esc)
57 MIDDLE_ MIDDLE_ MIDDLE_
58 -l --opt3 \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d long width \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d (esc)
59 \xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d (esc)
58
60
59 use "hg -v help showoptlist" to show global options
61 use "hg -v help showoptlist" to show global options
60
62
General Comments 0
You need to be logged in to leave comments. Login now