/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:15:15 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181116231515-zqd2yn6kj8lfydyp
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 == 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()
332
332
        self.clear_term()
333
333
        self.stdout.flush()
334
334
        self.stderr.write(prompt)
 
335
        self.stderr.flush()
335
336
 
336
337
    def report_transport_activity(self, transport, byte_count, direction):
337
338
        """Called by transports as they do IO.
340
341
        By default it does nothing.
341
342
        """
342
343
        self._progress_view.show_transport_activity(transport,
343
 
            direction, byte_count)
 
344
                                                    direction, byte_count)
344
345
 
345
346
    def log_transport_activity(self, display=False):
346
347
        """See UIFactory.log_transport_activity()"""
364
365
        """
365
366
        if not self._task_stack:
366
367
            warnings.warn("%r updated but no tasks are active" %
367
 
                (task,))
 
368
                          (task,))
368
369
        elif task != self._task_stack[-1]:
369
370
            # We used to check it was the top task, but it's hard to always
370
371
            # get this right and it's not necessarily useful: any actual
371
372
            # problems will be evident in use
372
 
            #warnings.warn("%r is not the top progress task %r" %
 
373
            # warnings.warn("%r is not the top progress task %r" %
373
374
            #     (task, self._task_stack[-1]))
374
375
            pass
375
376
        self._progress_view.show_progress(task)
461
462
    def _render_bar(self):
462
463
        # return a string for the progress bar itself
463
464
        if self.enable_bar and (
464
 
            (self._last_task is None) or self._last_task.show_bar):
 
465
                (self._last_task is None) or self._last_task.show_bar):
465
466
            # If there's no task object, we show space for the bar anyhow.
466
467
            # That's because most invocations of bzr will end showing progress
467
468
            # at some point, though perhaps only after doing some initial IO.
468
469
            # It looks better to draw the progress bar initially rather than
469
470
            # to have what looks like an incomplete progress bar.
470
 
            spin_str =  r'/-\|'[self._spin_pos % 4]
 
471
            spin_str = r'/-\|'[self._spin_pos % 4]
471
472
            self._spin_pos += 1
472
473
            cols = 20
473
474
            if self._last_task is None:
477
478
                completion_fraction = \
478
479
                    self._last_task._overall_completion_fraction() or 0
479
480
            if (completion_fraction < self._fraction and 'progress' in
480
 
                debug.debug_flags):
 
481
                    debug.debug_flags):
481
482
                debug.set_trace()
482
483
            self._fraction = completion_fraction
483
484
            markers = int(round(float(cols) * completion_fraction)) - 1
485
486
            return bar_str
486
487
        elif (self._last_task is None) or self._last_task.show_spinner:
487
488
            # The last task wanted just a spinner, no bar
488
 
            spin_str =  r'/-\|'[self._spin_pos % 4]
 
489
            spin_str = r'/-\|'[self._spin_pos % 4]
489
490
            self._spin_pos += 1
490
491
            return spin_str + ' '
491
492
        else:
533
534
        avail_width = self._avail_width()
534
535
        if avail_width is not None:
535
536
            # if terminal avail_width is unknown, don't truncate
536
 
            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)
537
539
            # GZ 2017-04-22: Should measure and truncate task_part properly
538
540
            gap = current_len - avail_width
539
541
            if gap > 0:
540
 
                task_part = task_part[:-gap-2] + '..'
 
542
                task_part = task_part[:-gap - 2] + '..'
541
543
        s = trans + bar_string + task_part + counter_part
542
544
        if avail_width is not None:
543
545
            if len(s) < avail_width:
603
605
        elif now >= (self._transport_update_time + 0.5):
604
606
            # guard against clock stepping backwards, and don't update too
605
607
            # often
606
 
            rate = (self._bytes_since_update
607
 
                    / (now - self._transport_update_time))
 
608
            rate = (self._bytes_since_update /
 
609
                    (now - self._transport_update_time))
608
610
            # using base-10 units (see HACKING.txt).
609
611
            msg = ("%6dkB %5dkB/s " %
610
 
                    (self._total_byte_count / 1000, int(rate) / 1000,))
 
612
                   (self._total_byte_count / 1000, int(rate) / 1000,))
611
613
            self._transport_update_time = now
612
614
            self._last_repaint = now
613
615
            self._bytes_since_update = 0
630
632
                  bps / 1000.,
631
633
                  self._bytes_by_direction['read'] / 1000.,
632
634
                  self._bytes_by_direction['write'] / 1000.,
633
 
                 ))
 
635
                  ))
634
636
        if self._bytes_by_direction['unknown'] > 0:
635
637
            msg += ' u:%.0fkB)' % (
636
638
                self._bytes_by_direction['unknown'] / 1000.