util: make wrap() require a width argument

This keeps hgweb's help engine from poking at file descriptors that
don't exist.
This commit is contained in:
Matt Mackall 2010-10-10 18:02:52 -05:00
parent 78b26c82ec
commit a3ff3a53e2
2 changed files with 3 additions and 5 deletions

View File

@ -1949,7 +1949,7 @@ def help_(ui, name=None, with_version=False, unknowncmd=False):
commands = cmds[f].replace("|",", ")
ui.write(" %s:\n %s\n"%(commands, h[f]))
else:
ui.write('%s\n' % (util.wrap(h[f],
ui.write('%s\n' % (util.wrap(h[f], textwidth,
initindent=' %-*s ' % (m, f),
hangindent=' ' * (m + 4))))
@ -2106,7 +2106,7 @@ def help_(ui, name=None, with_version=False, unknowncmd=False):
if desc:
initindent = ' %s%s ' % (opt, ' ' * (hanging - width))
hangindent = ' ' * (hanging + 3)
ui.write('%s\n' % (util.wrap(desc,
ui.write('%s\n' % (util.wrap(desc, textwidth,
initindent=initindent,
hangindent=hangindent)))
else:

View File

@ -1313,9 +1313,7 @@ class MBTextWrapper(textwrap.TextWrapper):
#### naming convention of above implementation follows 'textwrap' module
def wrap(line, width=None, initindent='', hangindent=''):
if width is None:
width = termwidth() - 2
def wrap(line, width, initindent='', hangindent=''):
maxindent = max(len(hangindent), len(initindent))
if width <= maxindent:
# adjust for weird terminal size