diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -8,7 +8,7 @@ from node import hex, nullid, nullrev, short from lock import release from i18n import _, gettext -import os, re, sys, textwrap, subprocess, difflib, time +import os, re, sys, subprocess, difflib, time import hg, util, revlog, bundlerepo, extensions, copies, context, error import patch, help, mdiff, tempfile, url, encoding import archival, changegroup, cmdutil, sshserver, hbisect @@ -1514,7 +1514,7 @@ def help_(ui, name=None, with_version=Fa commands = cmds[f].replace("|",", ") ui.write(" %s:\n %s\n"%(commands, h[f])) else: - ui.write(' %-*s %s\n' % (m, f, h[f])) + ui.write(' %-*s %s\n' % (m, f, util.wrap(h[f], m + 4))) if name != 'shortlist': exts, maxlength = extensions.enabled() @@ -1617,11 +1617,8 @@ def help_(ui, name=None, with_version=Fa opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0]) for first, second in opt_output: if second: - # wrap descriptions at 70 characters, just like the - # main help texts - second = textwrap.wrap(second, width=70 - opts_len - 3) - pad = '\n' + ' ' * (opts_len + 3) - ui.write(" %-*s %s\n" % (opts_len, first, pad.join(second))) + second = util.wrap(second, opts_len + 3) + ui.write(" %-*s %s\n" % (opts_len, first, second)) else: ui.write("%s\n" % first) diff --git a/mercurial/help.py b/mercurial/help.py --- a/mercurial/help.py +++ b/mercurial/help.py @@ -5,9 +5,8 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2, incorporated herein by reference. -import textwrap from i18n import _ -import extensions +import extensions, util def moduledoc(file): @@ -46,11 +45,8 @@ def listexts(header, exts, maxlength): return '' result = '\n%s\n\n' % header for name, desc in sorted(exts.iteritems()): - # wrap desc at 70 characters, just like the main help texts - desc = textwrap.wrap(desc, width=78 - maxlength - 4) - pad = '\n' + ' ' * (maxlength + 4) - result += ' %s %s\n' % (name.ljust(maxlength), - pad.join(desc)) + desc = util.wrap(desc, maxlength + 4) + result += ' %s %s\n' % (name.ljust(maxlength), desc) return result def extshelp(): diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -16,7 +16,7 @@ hide platform-specific details from the from i18n import _ import error, osutil import cStringIO, errno, re, shutil, sys, tempfile, traceback -import os, stat, time, calendar, random +import os, stat, time, calendar, random, textwrap import imp # Python compatibility @@ -1242,6 +1242,10 @@ def termwidth(): pass return 80 +def wrap(line, hangindent, width=78): + padding = '\n' + ' ' * hangindent + return padding.join(textwrap.wrap(line, width=width - hangindent)) + def iterlines(iterator): for chunk in iterator: for line in chunk.splitlines(): diff --git a/tests/test-extension.out b/tests/test-extension.out --- a/tests/test-extension.out +++ b/tests/test-extension.out @@ -36,8 +36,7 @@ enabled extensions: global options: -R --repository repository root directory or symbolic path name --cwd change working directory - -y --noninteractive do not prompt, assume 'yes' for any required - answers + -y --noninteractive do not prompt, assume 'yes' for any required answers -q --quiet suppress output -v --verbose enable additional output --config set/override config option diff --git a/tests/test-record.out b/tests/test-record.out --- a/tests/test-record.out +++ b/tests/test-record.out @@ -27,10 +27,8 @@ interactively select changes to commit options: - -A --addremove mark new/missing files as added/removed before - committing - --close-branch mark a branch as closed, hiding it from the branch - list + -A --addremove mark new/missing files as added/removed before committing + --close-branch mark a branch as closed, hiding it from the branch list -I --include include names matching the given patterns -X --exclude exclude names matching the given patterns -m --message use as commit message