~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-20 03:50:35 UTC
  • mfrom: (1740.5.9 bzr.mbp.traceback)
  • Revision ID: pqm@pqm.ubuntu.com-20060620035035-a9a7dc096fed5060
(mbp) show traceback on stderr on unexpected errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import sys
24
24
 
25
25
import bzrlib.progress
26
 
from bzrlib.ui import UIFactory
27
 
 
28
 
 
29
 
class TextUIFactory(UIFactory):
 
26
from bzrlib.symbol_versioning import *
 
27
from bzrlib.ui import CLIUIFactory
 
28
 
 
29
 
 
30
class TextUIFactory(CLIUIFactory):
 
31
    """A UI factory for Text user interefaces."""
 
32
 
 
33
    def __init__(self,
 
34
                 bar_type=None,
 
35
                 stdout=None,
 
36
                 stderr=None):
 
37
        """Create a TextUIFactory.
 
38
 
 
39
        :param bar_type: The type of progress bar to create. It defaults to 
 
40
                         letting the bzrlib.progress.ProgressBar factory auto
 
41
                         select.
 
42
        """
 
43
        super(TextUIFactory, self).__init__()
 
44
        self._bar_type = bar_type
 
45
        if stdout is None:
 
46
            self.stdout = sys.stdout
 
47
        else:
 
48
            self.stdout = stdout
 
49
        if stderr is None:
 
50
            self.stderr = sys.stderr
 
51
        else:
 
52
            self.stderr = stderr
 
53
 
 
54
    def prompt(self, prompt):
 
55
        """Emit prompt on the CLI."""
 
56
        self.stdout.write(prompt + "? [y/n]:")
 
57
        
 
58
    @deprecated_method(zero_eight)
30
59
    def progress_bar(self):
31
 
 
 
60
        """See UIFactory.nested_progress_bar()."""
32
61
        # this in turn is abstract, and creates either a tty or dots
33
62
        # bar depending on what we think of the terminal
34
63
        return bzrlib.progress.ProgressBar()
50
79
        except KeyboardInterrupt:
51
80
            return None
52
81
 
 
82
    def nested_progress_bar(self):
 
83
        """Return a nested progress bar.
 
84
        
 
85
        The actual bar type returned depends on the progress module which
 
86
        may return a tty or dots bar depending on the terminal.
 
87
        """
 
88
        if self._progress_bar_stack is None:
 
89
            self._progress_bar_stack = bzrlib.progress.ProgressBarStack(
 
90
                klass=self._bar_type)
 
91
        return self._progress_bar_stack.get_nested()
 
92
 
 
93
    def clear_term(self):
 
94
        """Prepare the terminal for output.
 
95
 
 
96
        This will, clear any progress bars, and leave the cursor at the
 
97
        leftmost position."""
 
98
        if self._progress_bar_stack is None:
 
99
            return
 
100
        overall_pb = self._progress_bar_stack.bottom()
 
101
        if overall_pb is not None:
 
102
            overall_pb.clear()