Details
Details
- Reviewers
quark - Group Reviewers
hg-reviewers - Commits
- rHGd880a6bcef2f: ui: refactor extractchoices so it doesn't break on Python 3
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| quark |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/ui.py (7 lines) |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | durin42 | ||
| Closed | durin42 | ||
| Abandoned | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 |
| # Sadly, the prompt string may have been built with a filename | # Sadly, the prompt string may have been built with a filename | ||||
| # containing "$$" so let's try to find the first valid-looking | # containing "$$" so let's try to find the first valid-looking | ||||
| # prompt to start parsing. Sadly, we also can't rely on | # prompt to start parsing. Sadly, we also can't rely on | ||||
| # choices containing spaces, ASCII, or basically anything | # choices containing spaces, ASCII, or basically anything | ||||
| # except an ampersand followed by a character. | # except an ampersand followed by a character. | ||||
| m = re.match(br'(?s)(.+?)\$\$([^\$]*&[^ \$].*)', prompt) | m = re.match(br'(?s)(.+?)\$\$([^\$]*&[^ \$].*)', prompt) | ||||
| msg = m.group(1) | msg = m.group(1) | ||||
| choices = [p.strip(' ') for p in m.group(2).split('$$')] | choices = [p.strip(' ') for p in m.group(2).split('$$')] | ||||
| return (msg, | def choicetuple(s): | ||||
| [(s[s.index('&') + 1].lower(), s.replace('&', '', 1)) | ampidx = s.index('&') | ||||
| for s in choices]) | return s[ampidx + 1:ampidx + 2].lower(), s.replace('&', '', 1) | ||||
| return (msg, [choicetuple(s) for s in choices]) | |||||
| def promptchoice(self, prompt, default=0): | def promptchoice(self, prompt, default=0): | ||||
| """Prompt user with a message, read response, and ensure it matches | """Prompt user with a message, read response, and ensure it matches | ||||
| one of the provided choices. The prompt is formatted as follows: | one of the provided choices. The prompt is formatted as follows: | ||||
| "would you like fries with that (Yn)? $$ &Yes $$ &No" | "would you like fries with that (Yn)? $$ &Yes $$ &No" | ||||
| The index of the choice is returned. Responses are case | The index of the choice is returned. Responses are case | ||||