Rev 3021: Add a stub bzrlilb.progress.TTYTaskDisplay. in http://people.ubuntu.com/~robertc/baz2.0/nested-pb

Robert Collins robertc at robertcollins.net
Tue Nov 20 02:04:16 GMT 2007


At http://people.ubuntu.com/~robertc/baz2.0/nested-pb

------------------------------------------------------------
revno: 3021
revision-id:robertc at robertcollins.net-20071120020408-dukr6u0l9xiwnob9
parent: robertc at robertcollins.net-20071120015047-ynshd1ecwt7acrou
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pb.simplify
timestamp: Tue 2007-11-20 13:04:08 +1100
message:
  Add a stub bzrlilb.progress.TTYTaskDisplay.
modified:
  bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
  bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
=== modified file 'bzrlib/progress.py'
--- a/bzrlib/progress.py	2007-11-20 01:50:47 +0000
+++ b/bzrlib/progress.py	2007-11-20 02:04:08 +0000
@@ -336,19 +336,17 @@
         raise NotImplementedError(self.task_changed)
 
 
-class DotsTaskDisplay(TaskDisplay):
-    """Display the task on a file stream using dots to mark activity."""
+class StreamTaskDisplay(TaskDisplay):
+    """Display the task on a file stream.
+    
+    This is a base class for common logic to the dots and tty versions.
+    """
 
     def __init__(self, task, stream):
         TaskDisplay.__init__(self, task)
         self._stream = stream
         self._init_state()
 
-    def clear(self):
-        if self._last_message is not None:
-            self._stream.write('\n')
-            self._init_state()
-
     def _init_state(self):
         """Clear the internal state used for controlling output."""
         self._last_message = None
@@ -358,6 +356,15 @@
         self.clear()
         self._stream.write((fmt + '\n') % args)
 
+
+class DotsTaskDisplay(StreamTaskDisplay):
+    """Display the task on a file stream using dots to mark activity."""
+
+    def clear(self):
+        if self._last_message is not None:
+            self._stream.write('\n')
+            self._init_state()
+
     def task_changed(self):
         # When the task changes, a dots display should output each message it
         # sees once, then dots until a new message is shown. Messages are shown
@@ -385,6 +392,16 @@
         pass
 
 
+class TTYTaskDisplay(StreamTaskDisplay):
+    """Display the task on a TTY file, using \r's to update a single line."""
+
+    def clear(self):
+        pass
+
+    def task_changed(self):
+        pass
+
+
 display_types['none'] = SilentTaskDisplay
 display_types['dummy'] = SilentTaskDisplay
 display_types['silent'] = SilentTaskDisplay

=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py	2007-11-20 01:50:47 +0000
+++ b/bzrlib/tests/test_progress.py	2007-11-20 02:04:08 +0000
@@ -30,6 +30,7 @@
         ProgressBarStack,
         SilentTaskDisplay,
         TTYProgressBar,
+        TTYTaskDisplay,
         )
 from bzrlib.tests import TestCase
 
@@ -521,6 +522,21 @@
         self.assertEqual('message:.', output.getvalue())
 
 
+class TestTTYTaskDisplay(TestCase):
+
+    def test_construct(self):
+        task = KnownLengthTask('message', 1)
+        output = StringIO()
+        display = TTYTaskDisplay(task, output)
+
+    def get_display(self):
+        """Get a task, output and display to test with."""
+        task = KnownLengthTask('message', 1)
+        output = StringIO()
+        display = TTYTaskDisplay(task, output)
+        return task, output, display
+
+
 class TestDisplayTypeSelection(TestCase):
 
     def test_via_environment(self):



More information about the bazaar-commits mailing list