mercurial/ui.py
changeset 8259 98acfd1d2b08
parent 8225 46293a0c7e9f
child 8312 b87a50b7125c
--- 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: