/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Martin Pool
  • Date: 2006-10-06 02:04:17 UTC
  • mfrom: (1908.10.1 bench_usecases.merge2)
  • mto: This revision was merged to the branch mainline in revision 2068.
  • Revision ID: mbp@sourcefrog.net-20061006020417-4949ca86f4417a4d
merge additional fix from cfbolz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005 Canonical Ltd
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
28
displays no output.
29
29
"""
30
30
 
 
31
import sys
31
32
 
32
33
import bzrlib.progress
33
 
from bzrlib.symbol_versioning import *
 
34
from bzrlib.symbol_versioning import (deprecated_method, zero_eight)
34
35
 
35
36
 
36
37
class UIFactory(object):
76
77
        cursor at the leftmost position."""
77
78
        raise NotImplementedError(self.clear_term)
78
79
 
79
 
 
80
 
class SilentUIFactory(UIFactory):
 
80
    def get_boolean(self, prompt):
 
81
        """Get a boolean question answered from the user. 
 
82
 
 
83
        :param prompt: a message to prompt the user with. Should be a single
 
84
        line without terminating \n.
 
85
        :return: True or False for y/yes or n/no.
 
86
        """
 
87
        raise NotImplementedError(self.get_boolean)
 
88
 
 
89
 
 
90
class CLIUIFactory(UIFactory):
 
91
    """Common behaviour for command line UI factories."""
 
92
 
 
93
    def __init__(self):
 
94
        super(CLIUIFactory, self).__init__()
 
95
        self.stdin = sys.stdin
 
96
 
 
97
    def get_boolean(self, prompt):
 
98
        self.clear_term()
 
99
        # FIXME: make a regexp and handle case variations as well.
 
100
        while True:
 
101
            self.prompt(prompt)
 
102
            line = self.stdin.readline()
 
103
            if line in ('y\n', 'yes\n'):
 
104
                return True
 
105
            if line in ('n\n', 'no\n'):
 
106
                return False
 
107
 
 
108
    def prompt(self, prompt):
 
109
        """Emit prompt on the CLI."""
 
110
 
 
111
 
 
112
class SilentUIFactory(CLIUIFactory):
81
113
    """A UI Factory which never prints anything.
82
114
 
83
115
    This is the default UI, if another one is never registered.