[PATCH 1 of 7] minirst: generate tables as a list of lines

Olav Reinert seroton10 at gmail.com
Sat May 26 10:43:46 CDT 2012


# HG changeset patch
# User Olav Reinert <seroton10 at gmail.com>
# Date 1337799357 -7200
# Node ID 5699ef4b5bd06e8685dd598e01ed46bee56e8ddc
# Parent  869328a917f726dafc396c9824160dcf85b50bf7
minirst: generate tables as a list of lines

diff -r 869328a917f7 -r 5699ef4b5bd0 mercurial/commands.py
--- a/mercurial/commands.py	Wed May 23 20:55:41 2012 +0200
+++ b/mercurial/commands.py	Wed May 23 20:55:57 2012 +0200
@@ -3324,7 +3324,8 @@
                          ('extensioncommands', _('Extension Commands'))):
             if matches[t]:
                 ui.write('%s:\n\n' % title)
-                ui.write(minirst.format(minirst.maketable(matches[t], 1)))
+                rst = '\n'.join(minirst.maketable(matches[t], 1))
+                ui.write(minirst.format(rst))
         return
 
     if name and name != 'shortlist':
diff -r 869328a917f7 -r 5699ef4b5bd0 mercurial/help.py
--- a/mercurial/help.py	Wed May 23 20:55:41 2012 +0200
+++ b/mercurial/help.py	Wed May 23 20:55:57 2012 +0200
@@ -58,9 +58,9 @@
     rst = minirst.maketable(data, 1)
 
     if multioccur:
-        rst += _("\n[+] marked option can be specified multiple times\n")
+        rst.append(_("\n[+] marked option can be specified multiple times\n"))
 
-    return rst
+    return '\n'.join(rst)
 
 # list all option lists
 def opttext(optlist, width, verbose):
diff -r 869328a917f7 -r 5699ef4b5bd0 mercurial/minirst.py
--- a/mercurial/minirst.py	Wed May 23 20:55:41 2012 +0200
+++ b/mercurial/minirst.py	Wed May 23 20:55:57 2012 +0200
@@ -658,11 +658,11 @@
     return lines
 
 def maketable(data, indent=0, header=False):
-    '''Generate an RST table for the given table data'''
+    '''Generate an RST table for the given table data as a list of lines'''
 
     widths = [max(encoding.colwidth(e) for e in c) for c in zip(*data)]
     indent = ' ' * indent
-    div = indent + ' '.join('=' * w for w in widths) + '\n'
+    div = indent + ' '.join('=' * w for w in widths)
 
     out = [div]
     for row in data:
@@ -670,8 +670,8 @@
         for w, v in zip(widths, row):
             pad = ' ' * (w - encoding.colwidth(v))
             l.append(v + pad)
-        out.append(indent + ' '.join(l) + "\n")
+        out.append(indent + ' '.join(l))
     if header and len(data) > 1:
         out.insert(2, div)
     out.append(div)
-    return ''.join(out)
+    return out
diff -r 869328a917f7 -r 5699ef4b5bd0 tests/test-minirst.py
--- a/tests/test-minirst.py	Wed May 23 20:55:41 2012 +0200
+++ b/tests/test-minirst.py	Wed May 23 20:55:57 2012 +0200
@@ -237,7 +237,8 @@
          ['1', '2', '3'],
          ['foo', 'bar', 'baz this list is very very very long man']]
 
-table = minirst.maketable(data, 2, True)
+rst = minirst.maketable(data, 2, True)
+table = '\n'.join(rst)
 
 print table
 
diff -r 869328a917f7 -r 5699ef4b5bd0 tests/test-minirst.py.out
--- a/tests/test-minirst.py.out	Wed May 23 20:55:41 2012 +0200
+++ b/tests/test-minirst.py.out	Wed May 23 20:55:57 2012 +0200
@@ -735,7 +735,6 @@
   1   2   3                                       
   foo bar baz this list is very very very long man
   === === ========================================
-
 == table ==
 60 column format:
 ----------------------------------------------------------------------


More information about the Mercurial-devel mailing list