comparison mercurial/ui.py @ 33740:d880a6bcef2f

ui: refactor extractchoices so it doesn't break on Python 3 Differential Revision: https://phab.mercurial-scm.org/D275
author Augie Fackler <augie@google.com>
date Mon, 24 Jul 2017 13:48:32 -0400
parents 6294654453ee
children 86aca74a063b
comparison
equal deleted inserted replaced
33739:888f24810ea2 33740:d880a6bcef2f
1267 # choices containing spaces, ASCII, or basically anything 1267 # choices containing spaces, ASCII, or basically anything
1268 # except an ampersand followed by a character. 1268 # except an ampersand followed by a character.
1269 m = re.match(br'(?s)(.+?)\$\$([^\$]*&[^ \$].*)', prompt) 1269 m = re.match(br'(?s)(.+?)\$\$([^\$]*&[^ \$].*)', prompt)
1270 msg = m.group(1) 1270 msg = m.group(1)
1271 choices = [p.strip(' ') for p in m.group(2).split('$$')] 1271 choices = [p.strip(' ') for p in m.group(2).split('$$')]
1272 return (msg, 1272 def choicetuple(s):
1273 [(s[s.index('&') + 1].lower(), s.replace('&', '', 1)) 1273 ampidx = s.index('&')
1274 for s in choices]) 1274 return s[ampidx + 1:ampidx + 2].lower(), s.replace('&', '', 1)
1275 return (msg, [choicetuple(s) for s in choices])
1275 1276
1276 def promptchoice(self, prompt, default=0): 1277 def promptchoice(self, prompt, default=0):
1277 """Prompt user with a message, read response, and ensure it matches 1278 """Prompt user with a message, read response, and ensure it matches
1278 one of the provided choices. The prompt is formatted as follows: 1279 one of the provided choices. The prompt is formatted as follows:
1279 1280