/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/ui/text.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 23:19:12 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7294.
  • Revision ID: jelmer@jelmer.uk-20181116231912-e043vpq22bdkxa6q
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
        """
68
68
        is_tty = self.ui.raw_stdin.isatty()
69
69
        if (os.environ.get('BRZ_TEXTUI_INPUT') != 'line-based' and
70
 
                self.ui.raw_stdin == getattr(sys.stdin, 'buffer', sys.stdin) and is_tty):
 
70
                self.ui.raw_stdin == _unwrap_stream(sys.stdin) and is_tty):
71
71
            self.line_based = False
72
72
            self.echo_back = True
73
73
        else:
123
123
 
124
124
    def _getchar(self):
125
125
        char = osutils.getchar()
126
 
        if char == chr(3): # INTR
 
126
        if char == chr(3):  # INTR
127
127
            raise KeyboardInterrupt
128
 
        if char == chr(4): # EOF (^d, C-d)
 
128
        if char == chr(4):  # EOF (^d, C-d)
129
129
            raise EOFError
130
130
        if isinstance(char, bytes):
131
131
            return char.decode('ascii', 'replace')
302
302
        if self.is_quiet():
303
303
            return NullProgressView()
304
304
        pb_type = config.GlobalStack().get('progress_bar')
305
 
        if pb_type == 'none': # Explicit requirement
 
305
        if pb_type == 'none':  # Explicit requirement
306
306
            return NullProgressView()
307
 
        if (pb_type == 'text' # Explicit requirement
308
 
            or progress._supports_progress(self.stderr)): # Guess
 
307
        if (pb_type == 'text' or # Explicit requirement
 
308
                progress._supports_progress(self.stderr)):  # Guess
309
309
            return TextProgressView(self.stderr)
310
310
        # No explicit requirement and no successful guess
311
311
        return NullProgressView()
341
341
        By default it does nothing.
342
342
        """
343
343
        self._progress_view.show_transport_activity(transport,
344
 
            direction, byte_count)
 
344
                                                    direction, byte_count)
345
345
 
346
346
    def log_transport_activity(self, display=False):
347
347
        """See UIFactory.log_transport_activity()"""
365
365
        """
366
366
        if not self._task_stack:
367
367
            warnings.warn("%r updated but no tasks are active" %
368
 
                (task,))
 
368
                          (task,))
369
369
        elif task != self._task_stack[-1]:
370
370
            # We used to check it was the top task, but it's hard to always
371
371
            # get this right and it's not necessarily useful: any actual
372
372
            # problems will be evident in use
373
 
            #warnings.warn("%r is not the top progress task %r" %
 
373
            # warnings.warn("%r is not the top progress task %r" %
374
374
            #     (task, self._task_stack[-1]))
375
375
            pass
376
376
        self._progress_view.show_progress(task)
462
462
    def _render_bar(self):
463
463
        # return a string for the progress bar itself
464
464
        if self.enable_bar and (
465
 
            (self._last_task is None) or self._last_task.show_bar):
 
465
                (self._last_task is None) or self._last_task.show_bar):
466
466
            # If there's no task object, we show space for the bar anyhow.
467
467
            # That's because most invocations of bzr will end showing progress
468
468
            # at some point, though perhaps only after doing some initial IO.
469
469
            # It looks better to draw the progress bar initially rather than
470
470
            # to have what looks like an incomplete progress bar.
471
 
            spin_str =  r'/-\|'[self._spin_pos % 4]
 
471
            spin_str = r'/-\|'[self._spin_pos % 4]
472
472
            self._spin_pos += 1
473
473
            cols = 20
474
474
            if self._last_task is None:
478
478
                completion_fraction = \
479
479
                    self._last_task._overall_completion_fraction() or 0
480
480
            if (completion_fraction < self._fraction and 'progress' in
481
 
                debug.debug_flags):
 
481
                    debug.debug_flags):
482
482
                debug.set_trace()
483
483
            self._fraction = completion_fraction
484
484
            markers = int(round(float(cols) * completion_fraction)) - 1
486
486
            return bar_str
487
487
        elif (self._last_task is None) or self._last_task.show_spinner:
488
488
            # The last task wanted just a spinner, no bar
489
 
            spin_str =  r'/-\|'[self._spin_pos % 4]
 
489
            spin_str = r'/-\|'[self._spin_pos % 4]
490
490
            self._spin_pos += 1
491
491
            return spin_str + ' '
492
492
        else:
534
534
        avail_width = self._avail_width()
535
535
        if avail_width is not None:
536
536
            # if terminal avail_width is unknown, don't truncate
537
 
            current_len = len(bar_string) + len(trans) + len(task_part) + len(counter_part)
 
537
            current_len = len(bar_string) + len(trans) + \
 
538
                len(task_part) + len(counter_part)
538
539
            # GZ 2017-04-22: Should measure and truncate task_part properly
539
540
            gap = current_len - avail_width
540
541
            if gap > 0:
541
 
                task_part = task_part[:-gap-2] + '..'
 
542
                task_part = task_part[:-gap - 2] + '..'
542
543
        s = trans + bar_string + task_part + counter_part
543
544
        if avail_width is not None:
544
545
            if len(s) < avail_width:
604
605
        elif now >= (self._transport_update_time + 0.5):
605
606
            # guard against clock stepping backwards, and don't update too
606
607
            # often
607
 
            rate = (self._bytes_since_update
608
 
                    / (now - self._transport_update_time))
 
608
            rate = (self._bytes_since_update /
 
609
                    (now - self._transport_update_time))
609
610
            # using base-10 units (see HACKING.txt).
610
611
            msg = ("%6dkB %5dkB/s " %
611
 
                    (self._total_byte_count / 1000, int(rate) / 1000,))
 
612
                   (self._total_byte_count / 1000, int(rate) / 1000,))
612
613
            self._transport_update_time = now
613
614
            self._last_repaint = now
614
615
            self._bytes_since_update = 0
631
632
                  bps / 1000.,
632
633
                  self._bytes_by_direction['read'] / 1000.,
633
634
                  self._bytes_by_direction['write'] / 1000.,
634
 
                 ))
 
635
                  ))
635
636
        if self._bytes_by_direction['unknown'] > 0:
636
637
            msg += ' u:%.0fkB)' % (
637
638
                self._bytes_by_direction['unknown'] / 1000.