~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-03 13:53:46 UTC
  • mto: This revision was merged to the branch mainline in revision 5826.
  • Revision ID: jelmer@samba.org-20110503135346-l2f6xnenzn3320gv
Kill annotate_file_revision_tree() in favor annotate_file_tree().

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
"""Text UI, write output to the console.
19
19
"""
20
20
 
21
 
import codecs
22
 
import getpass
23
21
import os
24
22
import sys
25
23
import time
26
 
import warnings
27
24
 
28
25
from bzrlib.lazy_import import lazy_import
29
26
lazy_import(globals(), """
 
27
import codecs
 
28
import getpass
 
29
import warnings
 
30
 
30
31
from bzrlib import (
31
32
    debug,
32
33
    progress,
33
34
    osutils,
34
 
    symbol_versioning,
35
35
    trace,
36
36
    )
37
37
 
38
38
""")
39
39
 
40
 
from bzrlib.osutils import watch_sigwinch
41
 
 
42
40
from bzrlib.ui import (
43
41
    UIFactory,
44
42
    NullProgressView,
62
60
        self.stderr = stderr
63
61
        # paints progress, network activity, etc
64
62
        self._progress_view = self.make_progress_view()
65
 
        # hook up the signals to watch for terminal size changes
66
 
        watch_sigwinch()
67
63
 
68
64
    def be_quiet(self, state):
69
65
        if state and not self._quiet:
157
153
        """Construct and return a new ProgressView subclass for this UI.
158
154
        """
159
155
        # with --quiet, never any progress view
160
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/320035>.  Otherwise if the
 
156
        # <https://bugs.launchpad.net/bzr/+bug/320035>.  Otherwise if the
161
157
        # user specifically requests either text or no progress bars, always
162
158
        # do that.  otherwise, guess based on $TERM and tty presence.
163
159
        if self.is_quiet():
304
300
        # correspond reliably to overall command progress
305
301
        self.enable_bar = False
306
302
 
 
303
    def _avail_width(self):
 
304
        # we need one extra space for terminals that wrap on last char
 
305
        w = osutils.terminal_width() 
 
306
        if w is None:
 
307
            return None
 
308
        else:
 
309
            return w - 1
 
310
 
307
311
    def _show_line(self, s):
308
312
        # sys.stderr.write("progress %r\n" % s)
309
 
        width = osutils.terminal_width()
 
313
        width = self._avail_width()
310
314
        if width is not None:
311
 
            # we need one extra space for terminals that wrap on last char
312
 
            width = width - 1
313
315
            s = '%-*.*s' % (width, width, s)
314
316
        self._term_file.write('\r' + s + '\r')
315
317
 
352
354
            return ''
353
355
 
354
356
    def _format_task(self, task):
 
357
        """Format task-specific parts of progress bar.
 
358
 
 
359
        :returns: (text_part, counter_part) both unicode strings.
 
360
        """
355
361
        if not task.show_count:
356
362
            s = ''
357
363
        elif task.current_cnt is not None and task.total_cnt is not None:
367
373
            t = t._parent_task
368
374
            if t.msg:
369
375
                m = t.msg + ':' + m
370
 
        return m + s
 
376
        return m, s
371
377
 
372
378
    def _render_line(self):
373
379
        bar_string = self._render_bar()
374
380
        if self._last_task:
375
 
            task_msg = self._format_task(self._last_task)
 
381
            task_part, counter_part = self._format_task(self._last_task)
376
382
        else:
377
 
            task_msg = ''
 
383
            task_part = counter_part = ''
378
384
        if self._last_task and not self._last_task.show_transport_activity:
379
385
            trans = ''
380
386
        else:
381
387
            trans = self._last_transport_msg
382
 
            if trans:
383
 
                trans += ' | '
384
 
        return (bar_string + trans + task_msg)
 
388
        # the bar separates the transport activity from the message, so even
 
389
        # if there's no bar or spinner, we must show something if both those
 
390
        # fields are present
 
391
        if (task_part or trans) and not bar_string:
 
392
            bar_string = '| '
 
393
        # preferentially truncate the task message if we don't have enough
 
394
        # space
 
395
        avail_width = self._avail_width()
 
396
        if avail_width is not None:
 
397
            # if terminal avail_width is unknown, don't truncate
 
398
            current_len = len(bar_string) + len(trans) + len(task_part) + len(counter_part)
 
399
            gap = current_len - avail_width
 
400
            if gap > 0:
 
401
                task_part = task_part[:-gap-2] + '..'
 
402
        s = trans + bar_string + task_part + counter_part
 
403
        if avail_width is not None:
 
404
            if len(s) < avail_width:
 
405
                s = s.ljust(avail_width)
 
406
            elif len(s) > avail_width:
 
407
                s = s[:avail_width]
 
408
        return s
385
409
 
386
410
    def _repaint(self):
387
411
        s = self._render_line()
443
467
            rate = (self._bytes_since_update
444
468
                    / (now - self._transport_update_time))
445
469
            # using base-10 units (see HACKING.txt).
446
 
            msg = ("%6dkB %5dkB/s" %
 
470
            msg = ("%6dkB %5dkB/s " %
447
471
                    (self._total_byte_count / 1000, int(rate) / 1000,))
448
472
            self._transport_update_time = now
449
473
            self._last_repaint = now