28
28
displays no output.
33
35
import bzrlib.progress
34
from bzrlib.symbol_versioning import *
37
class UIFactory(object):
40
This tells the library how to display things to the user. Through this
41
layer different applications can choose the style of UI.
45
super(UIFactory, self).__init__()
46
self._progress_bar_stack = None
48
@deprecated_method(zero_eight)
49
def progress_bar(self):
50
"""See UIFactory.nested_progress_bar()."""
51
raise NotImplementedError(self.progress_bar)
53
def get_password(self, prompt='', **kwargs):
54
"""Prompt the user for a password.
56
:param prompt: The prompt to present the user
57
:param kwargs: Arguments which will be expanded into the prompt.
58
This lets front ends display different things if
60
:return: The password string, return None if the user
63
raise NotImplementedError(self.get_password)
65
def nested_progress_bar(self):
66
"""Return a nested progress bar.
68
When the bar has been finished with, it should be released bu calling
71
raise NotImplementedError(self.nested_progress_bar)
74
"""Prepare the terminal for output.
76
This will, for example, clear text progress bars, and leave the
77
cursor at the leftmost position."""
78
raise NotImplementedError(self.clear_term)
80
def get_boolean(self, prompt):
81
"""Get a boolean question answered from the user.
83
:param prompt: a message to prompt the user with. Should be a single
84
line without terminating \n.
85
:return: True or False for y/yes or n/no.
87
raise NotImplementedError(self.get_boolean)
90
class CLIUIFactory(UIFactory):
91
"""Common behaviour for command line UI factories."""
94
super(CLIUIFactory, self).__init__()
95
self.stdin = sys.stdin
97
def get_boolean(self, prompt):
99
# FIXME: make a regexp and handle case variations as well.
102
line = self.stdin.readline()
103
if line in ('y\n', 'yes\n'):
105
if line in ('n\n', 'no\n'):
108
def prompt(self, prompt):
109
"""Emit prompt on the CLI."""
112
class SilentUIFactory(CLIUIFactory):
113
"""A UI Factory which never prints anything.
115
This is the default UI, if another one is never registered.
118
@deprecated_method(zero_eight)
119
def progress_bar(self):
120
"""See UIFactory.nested_progress_bar()."""
38
class TextUIFactory(object):
39
def progress_bar(self):
41
# this in turn is abstract, and creates either a tty or dots
42
# bar depending on what we think of the terminal
43
return bzrlib.progress.ProgressBar()
46
class SilentUIFactory(object):
47
def progress_bar(self):
121
48
return bzrlib.progress.DummyProgress()
123
def get_password(self, prompt='', **kwargs):
126
def nested_progress_bar(self):
127
if self._progress_bar_stack is None:
128
self._progress_bar_stack = bzrlib.progress.ProgressBarStack(
129
klass=bzrlib.progress.DummyProgress)
130
return self._progress_bar_stack.get_nested()
132
def clear_term(self):
136
def clear_decorator(func, *args, **kwargs):
137
"""Decorator that clears the term"""
138
ui_factory.clear_term()
139
func(*args, **kwargs)
142
51
ui_factory = SilentUIFactory()
143
"""IMPORTANT: never import this symbol directly. ONLY ever access it as