##// END OF EJS Templates
ui: extract choice from prompt...
Simon Heimberg -
r9048:86b4a9b0 default
parent child Browse files
Show More
@@ -291,25 +291,28 b' def filterpatch(ui, chunks):'
291 291 _('Record &all changes to all remaining files'),
292 292 _('&Quit, recording no changes'),
293 293 _('&?'))
294 r = (ui.prompt("%s %s " % (query, resps), choices)
295 or _('y')).lower()
296 if r == _('?'):
294 r = ui.promptchoice("%s %s " % (query, resps), choices)
295 if r == 7: # ?
297 296 doc = gettext(record.__doc__)
298 297 c = doc.find(_('y - record this change'))
299 298 for l in doc[c:].splitlines():
300 299 if l: ui.write(l.strip(), '\n')
301 300 continue
302 elif r == _('s'):
303 r = resp_file[0] = 'n'
304 elif r == _('f'):
305 r = resp_file[0] = 'y'
306 elif r == _('d'):
307 r = resp_all[0] = 'n'
308 elif r == _('a'):
309 r = resp_all[0] = 'y'
310 elif r == _('q'):
301 elif r == 0: # yes
302 ret = 'y'
303 elif r == 1: # no
304 ret = 'n'
305 elif r == 2: # Skip
306 ret = resp_file[0] = 'n'
307 elif r == 3: # file (Record remaining)
308 ret = resp_file[0] = 'y'
309 elif r == 4: # done, skip remaining
310 ret = resp_all[0] = 'n'
311 elif r == 5: # all
312 ret = resp_all[0] = 'y'
313 elif r == 6: # quit
311 314 raise util.Abort(_('user quit'))
312 return r
315 return ret
313 316 pos, total = 0, len(chunks) - 1
314 317 while chunks:
315 318 chunk = chunks.pop()
@@ -145,9 +145,9 b' def filemerge(repo, mynode, orig, fcd, f'
145 145
146 146 if not tool or tool == 'internal:prompt':
147 147 tool = "internal:local"
148 if ui.prompt(_(" no tool found to merge %s\n"
148 if ui.promptchoice(_(" no tool found to merge %s\n"
149 149 "keep (l)ocal or take (o)ther?") % fd,
150 (_("&Local"), _("&Other")), _("l")) != _("l"):
150 (_("&Local"), _("&Other")), 0):
151 151 tool = "internal:other"
152 152 if tool == "internal:local":
153 153 return 0
@@ -213,9 +213,9 b' def filemerge(repo, mynode, orig, fcd, f'
213 213
214 214 if not r and _toolbool(ui, tool, "checkchanged"):
215 215 if filecmp.cmp(repo.wjoin(fd), back):
216 if ui.prompt(_(" output file %s appears unchanged\n"
216 if ui.promptchoice(_(" output file %s appears unchanged\n"
217 217 "was merge successful (yn)?") % fd,
218 (_("&Yes"), _("&No")), _("n")) != _("y"):
218 (_("&Yes"), _("&No")), 1):
219 219 r = 1
220 220
221 221 if _toolbool(ui, tool, "fixeol"):
@@ -131,11 +131,13 b' def manifestmerge(repo, p1, p2, pa, over'
131 131 if m == n: # flags agree
132 132 return m # unchanged
133 133 if m and n and not a: # flags set, don't agree, differ from parent
134 r = repo.ui.prompt(
134 r = repo.ui.promptchoice(
135 135 _(" conflicting flags for %s\n"
136 136 "(n)one, e(x)ec or sym(l)ink?") % f,
137 (_("&None"), _("E&xec"), _("Sym&link")), _("n"))
138 return r != _("n") and r or ''
137 (_("&None"), _("E&xec"), _("Sym&link")), 0)
138 if r == 1: return "x" # Exec
139 if r == 2: return "l" # Symlink
140 return ""
139 141 if m and m != a: # changed from a to m
140 142 return m
141 143 if n and n != a: # changed from a to n
@@ -191,10 +193,10 b' def manifestmerge(repo, p1, p2, pa, over'
191 193 f, f2, f, fmerge(f, f2, f2), False)
192 194 elif f in ma: # clean, a different, no remote
193 195 if n != ma[f]:
194 if repo.ui.prompt(
196 if repo.ui.promptchoice(
195 197 _(" local changed %s which remote deleted\n"
196 198 "use (c)hanged version or (d)elete?") % f,
197 (_("&Changed"), _("&Delete")), _("c")) == _("d"):
199 (_("&Changed"), _("&Delete")), 0):
198 200 act("prompt delete", "r", f)
199 201 else:
200 202 act("prompt keep", "a", f)
@@ -222,10 +224,10 b' def manifestmerge(repo, p1, p2, pa, over'
222 224 elif f not in ma:
223 225 act("remote created", "g", f, m2.flags(f))
224 226 elif n != ma[f]:
225 if repo.ui.prompt(
227 if repo.ui.promptchoice(
226 228 _("remote changed %s which local deleted\n"
227 229 "use (c)hanged version or leave (d)eleted?") % f,
228 (_("&Changed"), _("&Deleted")), _("c")) == _("c"):
230 (_("&Changed"), _("&Deleted")), 0) == 0:
229 231 act("prompt recreating", "g", f, m2.flags(f))
230 232
231 233 return action
@@ -63,11 +63,11 b' def submerge(repo, wctx, mctx, actx):'
63 63 wctx.sub(s).get(r)
64 64 sm[s] = r
65 65 elif l[0] != r[0]: # sources differ
66 if repo.ui.prompt(
66 if repo.ui.promptchoice(
67 67 _(' subrepository sources for %s differ\n'
68 68 'use (l)ocal source (%s) or (r)emote source (%s)?')
69 69 % (s, l[0], r[0]),
70 (_('&Local'), _('&Remote')), _('l')) == _('r'):
70 (_('&Local'), _('&Remote')), 0):
71 71 wctx.sub(s).get(r)
72 72 sm[s] = r
73 73 elif l[1] == a[1]: # local side is unchanged
@@ -79,10 +79,10 b' def submerge(repo, wctx, mctx, actx):'
79 79 elif l == a: # remote removed, local unchanged
80 80 wctx.sub(s).remove()
81 81 else:
82 if repo.ui.prompt(
82 if repo.ui.promptchoice(
83 83 _(' local changed subrepository %s which remote removed\n'
84 84 'use (c)hanged version or (d)elete?') % s,
85 (_('&Changed'), _('&Delete')), _('c')) == _('d'):
85 (_('&Changed'), _('&Delete')), 0):
86 86 wctx.sub(s).remove()
87 87
88 88 for s, r in s2.items():
@@ -92,10 +92,10 b' def submerge(repo, wctx, mctx, actx):'
92 92 wctx.sub(s).get(r)
93 93 sm[s] = r
94 94 elif r != sa[s]:
95 if repo.ui.prompt(
95 if repo.ui.promptchoice(
96 96 _(' remote changed subrepository %s which local removed\n'
97 97 'use (c)hanged version or (d)elete?') % s,
98 (_('&Changed'), _('&Delete')), _('c')) == _('c'):
98 (_('&Changed'), _('&Delete')), 0) == 0:
99 99 wctx.sub(s).get(r)
100 100 sm[s] = r
101 101
@@ -269,30 +269,35 b' class ui(object):'
269 269 line = line[:-1]
270 270 return line
271 271
272 def prompt(self, msg, choices=None, default="y"):
273 """Prompt user with msg, read response, and ensure it matches
274 one of the provided choices. choices is a sequence of acceptable
275 responses with the format: ('&None', 'E&xec', 'Sym&link')
276 No sequence implies no response checking. Responses are case
277 insensitive. If ui is not interactive, the default is returned.
272 def prompt(self, msg, default="y"):
273 """Prompt user with msg, read response.
274 If ui is not interactive, the default is returned.
278 275 """
279 276 if not self.interactive():
280 277 self.write(msg, ' ', default, "\n")
281 278 return default
279 try:
280 r = self._readline(msg + ' ')
281 if not r:
282 return default
283 return r
284 except EOFError:
285 raise util.Abort(_('response expected'))
286
287 def promptchoice(self, msg, choices, default=0):
288 """Prompt user with msg, read response, and ensure it matches
289 one of the provided choices. The index of the choice is returned.
290 choices is a sequence of acceptable responses with the format:
291 ('&None', 'E&xec', 'Sym&link') Responses are case insensitive.
292 If ui is not interactive, the default is returned.
293 """
294 resps = [s[s.index('&')+1].lower() for s in choices]
282 295 while True:
283 try:
284 r = self._readline(msg + ' ')
285 if not r:
286 return default
287 if not choices:
288 return r
289 resps = [s[s.index('&')+1].lower() for s in choices]
290 if r.lower() in resps:
291 return r.lower()
292 else:
293 self.write(_("unrecognized response\n"))
294 except EOFError:
295 raise util.Abort(_('response expected'))
296 r = self.prompt(msg, resps[default])
297 if r.lower() in resps:
298 return resps.index(r.lower())
299 self.write(_("unrecognized response\n"))
300
296 301
297 302 def getpass(self, prompt=None, default=None):
298 303 if not self.interactive(): return default
General Comments 0
You need to be logged in to leave comments. Login now