From: Karl Hasselström Date: Tue, 3 Jun 2008 00:44:18 +0000 (+0200) Subject: Wrap the text of error messages X-Git-Tag: v0.15-rc1~217^2~1 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/a4b511ffeaba7e283d079d67d76e15463a54062e?ds=inline Wrap the text of error messages ... so that they fit nicely in an 80-column terminal. This makes it unnecessary to embed newlines and extra spaces in a few places. This patch only wraps the text of tagged output messages. I haven't found a reason to wrap other messages, but I haven't looked long and hard. Signed-off-by: Karl Hasselström --- diff --git a/stgit/commands/common.py b/stgit/commands/common.py index d6df813..100b5e1 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -118,21 +118,19 @@ def git_id(crt_series, rev): def check_local_changes(): if git.local_changes(): - raise CmdException, \ - 'local changes in the tree. Use "refresh" or "status --reset"' + raise CmdException('local changes in the tree. Use "refresh" or' + ' "status --reset"') def check_head_top_equal(crt_series): if not crt_series.head_top_equal(): - raise CmdException( -"""HEAD and top are not the same. This can happen if you - modify a branch with git. "stg repair --help" explains - more about what to do next.""") + raise CmdException('HEAD and top are not the same. This can happen' + ' if you modify a branch with git. "stg repair' + ' --help" explains more about what to do next.') def check_conflicts(): if git.get_conflicts(): - raise CmdException, \ - 'Unsolved conflicts. Please resolve them first or\n' \ - ' revert the changes with "status --reset"' + raise CmdException('Unsolved conflicts. Please resolve them first' + ' or revert the changes with "status --reset"') def print_crt_patch(crt_series, branch = None): if not branch: diff --git a/stgit/out.py b/stgit/out.py index d3c86b4..485b830 100644 --- a/stgit/out.py +++ b/stgit/out.py @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -import sys +import sys, textwrap class MessagePrinter(object): def __init__(self): @@ -49,6 +49,10 @@ class MessagePrinter(object): self.at_start_of_line = False def tagged_lines(self, tag, lines): tag += ': ' + width = 79 - 2*self.level - len(tag) + lines = [wl for line in lines + for wl in textwrap.wrap(line, width, + break_long_words = False)] for line in lines: self.single_line(tag + line) tag = ' '*len(tag)