53
52
letting the bzrlib.progress.ProgressBar factory auto
54
53
select. Deprecated.
56
super(TextUIFactory, self).__init__(stdin=stdin,
57
stdout=stdout, stderr=stderr)
59
symbol_versioning.warn(symbol_versioning.deprecated_in((1, 11, 0))
60
% "bar_type parameter")
55
super(TextUIFactory, self).__init__()
61
59
# paints progress, network activity, etc
62
60
self._progress_view = self.make_progress_view()
72
70
# to clear it. We might need to separately check for the case of
73
71
self._progress_view.clear()
73
def get_boolean(self, prompt):
74
# FIXME: make a regexp and handle case variations as well.
76
self.prompt(prompt + "? [y/n]: ")
77
line = self.stdin.readline()
78
if line in ('y\n', 'yes\n'):
80
if line in ('n\n', 'no\n'):
83
def get_non_echoed_password(self):
84
isatty = getattr(self.stdin, 'isatty', None)
85
if isatty is not None and isatty():
86
# getpass() ensure the password is not echoed and other
87
# cross-platform niceties
88
password = getpass.getpass('')
90
# echo doesn't make sense without a terminal
91
password = self.stdin.readline()
94
elif password[-1] == '\n':
95
password = password[:-1]
98
def get_password(self, prompt='', **kwargs):
99
"""Prompt the user for a password.
101
:param prompt: The prompt to present the user
102
:param kwargs: Arguments which will be expanded into the prompt.
103
This lets front ends display different things if
105
:return: The password string, return None if the user
106
canceled the request.
109
self.prompt(prompt, **kwargs)
110
# There's currently no way to say 'i decline to enter a password'
111
# as opposed to 'my password is empty' -- does it matter?
112
return self.get_non_echoed_password()
114
def get_username(self, prompt, **kwargs):
115
"""Prompt the user for a username.
117
:param prompt: The prompt to present the user
118
:param kwargs: Arguments which will be expanded into the prompt.
119
This lets front ends display different things if
121
:return: The username string, return None if the user
122
canceled the request.
125
self.prompt(prompt, **kwargs)
126
username = self.stdin.readline()
129
elif username[-1] == '\n':
130
username = username[:-1]
75
133
def make_progress_view(self):
76
134
"""Construct and return a new ProgressView subclass for this UI.
92
150
self.stdout.write(msg + '\n')
152
def prompt(self, prompt, **kwargs):
153
"""Emit prompt on the CLI.
155
:param kwargs: Dictionary of arguments to insert into the prompt,
156
to allow UIs to reformat the prompt.
159
# See <https://launchpad.net/bugs/365891>
160
prompt = prompt % kwargs
161
prompt = prompt.encode(osutils.get_terminal_encoding(), 'replace')
163
self.stderr.write(prompt)
94
165
def report_transport_activity(self, transport, byte_count, direction):
95
166
"""Called by transports as they do IO.