~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    back to working through the terminal.
42
42
"""
43
43
 
 
44
from __future__ import absolute_import
44
45
 
45
46
import warnings
46
47
 
165
166
            "  bzr upgrade %(basedir)s"),
166
167
        locks_steal_dead=(
167
168
            u"Stole dead lock %(lock_url)s %(other_holder_info)s."),
 
169
        not_checking_ssl_cert=(
 
170
            u"Not checking SSL certificate for %(host)s."),
168
171
        )
169
172
 
170
173
    def __init__(self):
324
327
            warnings.warn(fail)   # so tests will fail etc
325
328
            return fail
326
329
 
 
330
    def choose(self, msg, choices, default=None):
 
331
        """Prompt the user for a list of alternatives.
 
332
 
 
333
        :param msg: message to be shown as part of the prompt.
 
334
 
 
335
        :param choices: list of choices, with the individual choices separated
 
336
            by '\n', e.g.: choose("Save changes?", "&Yes\n&No\n&Cancel"). The
 
337
            letter after the '&' is the shortcut key for that choice. Thus you
 
338
            can type 'c' to select "Cancel".  Shorcuts are case insensitive.
 
339
            The shortcut does not need to be the first letter. If a shorcut key
 
340
            is not provided, the first letter for the choice will be used.
 
341
 
 
342
        :param default: default choice (index), returned for example when enter
 
343
            is pressed for the console version.
 
344
 
 
345
        :return: the index fo the user choice (so '0', '1' or '2' for
 
346
            respectively yes/no/cancel in the previous example).
 
347
        """
 
348
        raise NotImplementedError(self.choose)
 
349
 
327
350
    def get_boolean(self, prompt):
328
351
        """Get a boolean question answered from the user.
329
352
 
331
354
            line without terminating \\n.
332
355
        :return: True or False for y/yes or n/no.
333
356
        """
334
 
        raise NotImplementedError(self.get_boolean)
 
357
        choice = self.choose(prompt + '?', '&yes\n&no', default=None)
 
358
        return 0 == choice
335
359
 
336
360
    def get_integer(self, prompt):
337
361
        """Get an integer from the user.