diff mercurial/ui.py @ 8259:98acfd1d2b08

ui: replace regexp pattern with sequence of choices Use ampersands (&) to delineate the response char in each choice. ui.prompt() responses are now explicitly case insensitive. GUIs that subclass ui can generate dialogs from the full choice names.
author Steve Borho <steve@borho.org>
date Thu, 30 Apr 2009 10:15:32 -0500
parents 46293a0c7e9f
children b87a50b7125c
line wrap: on
line diff
--- a/mercurial/ui.py	Fri Apr 24 14:40:56 2009 -0700
+++ b/mercurial/ui.py	Thu Apr 30 10:15:32 2009 -0500
@@ -268,10 +268,12 @@
             line = line[:-1]
         return line
 
-    def prompt(self, msg, pat=None, default="y"):
-        """Prompt user with msg, read response, and ensure it matches pat
-
-        If not interactive -- the default is returned
+    def prompt(self, msg, choices=None, default="y"):
+        """Prompt user with msg, read response, and ensure it matches
+        one of the provided choices. choices is a sequence of acceptable
+        responses with the format: ('&None', 'E&xec', 'Sym&link')
+        No sequence implies no response checking. Responses are case
+        insensitive. If ui is not interactive, the default is returned.
         """
         if not self.interactive():
             self.note(msg, ' ', default, "\n")
@@ -281,8 +283,11 @@
                 r = self._readline(msg + ' ')
                 if not r:
                     return default
-                if not pat or re.match(pat, r):
+                if not choices:
                     return r
+                resps = [s[s.index('&')+1].lower() for s in choices]
+                if r.lower() in resps:
+                    return r.lower()
                 else:
                     self.write(_("unrecognized response\n"))
             except EOFError: