add a simple nested buffering scheme to ui
authorMatt Mackall <mpm@selenic.com>
Fri, 01 Dec 2006 01:28:18 -0600
changeset 3737 9f5c46c50118
parent 3736 ad3d5b4367cb
child 3738 cb48cd27d3f4
add a simple nested buffering scheme to ui
mercurial/ui.py
--- a/mercurial/ui.py	Thu Nov 30 22:38:48 2006 -0600
+++ b/mercurial/ui.py	Fri Dec 01 01:28:18 2006 -0600
@@ -29,6 +29,7 @@
                  interactive=True, traceback=False, report_untrusted=True,
                  parentui=None):
         self.overlay = None
+        self.buffers = []
         if parentui is None:
             # this is the parent of all ui children
             self.parentui = None
@@ -367,9 +368,18 @@
             path = self.config("paths", default)
         return path or loc
 
+    def pushbuffer(self):
+        self.buffers.append([])
+
+    def popbuffer(self):
+        return "".join(self.buffers.pop())
+
     def write(self, *args):
-        for a in args:
-            sys.stdout.write(str(a))
+        if self.buffers:
+            self.buffers[-1].extend([str(a) for a in args])
+        else:
+            for a in args:
+                sys.stdout.write(str(a))
 
     def write_err(self, *args):
         try: