mercurial/ui.py
changeset 19226 c58b6ab4c26f
parent 19195 9311cd5c09ed
child 19536 ab3cf67740d6
child 19880 ba2be32d14f2
equal deleted inserted replaced
19225:6cf8e3b4e074 19226:c58b6ab4c26f
   637                 return default
   637                 return default
   638             return r
   638             return r
   639         except EOFError:
   639         except EOFError:
   640             raise util.Abort(_('response expected'))
   640             raise util.Abort(_('response expected'))
   641 
   641 
   642     def promptchoice(self, msg, choices, default=0):
   642     def promptchoice(self, prompt, default=0):
   643         """Prompt user with msg, read response, and ensure it matches
   643         """Prompt user with a message, read response, and ensure it matches
   644         one of the provided choices. The index of the choice is returned.
   644         one of the provided choices. The prompt is formatted as follows:
   645         choices is a sequence of acceptable responses with the format:
   645 
   646         ('&None', 'E&xec', 'Sym&link') Responses are case insensitive.
   646            "would you like fries with that (Yn)? $$ &Yes $$ &No"
   647         If ui is not interactive, the default is returned.
   647 
       
   648         The index of the choice is returned. Responses are case
       
   649         insensitive. If ui is not interactive, the default is
       
   650         returned.
   648         """
   651         """
       
   652 
       
   653         parts = prompt.split('$$')
       
   654         msg = parts[0].rstrip(' ')
       
   655         choices = [p.strip(' ') for p in parts[1:]]
   649         resps = [s[s.index('&') + 1].lower() for s in choices]
   656         resps = [s[s.index('&') + 1].lower() for s in choices]
   650         while True:
   657         while True:
   651             r = self.prompt(msg, resps[default])
   658             r = self.prompt(msg, resps[default])
   652             if r.lower() in resps:
   659             if r.lower() in resps:
   653                 return resps.index(r.lower())
   660                 return resps.index(r.lower())