~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

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
 
154
155
            "The command 'bzr %(deprecated_name)s' "
155
156
            "has been deprecated in bzr %(deprecated_in_version)s. "
156
157
            "Please use 'bzr %(recommended_name)s' instead."),
 
158
        deprecated_command_option=(
 
159
            "The option '%(deprecated_name)s' to 'bzr %(command)s' "
 
160
            "has been deprecated in bzr %(deprecated_in_version)s. "
 
161
            "Please use '%(recommended_name)s' instead."),
157
162
        recommend_upgrade=("%(current_format_name)s is deprecated "
158
163
            "and a better format is available.\n"
159
164
            "It is recommended that you upgrade by "
320
325
            warnings.warn(fail)   # so tests will fail etc
321
326
            return fail
322
327
 
 
328
    def choose(self, msg, choices, default=None):
 
329
        """Prompt the user for a list of alternatives.
 
330
 
 
331
        :param msg: message to be shown as part of the prompt.
 
332
 
 
333
        :param choices: list of choices, with the individual choices separated
 
334
            by '\n', e.g.: choose("Save changes?", "&Yes\n&No\n&Cancel"). The
 
335
            letter after the '&' is the shortcut key for that choice. Thus you
 
336
            can type 'c' to select "Cancel".  Shorcuts are case insensitive.
 
337
            The shortcut does not need to be the first letter. If a shorcut key
 
338
            is not provided, the first letter for the choice will be used.
 
339
 
 
340
        :param default: default choice (index), returned for example when enter
 
341
            is pressed for the console version.
 
342
 
 
343
        :return: the index fo the user choice (so '0', '1' or '2' for
 
344
            respectively yes/no/cancel in the previous example).
 
345
        """
 
346
        raise NotImplementedError(self.choose)
 
347
 
323
348
    def get_boolean(self, prompt):
324
349
        """Get a boolean question answered from the user.
325
350
 
327
352
            line without terminating \\n.
328
353
        :return: True or False for y/yes or n/no.
329
354
        """
330
 
        raise NotImplementedError(self.get_boolean)
 
355
        choice = self.choose(prompt + '?', '&yes\n&no', default=None)
 
356
        return 0 == choice
331
357
 
332
358
    def get_integer(self, prompt):
333
359
        """Get an integer from the user.