chiark / gitweb /
Wrap the text of error messages
authorKarl Hasselström <kha@treskal.com>
Tue, 3 Jun 2008 00:44:18 +0000 (02:44 +0200)
committerKarl Hasselström <kha@treskal.com>
Tue, 3 Jun 2008 00:44:18 +0000 (02:44 +0200)
... 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 <kha@treskal.com>
stgit/commands/common.py
stgit/out.py

index d6df813542b4486f06653cbdf3ca0906218420fe..100b5e1d4f70a92d6b7a3fc4e48d44270a7dfbef 100644 (file)
@@ -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:
index d3c86b4cff9012c51a68f47547c933d9b0499593..485b830658954ec29c48b19f8047a029b4e28172 100644 (file)
@@ -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)