util, minirst: do not crash with COLUMNS=0
authorMartin Geisler <mg@lazybytes.net>
Thu, 03 Sep 2009 21:07:06 +0200
changeset 9417 4c3fb45123e5
parent 9416 eecbaac5ca88
child 9418 a82db54bc3be
util, minirst: do not crash with COLUMNS=0
mercurial/minirst.py
mercurial/util.py
--- a/mercurial/minirst.py	Thu Sep 03 02:42:56 2009 +0200
+++ b/mercurial/minirst.py	Thu Sep 03 21:07:06 2009 +0200
@@ -279,6 +279,8 @@
 
 def formatblock(block, width):
     """Format a block according to width."""
+    if width <= 0:
+        width = 78
     indent = ' ' * block['indent']
     if block['type'] == 'margin':
         return ''
--- a/mercurial/util.py	Thu Sep 03 02:42:56 2009 +0200
+++ b/mercurial/util.py	Thu Sep 03 21:07:06 2009 +0200
@@ -1274,6 +1274,9 @@
 def wrap(line, hangindent, width=None):
     if width is None:
         width = termwidth() - 2
+    if width <= hangindent:
+        # adjust for weird terminal size
+        width = max(78, hangindent + 1)
     padding = '\n' + ' ' * hangindent
     return padding.join(textwrap.wrap(line, width=width - hangindent))