/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

Merge test-run support.

Show diffs side-by-side

added added

removed removed

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