##// END OF EJS Templates
replace Python standard textwrap by MBCS sensitive one for i18n text...
FUJIWARA Katsunori -
r11297:d320e704 default
parent child Browse files
Show More
@@ -1697,7 +1697,9 b' def help_(ui, name=None, with_version=Fa'
1697 1697 commands = cmds[f].replace("|",", ")
1698 1698 ui.write(" %s:\n %s\n"%(commands, h[f]))
1699 1699 else:
1700 ui.write(' %-*s %s\n' % (m, f, util.wrap(h[f], m + 4)))
1700 ui.write('%s\n' % (util.wrap(h[f],
1701 initindent=' %-*s ' % (m, f),
1702 hangindent=' ' * (m + 4))))
1701 1703
1702 1704 if not ui.quiet:
1703 1705 addglobalopts(True)
@@ -1824,8 +1826,11 b' def help_(ui, name=None, with_version=Fa'
1824 1826 opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
1825 1827 for first, second in opt_output:
1826 1828 if second:
1827 second = util.wrap(second, opts_len + 3)
1828 ui.write(" %-*s %s\n" % (opts_len, first, second))
1829 initindent = ' %-*s ' % (opts_len, first)
1830 hangindent = ' ' * (opts_len + 3)
1831 ui.write('%s\n' % (util.wrap(second,
1832 initindent=initindent,
1833 hangindent=hangindent)))
1829 1834 else:
1830 1835 ui.write("%s\n" % first)
1831 1836
@@ -72,6 +72,6 b' def colwidth(s):'
72 72 d = s.decode(encoding, 'replace')
73 73 if hasattr(unicodedata, 'east_asian_width'):
74 74 w = unicodedata.east_asian_width
75 return sum([w(c) in 'WF' and 2 or 1 for c in d])
75 return sum([w(c) in 'WFA' and 2 or 1 for c in d])
76 76 return len(d)
77 77
@@ -35,8 +35,8 b' It only supports a small subset of reStr'
35 35 - inline literals (no other inline markup is not recognized)
36 36 """
37 37
38 import re, sys, textwrap
39
38 import re, sys
39 import util
40 40
41 41 def findblocks(text):
42 42 """Find continuous blocks of lines in text.
@@ -304,9 +304,9 b' def formatblock(block, width):'
304 304 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip())
305 305 defindent = indent + hang * ' '
306 306 text = ' '.join(map(str.strip, block['lines'][1:]))
307 return "%s\n%s" % (term, textwrap.fill(text, width=width,
308 initial_indent=defindent,
309 subsequent_indent=defindent))
307 return '%s\n%s' % (term, util.wrap(text, width=width,
308 initindent=defindent,
309 hangindent=defindent))
310 310 subindent = indent
311 311 if block['type'] == 'bullet':
312 312 if block['lines'][0].startswith('| '):
@@ -338,9 +338,9 b' def formatblock(block, width):'
338 338 subindent = indent + (len(option) + len(arg)) * ' '
339 339
340 340 text = ' '.join(map(str.strip, block['lines']))
341 return textwrap.fill(text, width=width,
342 initial_indent=indent,
343 subsequent_indent=subindent)
341 return util.wrap(text, width=width,
342 initindent=indent,
343 hangindent=subindent)
344 344
345 345
346 346 def format(text, width, indent=0, keep=None):
@@ -5,7 +5,7 b''
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 import cgi, re, os, time, urllib, textwrap
8 import cgi, re, os, time, urllib
9 9 import util, encoding
10 10
11 11 def stringify(thing):
@@ -61,15 +61,17 b' def fill(text, width):'
61 61 while True:
62 62 m = para_re.search(text, start)
63 63 if not m:
64 w = len(text)
65 while w > start and text[w - 1].isspace():
64 uctext = unicode(text[start:], encoding.encoding)
65 w = len(uctext)
66 while 0 < w and uctext[w - 1].isspace():
66 67 w -= 1
67 yield text[start:w], text[w:]
68 yield (uctext[:w].encode(encoding.encoding),
69 uctext[w:].encode(encoding.encoding))
68 70 break
69 71 yield text[start:m.start(0)], m.group(1)
70 72 start = m.end(1)
71 73
72 return "".join([space_re.sub(' ', textwrap.fill(para, width)) + rest
74 return "".join([space_re.sub(' ', util.wrap(para, width=width)) + rest
73 75 for para, rest in findparas()])
74 76
75 77 def firstline(text):
@@ -16,7 +16,7 b' hide platform-specific details from the '
16 16 from i18n import _
17 17 import error, osutil, encoding
18 18 import cStringIO, errno, re, shutil, sys, tempfile, traceback
19 import os, stat, time, calendar, textwrap, signal
19 import os, stat, time, calendar, textwrap, unicodedata, signal
20 20 import imp
21 21
22 22 # Python compatibility
@@ -1257,21 +1257,49 b' def uirepr(s):'
1257 1257 # Avoid double backslash in Windows path repr()
1258 1258 return repr(s).replace('\\\\', '\\')
1259 1259
1260 def wrap(line, hangindent, width=None):
1260 #### naming convention of below implementation follows 'textwrap' module
1261
1262 class MBTextWrapper(textwrap.TextWrapper):
1263 def __init__(self, **kwargs):
1264 textwrap.TextWrapper.__init__(self, **kwargs)
1265
1266 def _cutdown(self, str, space_left):
1267 l = 0
1268 ucstr = unicode(str, encoding.encoding)
1269 w = unicodedata.east_asian_width
1270 for i in xrange(len(ucstr)):
1271 l += w(ucstr[i]) in 'WFA' and 2 or 1
1272 if space_left < l:
1273 return (ucstr[:i].encode(encoding.encoding),
1274 ucstr[i:].encode(encoding.encoding))
1275 return str, ''
1276
1277 # ----------------------------------------
1278 # overriding of base class
1279
1280 def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
1281 space_left = max(width - cur_len, 1)
1282
1283 if self.break_long_words:
1284 cut, res = self._cutdown(reversed_chunks[-1], space_left)
1285 cur_line.append(cut)
1286 reversed_chunks[-1] = res
1287 elif not cur_line:
1288 cur_line.append(reversed_chunks.pop())
1289
1290 #### naming convention of above implementation follows 'textwrap' module
1291
1292 def wrap(line, width=None, initindent='', hangindent=''):
1261 1293 if width is None:
1262 1294 width = termwidth() - 2
1263 if width <= hangindent:
1295 maxindent = max(len(hangindent), len(initindent))
1296 if width <= maxindent:
1264 1297 # adjust for weird terminal size
1265 width = max(78, hangindent + 1)
1266 padding = '\n' + ' ' * hangindent
1267 # To avoid corrupting multi-byte characters in line, we must wrap
1268 # a Unicode string instead of a bytestring.
1269 try:
1270 u = line.decode(encoding.encoding)
1271 w = padding.join(textwrap.wrap(u, width=width - hangindent))
1272 return w.encode(encoding.encoding)
1273 except UnicodeDecodeError:
1274 return padding.join(textwrap.wrap(line, width=width - hangindent))
1298 width = max(78, maxindent + 1)
1299 wrapper = MBTextWrapper(width=width,
1300 initial_indent=initindent,
1301 subsequent_indent=hangindent)
1302 return wrapper.fill(line)
1275 1303
1276 1304 def iterlines(iterator):
1277 1305 for chunk in iterator:
@@ -121,18 +121,18 b' tip 5:db5'
121 121 ? 3:770b9b11621d
122 122 % hg tags (latin-1)
123 123 tip 5:db5520b4645f
124 3:770b9b11621d
124 � 3:770b9b11621d
125 125 % hg tags (utf-8)
126 126 tip 5:db5520b4645f
127 é 3:770b9b11621d
127 é 3:770b9b11621d
128 128 % hg branches (ascii)
129 129 ? 5:db5520b4645f
130 130 default 4:9cff3c980b58 (inactive)
131 131 % hg branches (latin-1)
132 5:db5520b4645f
132 � 5:db5520b4645f
133 133 default 4:9cff3c980b58 (inactive)
134 134 % hg branches (utf-8)
135 é 5:db5520b4645f
135 é 5:db5520b4645f
136 136 default 4:9cff3c980b58 (inactive)
137 137 % hg log (utf-8)
138 138 changeset: 5:db5520b4645f
General Comments 0
You need to be logged in to leave comments. Login now