~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

Allows ui factories to query users for an integer.

* bzrlib/tests/test_ui.py:
(TestTextUIFactory.test_text_ui_get_integer,
CannedInputUIFactoryTests.test_canned_input_get_input): Tests.

* bzrlib/ui/__init__.py:
(UIFactory.get_integer): New definition.
(CannedInputUIFactory.get_integer): Implementation.

* bzrlib/ui/text.py:
(TextUIFactory.get_integer): Implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
                # end-of-file; possibly should raise an error here instead
83
83
                return None
84
84
 
 
85
    def get_integer(self, prompt):
 
86
        while True:
 
87
            self.prompt(prompt)
 
88
            line = self.stdin.readline()
 
89
            try:
 
90
                return int(line)
 
91
            except ValueError:
 
92
                pass
 
93
 
85
94
    def get_non_echoed_password(self):
86
95
        isatty = getattr(self.stdin, 'isatty', None)
87
96
        if isatty is not None and isatty():