# HG changeset patch # User Steve Borho # Date 2009-04-30 15:15:32 # Node ID 98acfd1d2b08627dd20aa8dcd893a4a23e828351 # Parent 2263c49af028ec97cf8a2d11ef134e524bbd88fc 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. diff --git a/hgext/record.py b/hgext/record.py --- a/hgext/record.py +++ b/hgext/record.py @@ -282,8 +282,16 @@ def filterpatch(ui, chunks): if resp_file[0] is not None: return resp_file[0] while True: - choices = _('[Ynsfdaq?]') - r = (ui.prompt("%s %s " % (query, choices), '(?i)%s?$' % choices) + resps = _('[Ynsfdaq?]') + choices = (_('&Yes, record this change'), + _('&No, skip this change'), + _('&Skip remaining changes to this file'), + _('Record remaining changes to this &file'), + _('&Done, skip remaining changes and files'), + _('Record &all changes to all remaining files'), + _('&Quit, recording no changes'), + _('&?')) + r = (ui.prompt("%s %s " % (query, resps), choices) or _('y')).lower() if r == _('?'): doc = gettext(record.__doc__) diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -143,7 +143,7 @@ def filemerge(repo, mynode, orig, fcd, f tool = "internal:local" if ui.prompt(_(" no tool found to merge %s\n" "keep (l)ocal or take (o)ther?") % fd, - _("[lo]"), _("l")) != _("l"): + (_("&Local"), _("&Other")), _("l")) != _("l"): tool = "internal:other" if tool == "internal:local": return 0 @@ -205,7 +205,7 @@ def filemerge(repo, mynode, orig, fcd, f if filecmp.cmp(repo.wjoin(fd), back): if ui.prompt(_(" output file %s appears unchanged\n" "was merge successful (yn)?") % fd, - _("[yn]"), _("n")) != _("y"): + (_("&Yes"), _("&No")), _("n")) != _("y"): r = 1 if _toolbool(ui, tool, "fixeol"): diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -147,8 +147,9 @@ def manifestmerge(repo, p1, p2, pa, over if not a: # both differ from parent r = repo.ui.prompt( _(" conflicting flags for %s\n" - "(n)one, e(x)ec or sym(l)ink?") % f, "[nxl]", "n") - return r != "n" and r or '' + "(n)one, e(x)ec or sym(l)ink?") % f, + (_("&None"), _("E&xec"), _("Sym&link")), _("n")) + return r != _("n") and r or '' if m == a: return n # changed from m to n return m # changed from n to m @@ -219,7 +220,7 @@ def manifestmerge(repo, p1, p2, pa, over if repo.ui.prompt( _(" local changed %s which remote deleted\n" "use (c)hanged version or (d)elete?") % f, - _("[cd]"), _("c")) == _("d"): + (_("&Changed"), _("&Delete")), _("c")) == _("d"): act("prompt delete", "r", f) act("prompt keep", "a", f) else: @@ -254,7 +255,7 @@ def manifestmerge(repo, p1, p2, pa, over if repo.ui.prompt( _("remote changed %s which local deleted\n" "use (c)hanged version or leave (d)eleted?") % f, - _("[cd]"), _("c")) == _("c"): + (_("&Changed"), _("&Deleted")), _("c")) == _("c"): act("prompt recreating", "g", f, m2.flags(f)) else: act("remote created", "g", f, m2.flags(f)) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -268,10 +268,12 @@ class ui(object): 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 @@ class ui(object): 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: