~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-17 10:04:37 UTC
  • mfrom: (4449.2.6 339385-set-progress-bar)
  • Revision ID: pqm@pqm.ubuntu.com-20090617100437-gavn9zkum4dj5yjz
(mbp) resurrect BZR_PROGRESS_BAR

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""Text UI, write output to the console.
20
20
"""
21
21
 
 
22
import os
22
23
import sys
23
24
import time
24
25
import warnings
56
57
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 11, 0))
57
58
                % "bar_type parameter")
58
59
        # paints progress, network activity, etc
59
 
        self._progress_view = TextProgressView(self.stderr)
60
 
 
 
60
        self._progress_view = self._make_progress_view()
 
61
        
61
62
    def clear_term(self):
62
63
        """Prepare the terminal for output.
63
64
 
69
70
        # to clear it.  We might need to separately check for the case of
70
71
        self._progress_view.clear()
71
72
 
 
73
    def _make_progress_view(self):
 
74
        if os.environ.get('BZR_PROGRESS_BAR') in ('text', None, ''):
 
75
            return TextProgressView(self.stderr)
 
76
        else:
 
77
            return NullProgressView()
 
78
 
72
79
    def note(self, msg):
73
80
        """Write an already-formatted message, clearing the progress bar if necessary."""
74
81
        self.clear_term()
80
87
        This may update a progress bar, spinner, or similar display.
81
88
        By default it does nothing.
82
89
        """
83
 
        self._progress_view._show_transport_activity(transport,
 
90
        self._progress_view.show_transport_activity(transport,
84
91
            direction, byte_count)
85
92
 
86
93
    def _progress_updated(self, task):
98
105
        self._progress_view.clear()
99
106
 
100
107
 
 
108
class NullProgressView(object):
 
109
    """Soak up and ignore progress information."""
 
110
 
 
111
    def clear(self):
 
112
        pass
 
113
 
 
114
    def show_progress(self, task):
 
115
        pass
 
116
 
 
117
    def show_transport_activity(self, transport, direction, byte_count):
 
118
        pass
 
119
    
 
120
 
101
121
class TextProgressView(object):
102
122
    """Display of progress bar and other information on a tty.
103
123
 
216
236
        self._last_repaint = now
217
237
        self._repaint()
218
238
 
219
 
    def _show_transport_activity(self, transport, direction, byte_count):
 
239
    def show_transport_activity(self, transport, direction, byte_count):
220
240
        """Called by transports via the ui_factory, as they do IO.
221
241
 
222
242
        This may update a progress bar, spinner, or similar display.