Mercurial > hg-stable
changeset 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 | 2263c49af028 |
children | 54a4b520bd7d |
files | hgext/record.py mercurial/filemerge.py mercurial/merge.py mercurial/ui.py |
diffstat | 4 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/record.py Fri Apr 24 14:40:56 2009 -0700 +++ b/hgext/record.py Thu Apr 30 10:15:32 2009 -0500 @@ -282,8 +282,16 @@ 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__)
--- a/mercurial/filemerge.py Fri Apr 24 14:40:56 2009 -0700 +++ b/mercurial/filemerge.py Thu Apr 30 10:15:32 2009 -0500 @@ -143,7 +143,7 @@ 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 @@ 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"):
--- a/mercurial/merge.py Fri Apr 24 14:40:56 2009 -0700 +++ b/mercurial/merge.py Thu Apr 30 10:15:32 2009 -0500 @@ -147,8 +147,9 @@ 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 @@ 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 @@ 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))
--- 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: