~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf_ui.py

  • Committer: Patch Queue Manager
  • Date: 2015-12-17 18:39:00 UTC
  • mfrom: (6606.1.2 fix-float)
  • Revision ID: pqm@pqm.ubuntu.com-20151217183900-0719du2uv1kwu3lc
(vila) Inline testtools private method to fix an issue in xenial (the
 private implementation has changed in an backward incompatible way).
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
17
18
 
18
19
from cStringIO import StringIO
19
20
import shutil
251
252
        diff_file.seek(0)
252
253
        return patches.parse_patch(diff_file)
253
254
 
254
 
    def prompt(self, message):
255
 
        """Prompt the user for a character.
256
 
 
257
 
        :param message: The message to prompt a user with.
258
 
        :return: A character.
259
 
        """
260
 
        if not sys.stdin.isatty():
261
 
            # Since there is no controlling terminal we will hang when trying
262
 
            # to prompt the user, better abort now.  See
263
 
            # https://code.launchpad.net/~bialix/bzr/shelve-no-tty/+merge/14905
264
 
            # for more context.
265
 
            raise errors.BzrError(gettext("You need a controlling terminal."))
266
 
        sys.stdout.write(message)
267
 
        char = osutils.getchar()
268
 
        sys.stdout.write("\r" + ' ' * len(message) + '\r')
269
 
        sys.stdout.flush()
270
 
        return char
271
 
 
272
 
    def prompt_bool(self, question, long=False, allow_editor=False):
 
255
    def prompt(self, message, choices, default):
 
256
        return ui.ui_factory.choose(message, choices, default=default)
 
257
 
 
258
    def prompt_bool(self, question, allow_editor=False):
273
259
        """Prompt the user with a yes/no question.
274
260
 
275
261
        This may be overridden by self.auto.  It may also *set* self.auto.  It
279
265
        """
280
266
        if self.auto:
281
267
            return True
282
 
        editor_string = ''
283
 
        if long:
284
 
            if allow_editor:
285
 
                editor_string = '(E)dit manually, '
286
 
            prompt = ' [(y)es, (N)o, %s(f)inish, or (q)uit]' % editor_string
 
268
        alternatives_chars = 'yn'
 
269
        alternatives = '&yes\n&No'
 
270
        if allow_editor:
 
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)
 
276
        if choice is None:
 
277
            # EOF.
 
278
            char = 'n'
287
279
        else:
288
 
            if allow_editor:
289
 
                editor_string = 'e'
290
 
            prompt = ' [yN%sfq?]' % editor_string
291
 
        char = self.prompt(question + prompt)
 
280
            char = alternatives_chars[choice]
292
281
        if char == 'y':
293
282
            return True
294
283
        elif char == 'e' and allow_editor:
296
285
        elif char == 'f':
297
286
            self.auto = True
298
287
            return True
299
 
        elif char == '?':
300
 
            return self.prompt_bool(question, long=True)
301
288
        if char == 'q':
302
289
            raise errors.UserAbort()
303
290
        else: