Show More
@@ -640,6 +640,20 b' class ui(object):' | |||
|
640 | 640 | except EOFError: |
|
641 | 641 | raise util.Abort(_('response expected')) |
|
642 | 642 | |
|
643 | @staticmethod | |
|
644 | def extractchoices(prompt): | |
|
645 | """Extract prompt message and list of choices from specified prompt. | |
|
646 | ||
|
647 | This returns tuple "(message, choices)", and "choices" is the | |
|
648 | list of tuple "(response character, text without &)". | |
|
649 | """ | |
|
650 | parts = prompt.split('$$') | |
|
651 | msg = parts[0].rstrip(' ') | |
|
652 | choices = [p.strip(' ') for p in parts[1:]] | |
|
653 | return (msg, | |
|
654 | [(s[s.index('&') + 1].lower(), s.replace('&', '', 1)) | |
|
655 | for s in choices]) | |
|
656 | ||
|
643 | 657 | def promptchoice(self, prompt, default=0): |
|
644 | 658 | """Prompt user with a message, read response, and ensure it matches |
|
645 | 659 | one of the provided choices. The prompt is formatted as follows: |
@@ -651,10 +665,8 b' class ui(object):' | |||
|
651 | 665 | returned. |
|
652 | 666 | """ |
|
653 | 667 | |
|
654 | parts = prompt.split('$$') | |
|
655 | msg = parts[0].rstrip(' ') | |
|
656 | choices = [p.strip(' ') for p in parts[1:]] | |
|
657 | resps = [s[s.index('&') + 1].lower() for s in choices] | |
|
668 | msg, choices = self.extractchoices(prompt) | |
|
669 | resps = [r for r, t in choices] | |
|
658 | 670 | while True: |
|
659 | 671 | r = self.prompt(msg, resps[default]) |
|
660 | 672 | if r.lower() in resps: |
General Comments 0
You need to be logged in to leave comments.
Login now