51
53
letting the bzrlib.progress.ProgressBar factory auto
52
54
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")
56
super(TextUIFactory, self).__init__()
57
# TODO: there's no good reason not to pass all three streams, maybe we
58
# should deprecate the default values...
59
62
# paints progress, network activity, etc
60
self._progress_view = self._make_progress_view()
63
self._progress_view = self.make_progress_view()
62
65
def clear_term(self):
63
66
"""Prepare the terminal for output.
70
73
# to clear it. We might need to separately check for the case of
71
74
self._progress_view.clear()
73
def _make_progress_view(self):
74
if os.environ.get('BZR_PROGRESS_BAR') in ('text', None, ''):
76
def get_boolean(self, prompt):
78
self.prompt(prompt + "? [y/n]: ")
79
line = self.stdin.readline().lower()
80
if line in ('y\n', 'yes\n'):
82
elif line in ('n\n', 'no\n'):
84
elif line in ('', None):
85
# end-of-file; possibly should raise an error here instead
88
def get_non_echoed_password(self):
89
isatty = getattr(self.stdin, 'isatty', None)
90
if isatty is not None and isatty():
91
# getpass() ensure the password is not echoed and other
92
# cross-platform niceties
93
password = getpass.getpass('')
95
# echo doesn't make sense without a terminal
96
password = self.stdin.readline()
99
elif password[-1] == '\n':
100
password = password[:-1]
103
def get_password(self, prompt='', **kwargs):
104
"""Prompt the user for a password.
106
:param prompt: The prompt to present the user
107
:param kwargs: Arguments which will be expanded into the prompt.
108
This lets front ends display different things if
110
:return: The password string, return None if the user
111
canceled the request.
114
self.prompt(prompt, **kwargs)
115
# There's currently no way to say 'i decline to enter a password'
116
# as opposed to 'my password is empty' -- does it matter?
117
return self.get_non_echoed_password()
119
def get_username(self, prompt, **kwargs):
120
"""Prompt the user for a username.
122
:param prompt: The prompt to present the user
123
:param kwargs: Arguments which will be expanded into the prompt.
124
This lets front ends display different things if
126
:return: The username string, return None if the user
127
canceled the request.
130
self.prompt(prompt, **kwargs)
131
username = self.stdin.readline()
134
elif username[-1] == '\n':
135
username = username[:-1]
138
def make_progress_view(self):
139
"""Construct and return a new ProgressView subclass for this UI.
141
# if the user specifically requests either text or no progress bars,
142
# always do that. otherwise, guess based on $TERM and tty presence.
143
if os.environ.get('BZR_PROGRESS_BAR') == 'text':
144
return TextProgressView(self.stderr)
145
elif os.environ.get('BZR_PROGRESS_BAR') == 'none':
146
return NullProgressView()
147
elif progress._supports_progress(self.stderr):
75
148
return TextProgressView(self.stderr)
77
150
return NullProgressView()
82
155
self.stdout.write(msg + '\n')
157
def prompt(self, prompt, **kwargs):
158
"""Emit prompt on the CLI.
160
:param kwargs: Dictionary of arguments to insert into the prompt,
161
to allow UIs to reformat the prompt.
164
# See <https://launchpad.net/bugs/365891>
165
prompt = prompt % kwargs
166
prompt = prompt.encode(osutils.get_terminal_encoding(), 'replace')
168
self.stderr.write(prompt)
84
170
def report_transport_activity(self, transport, byte_count, direction):
85
171
"""Called by transports as they do IO.
105
191
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
194
class TextProgressView(object):
122
195
"""Display of progress bar and other information on a tty.