32
35
import bzrlib.progress
33
from bzrlib.symbol_versioning import *
36
class UIFactory(object):
39
This tells the library how to display things to the user. Through this
40
layer different applications can choose the style of UI.
44
super(UIFactory, self).__init__()
45
self._progress_bar_stack = None
47
@deprecated_method(zero_eight)
48
def progress_bar(self):
49
"""See UIFactory.nested_progress_bar()."""
50
raise NotImplementedError(self.progress_bar)
52
def get_password(self, prompt='', **kwargs):
53
"""Prompt the user for a password.
55
:param prompt: The prompt to present the user
56
:param kwargs: Arguments which will be expanded into the prompt.
57
This lets front ends display different things if
59
:return: The password string, return None if the user
62
raise NotImplementedError(self.get_password)
64
def nested_progress_bar(self):
65
"""Return a nested progress bar.
67
When the bar has been finished with, it should be released bu calling
70
raise NotImplementedError(self.nested_progress_bar)
73
"""Prepare the terminal for output.
75
This will, for example, clear text progress bars, and leave the
76
cursor at the leftmost position."""
77
raise NotImplementedError(self.clear_term)
80
class SilentUIFactory(UIFactory):
81
"""A UI Factory which never prints anything.
83
This is the default UI, if another one is never registered.
86
@deprecated_method(zero_eight)
87
def progress_bar(self):
88
"""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):
89
48
return bzrlib.progress.DummyProgress()
91
def get_password(self, prompt='', **kwargs):
94
def nested_progress_bar(self):
95
if self._progress_bar_stack is None:
96
self._progress_bar_stack = bzrlib.progress.ProgressBarStack(
97
klass=bzrlib.progress.DummyProgress)
98
return self._progress_bar_stack.get_nested()
100
def clear_term(self):
104
def clear_decorator(func, *args, **kwargs):
105
"""Decorator that clears the term"""
106
ui_factory.clear_term()
107
func(*args, **kwargs)
110
51
ui_factory = SilentUIFactory()
111
"""IMPORTANT: never import this symbol directly. ONLY ever access it as