comparison mercurial/util.py @ 8938:9b8c9266c59d

commands: wrap short descriptions in 'hg help' The code for wrapping a single line of text with a hanging indent was duplicated in commands and help -- it's now moved to a new function called wrap in util. The function defaults to a line width is 78 chars, and this un-wraps some command line flag descriptions, hence the test output changes.
author Martin Geisler <mg@lazybytes.net>
date Wed, 24 Jun 2009 19:15:58 +0200
parents 7a9151bc5b37
children 0001e49f1c11 9f191931c859
comparison
equal deleted inserted replaced
8937:ea798e03a32e 8938:9b8c9266c59d
14 """ 14 """
15 15
16 from i18n import _ 16 from i18n import _
17 import error, osutil 17 import error, osutil
18 import cStringIO, errno, re, shutil, sys, tempfile, traceback 18 import cStringIO, errno, re, shutil, sys, tempfile, traceback
19 import os, stat, time, calendar, random 19 import os, stat, time, calendar, random, textwrap
20 import imp 20 import imp
21 21
22 # Python compatibility 22 # Python compatibility
23 23
24 def sha1(s): 24 def sha1(s):
1240 pass 1240 pass
1241 except ImportError: 1241 except ImportError:
1242 pass 1242 pass
1243 return 80 1243 return 80
1244 1244
1245 def wrap(line, hangindent, width=78):
1246 padding = '\n' + ' ' * hangindent
1247 return padding.join(textwrap.wrap(line, width=width - hangindent))
1248
1245 def iterlines(iterator): 1249 def iterlines(iterator):
1246 for chunk in iterator: 1250 for chunk in iterator:
1247 for line in chunk.splitlines(): 1251 for line in chunk.splitlines():
1248 yield line 1252 yield line