Show More
@@ -1697,7 +1697,9 b' def help_(ui, name=None, with_version=Fa' | |||||
1697 | commands = cmds[f].replace("|",", ") |
|
1697 | commands = cmds[f].replace("|",", ") | |
1698 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
1698 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
1699 | else: |
|
1699 | else: | |
1700 |
ui.write(' |
|
1700 | ui.write('%s\n' % (util.wrap(h[f], | |
|
1701 | initindent=' %-*s ' % (m, f), | |||
|
1702 | hangindent=' ' * (m + 4)))) | |||
1701 |
|
1703 | |||
1702 | if not ui.quiet: |
|
1704 | if not ui.quiet: | |
1703 | addglobalopts(True) |
|
1705 | addglobalopts(True) | |
@@ -1824,8 +1826,11 b' def help_(ui, name=None, with_version=Fa' | |||||
1824 | opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0]) |
|
1826 | opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0]) | |
1825 | for first, second in opt_output: |
|
1827 | for first, second in opt_output: | |
1826 | if second: |
|
1828 | if second: | |
1827 | second = util.wrap(second, opts_len + 3) |
|
1829 | initindent = ' %-*s ' % (opts_len, first) | |
1828 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
1830 | hangindent = ' ' * (opts_len + 3) | |
|
1831 | ui.write('%s\n' % (util.wrap(second, | |||
|
1832 | initindent=initindent, | |||
|
1833 | hangindent=hangindent))) | |||
1829 | else: |
|
1834 | else: | |
1830 | ui.write("%s\n" % first) |
|
1835 | ui.write("%s\n" % first) | |
1831 |
|
1836 |
@@ -72,6 +72,6 b' def colwidth(s):' | |||||
72 | d = s.decode(encoding, 'replace') |
|
72 | d = s.decode(encoding, 'replace') | |
73 | if hasattr(unicodedata, 'east_asian_width'): |
|
73 | if hasattr(unicodedata, 'east_asian_width'): | |
74 | w = unicodedata.east_asian_width |
|
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 | return len(d) |
|
76 | return len(d) | |
77 |
|
77 |
@@ -35,8 +35,8 b' It only supports a small subset of reStr' | |||||
35 | - inline literals (no other inline markup is not recognized) |
|
35 | - inline literals (no other inline markup is not recognized) | |
36 | """ |
|
36 | """ | |
37 |
|
37 | |||
38 |
import re, sys |
|
38 | import re, sys | |
39 |
|
39 | import util | ||
40 |
|
40 | |||
41 | def findblocks(text): |
|
41 | def findblocks(text): | |
42 | """Find continuous blocks of lines in text. |
|
42 | """Find continuous blocks of lines in text. | |
@@ -304,9 +304,9 b' def formatblock(block, width):' | |||||
304 | hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) |
|
304 | hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) | |
305 | defindent = indent + hang * ' ' |
|
305 | defindent = indent + hang * ' ' | |
306 | text = ' '.join(map(str.strip, block['lines'][1:])) |
|
306 | text = ' '.join(map(str.strip, block['lines'][1:])) | |
307 |
return |
|
307 | return '%s\n%s' % (term, util.wrap(text, width=width, | |
308 |
|
|
308 | initindent=defindent, | |
309 |
|
|
309 | hangindent=defindent)) | |
310 | subindent = indent |
|
310 | subindent = indent | |
311 | if block['type'] == 'bullet': |
|
311 | if block['type'] == 'bullet': | |
312 | if block['lines'][0].startswith('| '): |
|
312 | if block['lines'][0].startswith('| '): | |
@@ -338,9 +338,9 b' def formatblock(block, width):' | |||||
338 | subindent = indent + (len(option) + len(arg)) * ' ' |
|
338 | subindent = indent + (len(option) + len(arg)) * ' ' | |
339 |
|
339 | |||
340 | text = ' '.join(map(str.strip, block['lines'])) |
|
340 | text = ' '.join(map(str.strip, block['lines'])) | |
341 |
return |
|
341 | return util.wrap(text, width=width, | |
342 |
|
|
342 | initindent=indent, | |
343 |
|
|
343 | hangindent=subindent) | |
344 |
|
344 | |||
345 |
|
345 | |||
346 | def format(text, width, indent=0, keep=None): |
|
346 | def format(text, width, indent=0, keep=None): |
@@ -5,7 +5,7 b'' | |||||
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 |
import cgi, re, os, time, urllib |
|
8 | import cgi, re, os, time, urllib | |
9 | import util, encoding |
|
9 | import util, encoding | |
10 |
|
10 | |||
11 | def stringify(thing): |
|
11 | def stringify(thing): | |
@@ -61,15 +61,17 b' def fill(text, width):' | |||||
61 | while True: |
|
61 | while True: | |
62 | m = para_re.search(text, start) |
|
62 | m = para_re.search(text, start) | |
63 | if not m: |
|
63 | if not m: | |
64 | w = len(text) |
|
64 | uctext = unicode(text[start:], encoding.encoding) | |
65 | while w > start and text[w - 1].isspace(): |
|
65 | w = len(uctext) | |
|
66 | while 0 < w and uctext[w - 1].isspace(): | |||
66 | w -= 1 |
|
67 | w -= 1 | |
67 | yield text[start:w], text[w:] |
|
68 | yield (uctext[:w].encode(encoding.encoding), | |
|
69 | uctext[w:].encode(encoding.encoding)) | |||
68 | break |
|
70 | break | |
69 | yield text[start:m.start(0)], m.group(1) |
|
71 | yield text[start:m.start(0)], m.group(1) | |
70 | start = m.end(1) |
|
72 | start = m.end(1) | |
71 |
|
73 | |||
72 |
return "".join([space_re.sub(' ', |
|
74 | return "".join([space_re.sub(' ', util.wrap(para, width=width)) + rest | |
73 | for para, rest in findparas()]) |
|
75 | for para, rest in findparas()]) | |
74 |
|
76 | |||
75 | def firstline(text): |
|
77 | def firstline(text): |
@@ -16,7 +16,7 b' hide platform-specific details from the ' | |||||
16 | from i18n import _ |
|
16 | from i18n import _ | |
17 | import error, osutil, encoding |
|
17 | import error, osutil, encoding | |
18 | import cStringIO, errno, re, shutil, sys, tempfile, traceback |
|
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 | import imp |
|
20 | import imp | |
21 |
|
21 | |||
22 | # Python compatibility |
|
22 | # Python compatibility | |
@@ -1257,21 +1257,49 b' def uirepr(s):' | |||||
1257 | # Avoid double backslash in Windows path repr() |
|
1257 | # Avoid double backslash in Windows path repr() | |
1258 | return repr(s).replace('\\\\', '\\') |
|
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 | if width is None: |
|
1293 | if width is None: | |
1262 | width = termwidth() - 2 |
|
1294 | width = termwidth() - 2 | |
1263 | if width <= hangindent: |
|
1295 | maxindent = max(len(hangindent), len(initindent)) | |
|
1296 | if width <= maxindent: | |||
1264 | # adjust for weird terminal size |
|
1297 | # adjust for weird terminal size | |
1265 |
width = max(78, |
|
1298 | width = max(78, maxindent + 1) | |
1266 | padding = '\n' + ' ' * hangindent |
|
1299 | wrapper = MBTextWrapper(width=width, | |
1267 | # To avoid corrupting multi-byte characters in line, we must wrap |
|
1300 | initial_indent=initindent, | |
1268 | # a Unicode string instead of a bytestring. |
|
1301 | subsequent_indent=hangindent) | |
1269 | try: |
|
1302 | return wrapper.fill(line) | |
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)) |
|
|||
1275 |
|
1303 | |||
1276 | def iterlines(iterator): |
|
1304 | def iterlines(iterator): | |
1277 | for chunk in iterator: |
|
1305 | for chunk in iterator: |
General Comments 0
You need to be logged in to leave comments.
Login now