252
252
diff_file.seek(0)
253
253
return patches.parse_patch(diff_file)
255
def _char_based(self):
256
# FIXME: A bit hackish to use INSIDE_EMACS here, but there is another
257
# work in progress moving this method (and more importantly prompt()
258
# below) into the ui area and address the issue in better ways.
260
return os.environ.get('INSIDE_EMACS', None) is None
262
def prompt(self, message):
263
"""Prompt the user for a character.
265
:param message: The message to prompt a user with.
266
:return: A character.
268
char_based = self._char_based()
269
if char_based and not sys.stdin.isatty():
270
# Since there is no controlling terminal we will hang when
271
# trying to prompt the user, better abort now. See
272
# https://code.launchpad.net/~bialix/bzr/shelve-no-tty/+merge/14905
274
raise errors.BzrError(gettext("You need a controlling terminal."))
275
sys.stdout.write(message)
277
# We peek one char at a time which requires a real term here
278
char = osutils.getchar()
280
# While running tests (or under emacs) the input is line buffered
281
# so we must not use osutils.getchar(). Instead we switch to a mode
282
# where each line is terminated by a new line
283
line = sys.stdin.readline()
285
# XXX: Warn if more than one char is typed ?
288
# Empty input, callers handle it as enter
290
sys.stdout.write("\r" + ' ' * len(message) + '\r')
294
def prompt_bool(self, question, long=False, allow_editor=False):
255
def prompt(self, message, choices, default):
256
return ui.ui_factory.confirm(message, choices, default=default)
258
def prompt_bool(self, question, allow_editor=False):
295
259
"""Prompt the user with a yes/no question.
297
261
This may be overridden by self.auto. It may also *set* self.auto. It
307
editor_string = '(E)dit manually, '
308
prompt = ' [(y)es, (N)o, %s(f)inish, or (q)uit]' % editor_string
268
alternatives_chars = 'yn'
269
alternatives = '&yes\n&No'
271
alternatives_chars += 'e'
272
alternatives += '\n&edit manually'
273
alternatives_chars += 'fq'
274
alternatives += '\n&finish\n&quit'
275
choice = self.prompt(question, alternatives, 1)
312
prompt = ' [yN%sfq?]' % editor_string
313
char = self.prompt(question + prompt)
280
char = alternatives_chars[choice]
316
283
elif char == 'e' and allow_editor: