~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Martin Pool
  • Date: 2005-07-17 18:38:22 UTC
  • Revision ID: mbp@sourcefrog.net-20050717183820-e347e5897ccd375b
- progress bar: avoid repeatedly checking screen width

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
        self.show_bar = show_bar
116
116
        self.show_count = show_count
117
117
 
 
118
        self.width = _width()
 
119
        
118
120
 
119
121
    def tick(self):
120
122
        self.update(self.last_msg, self.last_cnt, self.last_total)
141
143
 
142
144
        self.last_update = now
143
145
        
144
 
        width = _width()
145
 
 
146
146
        if total_cnt:
147
147
            assert current_cnt <= total_cnt
148
148
        if current_cnt:
182
182
 
183
183
        if self.show_bar:
184
184
            # progress bar, if present, soaks up all remaining space
185
 
            cols = width - 1 - len(msg) - len(spin_str) - len(pct_str) \
 
185
            cols = self.width - 1 - len(msg) - len(spin_str) - len(pct_str) \
186
186
                   - len(eta_str) - len(count_str) - 3
187
187
 
188
188
            if total_cnt:
203
203
 
204
204
        m = spin_str + bar_str + msg + count_str + pct_str + eta_str
205
205
 
206
 
        assert len(m) < width
207
 
        self.to_file.write('\r' + m.ljust(width - 1))
 
206
        assert len(m) < self.width
 
207
        self.to_file.write('\r' + m.ljust(self.width - 1))
208
208
        #self.to_file.flush()
209
209
            
210
210
 
212
212
        if self.suppressed:
213
213
            return
214
214
        
215
 
        self.to_file.write('\r%s\r' % (' ' * (_width() - 1)))
 
215
        self.to_file.write('\r%s\r' % (' ' * (self.width - 1)))
216
216
        #self.to_file.flush()        
217
217
    
218
218