~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Martin Pool
  • Date: 2008-12-15 08:28:57 UTC
  • mto: (3882.7.11 progress)
  • mto: This revision was merged to the branch mainline in revision 3940.
  • Revision ID: mbp@sourcefrog.net-20081215082857-asjzld70e2s1i0ta
Change progress bars to a more MVC style

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        self._total_byte_count = 0
63
63
        self._bytes_since_update = 0
64
64
        self._last_activity_time = None
65
 
        # there must always be a top-level progress bar, even if it's not
66
 
        # always shown.
67
 
        self.nested_progress_bar()
 
65
        # paints progress, network activity, etc
 
66
        self._progress_view = progress.TextProgressView(self.stderr)
68
67
 
69
68
    def prompt(self, prompt):
70
69
        """Emit prompt on the CLI."""
71
70
        self.stdout.write(prompt)
72
71
        
73
 
    def nested_progress_bar(self):
74
 
        """Return a nested progress bar.
75
 
        
76
 
        The actual bar type returned depends on the progress module which
77
 
        may return a tty or dots bar depending on the terminal.
78
 
        """
79
 
        if self._progress_bar_stack is None:
80
 
            self._progress_bar_stack = progress.ProgressBarStack(
81
 
                klass=self._bar_type)
82
 
        return self._progress_bar_stack.get_nested()
83
 
 
84
72
    def clear_term(self):
85
73
        """Prepare the terminal for output.
86
74
 
90
78
        # directed into a file rather than to the terminal, and the progress
91
79
        # bar _is_ going to the terminal, we shouldn't need
92
80
        # to clear it.  We might need to separately check for the case of 
93
 
        if self._progress_bar_stack is None:
94
 
            return
95
 
        overall_pb = self._progress_bar_stack.bottom()
96
 
        if overall_pb is not None:
97
 
            overall_pb.clear()
 
81
        self._progress_view.clear()
98
82
 
99
83
    def report_transport_activity(self, transport, byte_count, direction):
100
84
        """Called by transports as they do IO.
102
86
        This may update a progress bar, spinner, or similar display.
103
87
        By default it does nothing.
104
88
        """
105
 
        # XXX: this is separate from the count-based progress bar, but should
106
 
        # be integrated with it...
 
89
        # XXX: Probably there should be a transport activity model, and that
 
90
        # too should be seen by the progress view, rather than being poked in
 
91
        # here.
107
92
        self._total_byte_count += byte_count
108
93
        self._bytes_since_update += byte_count
109
94
        now = time.time()
117
102
                (self._total_byte_count>>10, int(rate)>>10,))
118
103
            self._last_activity_time = now
119
104
            self._bytes_since_update = 0
120
 
            overall_pb = self._progress_bar_stack.bottom()
121
 
            overall_pb.update(msg=None, transport_msg=msg)
 
105
            self._progress_view.show_transport_activity(msg)
 
106
 
 
107
    def show_progress(self, task):
 
108
        """A task has been updated and wants to be displayed.
 
109
        """
 
110
        self._progress_view.show_progress(task)
 
111
 
 
112
    def progress_finished(self, task):
 
113
        CLIUIFactory.progress_finished(self, task)
 
114
        if not self._task_stack:
 
115
            # finished top-level task
 
116
            self._progress_view.clear()