51
52
letting the bzrlib.progress.ProgressBar factory auto
52
53
select. Deprecated.
54
super(TextUIFactory, self).__init__(stdin=stdin,
55
stdout=stdout, stderr=stderr)
57
symbol_versioning.warn(symbol_versioning.deprecated_in((1, 11, 0))
58
% "bar_type parameter")
55
super(TextUIFactory, self).__init__()
56
# TODO: there's no good reason not to pass all three streams, maybe we
57
# should deprecate the default values...
59
61
# paints progress, network activity, etc
60
self._progress_view = self._make_progress_view()
62
self._progress_view = self.make_progress_view()
62
64
def clear_term(self):
63
65
"""Prepare the terminal for output.
70
72
# to clear it. We might need to separately check for the case of
71
73
self._progress_view.clear()
73
def _make_progress_view(self):
74
if os.environ.get('BZR_PROGRESS_BAR') in ('text', None, ''):
75
def get_boolean(self, prompt):
77
self.prompt(prompt + "? [y/n]: ")
78
line = self.stdin.readline().lower()
79
if line in ('y\n', 'yes\n'):
81
elif line in ('n\n', 'no\n'):
83
elif line in ('', None):
84
# end-of-file; possibly should raise an error here instead
87
def get_non_echoed_password(self):
88
isatty = getattr(self.stdin, 'isatty', None)
89
if isatty is not None and isatty():
90
# getpass() ensure the password is not echoed and other
91
# cross-platform niceties
92
password = getpass.getpass('')
94
# echo doesn't make sense without a terminal
95
password = self.stdin.readline()
98
elif password[-1] == '\n':
99
password = password[:-1]
102
def get_password(self, prompt='', **kwargs):
103
"""Prompt the user for a password.
105
:param prompt: The prompt to present the user
106
:param kwargs: Arguments which will be expanded into the prompt.
107
This lets front ends display different things if
109
:return: The password string, return None if the user
110
canceled the request.
113
self.prompt(prompt, **kwargs)
114
# There's currently no way to say 'i decline to enter a password'
115
# as opposed to 'my password is empty' -- does it matter?
116
return self.get_non_echoed_password()
118
def get_username(self, prompt, **kwargs):
119
"""Prompt the user for a username.
121
:param prompt: The prompt to present the user
122
:param kwargs: Arguments which will be expanded into the prompt.
123
This lets front ends display different things if
125
:return: The username string, return None if the user
126
canceled the request.
129
self.prompt(prompt, **kwargs)
130
username = self.stdin.readline()
133
elif username[-1] == '\n':
134
username = username[:-1]
137
def make_progress_view(self):
138
"""Construct and return a new ProgressView subclass for this UI.
140
# if the user specifically requests either text or no progress bars,
141
# always do that. otherwise, guess based on $TERM and tty presence.
142
if os.environ.get('BZR_PROGRESS_BAR') == 'text':
143
return TextProgressView(self.stderr)
144
elif os.environ.get('BZR_PROGRESS_BAR') == 'none':
145
return NullProgressView()
146
elif progress._supports_progress(self.stderr):
75
147
return TextProgressView(self.stderr)
77
149
return NullProgressView()
82
154
self.stdout.write(msg + '\n')
156
def prompt(self, prompt, **kwargs):
157
"""Emit prompt on the CLI.
159
:param kwargs: Dictionary of arguments to insert into the prompt,
160
to allow UIs to reformat the prompt.
163
# See <https://launchpad.net/bugs/365891>
164
prompt = prompt % kwargs
165
prompt = prompt.encode(osutils.get_terminal_encoding(), 'replace')
167
self.stderr.write(prompt)
84
169
def report_transport_activity(self, transport, byte_count, direction):
85
170
"""Called by transports as they do IO.
105
190
self._progress_view.clear()
108
class NullProgressView(object):
109
"""Soak up and ignore progress information."""
114
def show_progress(self, task):
117
def show_transport_activity(self, transport, direction, byte_count):
121
193
class TextProgressView(object):
122
194
"""Display of progress bar and other information on a tty.