~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Martin
  • Date: 2010-06-22 00:32:37 UTC
  • mto: This revision was merged to the branch mainline in revision 5315.
  • Revision ID: gzlist@googlemail.com-20100622003237-zntnpyx8hjb5jnpw
Change interface of _command_line_to_argv so old tests can still be used with new stripping logic

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
21
23
import os
22
24
import sys
23
25
import time
 
26
import warnings
24
27
 
25
28
from bzrlib.lazy_import import lazy_import
26
29
lazy_import(globals(), """
27
 
import codecs
28
 
import getpass
29
 
import warnings
30
 
 
31
30
from bzrlib import (
32
31
    debug,
33
32
    progress,
34
33
    osutils,
 
34
    symbol_versioning,
35
35
    trace,
36
36
    )
37
37
 
300
300
        # correspond reliably to overall command progress
301
301
        self.enable_bar = False
302
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
 
 
311
303
    def _show_line(self, s):
312
304
        # sys.stderr.write("progress %r\n" % s)
313
 
        width = self._avail_width()
 
305
        width = osutils.terminal_width()
314
306
        if width is not None:
 
307
            # we need one extra space for terminals that wrap on last char
 
308
            width = width - 1
315
309
            s = '%-*.*s' % (width, width, s)
316
310
        self._term_file.write('\r' + s + '\r')
317
311
 
354
348
            return ''
355
349
 
356
350
    def _format_task(self, task):
357
 
        """Format task-specific parts of progress bar.
358
 
 
359
 
        :returns: (text_part, counter_part) both unicode strings.
360
 
        """
361
351
        if not task.show_count:
362
352
            s = ''
363
353
        elif task.current_cnt is not None and task.total_cnt is not None:
373
363
            t = t._parent_task
374
364
            if t.msg:
375
365
                m = t.msg + ':' + m
376
 
        return m, s
 
366
        return m + s
377
367
 
378
368
    def _render_line(self):
379
369
        bar_string = self._render_bar()
380
370
        if self._last_task:
381
 
            task_part, counter_part = self._format_task(self._last_task)
 
371
            task_msg = self._format_task(self._last_task)
382
372
        else:
383
 
            task_part = counter_part = ''
 
373
            task_msg = ''
384
374
        if self._last_task and not self._last_task.show_transport_activity:
385
375
            trans = ''
386
376
        else:
387
377
            trans = self._last_transport_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
 
378
            if trans:
 
379
                trans += ' | '
 
380
        return (bar_string + trans + task_msg)
409
381
 
410
382
    def _repaint(self):
411
383
        s = self._render_line()
467
439
            rate = (self._bytes_since_update
468
440
                    / (now - self._transport_update_time))
469
441
            # using base-10 units (see HACKING.txt).
470
 
            msg = ("%6dkB %5dkB/s " %
 
442
            msg = ("%6dkB %5dkB/s" %
471
443
                    (self._total_byte_count / 1000, int(rate) / 1000,))
472
444
            self._transport_update_time = now
473
445
            self._last_repaint = now