changeset 17909:3326fd05eb1f

formatter: add condwrite method This makes handling conditional output tidier
author Matt Mackall <mpm@selenic.com>
date Sat, 03 Nov 2012 14:37:50 -0500
parents 42f8ee0e04ac
children c8709ff57ff2
files mercurial/formatter.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/formatter.py	Wed Oct 24 23:09:31 2012 +0200
+++ b/mercurial/formatter.py	Sat Nov 03 14:37:50 2012 -0500
@@ -31,6 +31,10 @@
         '''do default text output while assigning data to item'''
         for k, v in zip(fields.split(), fielddata):
             self._item[k] = v
+    def condwrite(self, cond, fields, deftext, *fielddata, **opts):
+        '''do conditional write (primarily for plain formatter)'''
+        for k, v in zip(fields.split(), fielddata):
+            self._item[k] = v
     def plain(self, text, **opts):
         '''show raw text for non-templated mode'''
         pass
@@ -51,6 +55,10 @@
         pass
     def write(self, fields, deftext, *fielddata, **opts):
         self._ui.write(deftext % fielddata, **opts)
+    def condwrite(self, cond, fields, deftext, *fielddata, **opts):
+        '''do conditional write'''
+        if cond:
+            self._ui.write(deftext % fielddata, **opts)
     def plain(self, text, **opts):
         self._ui.write(text, **opts)
     def end(self):