##// END OF EJS Templates
commandserver: attach prompt default and choices to message...
Yuya Nishihara -
r40628:83e571ea default
parent child Browse files
Show More
@@ -1390,12 +1390,16 b' class ui(object):'
1390 """Prompt user with msg, read response.
1390 """Prompt user with msg, read response.
1391 If ui is not interactive, the default is returned.
1391 If ui is not interactive, the default is returned.
1392 """
1392 """
1393 return self._prompt(msg, default=default)
1394
1395 def _prompt(self, msg, **opts):
1396 default = opts[r'default']
1393 if not self.interactive():
1397 if not self.interactive():
1394 self._writemsg(self._fmsgout, msg, ' ', type='prompt')
1398 self._writemsg(self._fmsgout, msg, ' ', type='prompt', **opts)
1395 self._writemsg(self._fmsgout, default or '', "\n",
1399 self._writemsg(self._fmsgout, default or '', "\n",
1396 type='promptecho')
1400 type='promptecho')
1397 return default
1401 return default
1398 self._writemsgnobuf(self._fmsgout, msg, type='prompt')
1402 self._writemsgnobuf(self._fmsgout, msg, type='prompt', **opts)
1399 self.flush()
1403 self.flush()
1400 try:
1404 try:
1401 r = self._readline()
1405 r = self._readline()
@@ -1449,7 +1453,7 b' class ui(object):'
1449 msg, choices = self.extractchoices(prompt)
1453 msg, choices = self.extractchoices(prompt)
1450 resps = [r for r, t in choices]
1454 resps = [r for r, t in choices]
1451 while True:
1455 while True:
1452 r = self.prompt(msg, resps[default])
1456 r = self._prompt(msg, default=resps[default], choices=choices)
1453 if r.lower() in resps:
1457 if r.lower() in resps:
1454 return resps.index(r.lower())
1458 return resps.index(r.lower())
1455 # TODO: shouldn't it be a warning?
1459 # TODO: shouldn't it be a warning?
@@ -619,6 +619,10 b' changelog and manifest would have invali'
619 > @command(b"debugprompt", norepo=True)
619 > @command(b"debugprompt", norepo=True)
620 > def debugprompt(ui):
620 > def debugprompt(ui):
621 > ui.write(b"%s\n" % ui.prompt(b"prompt:"))
621 > ui.write(b"%s\n" % ui.prompt(b"prompt:"))
622 > @command(b"debugpromptchoice", norepo=True)
623 > def debugpromptchoice(ui):
624 > msg = b"promptchoice (y/n)? $$ &Yes $$ &No"
625 > ui.write(b"%d\n" % ui.promptchoice(msg))
622 > @command(b"debugreadstdin", norepo=True)
626 > @command(b"debugreadstdin", norepo=True)
623 > def debugreadstdin(ui):
627 > def debugreadstdin(ui):
624 > ui.write(b"read: %r\n" % sys.stdin.read(1))
628 > ui.write(b"read: %r\n" % sys.stdin.read(1))
@@ -751,6 +755,24 b' structured message channel:'
751 message: '\xa2DdataOchecking files\nDtypeFstatus'
755 message: '\xa2DdataOchecking files\nDtypeFstatus'
752 message: '\xa2DdataX/checked 0 changesets with 0 changes to 0 files\nDtypeFstatus'
756 message: '\xa2DdataX/checked 0 changesets with 0 changes to 0 files\nDtypeFstatus'
753
757
758 >>> from hgclient import checkwith, readchannel, runcommand, stringio
759 >>> @checkwith(extraargs=[b'--config', b'ui.message-output=channel',
760 ... b'--config', b'cmdserver.message-encodings=cbor',
761 ... b'--config', b'extensions.dbgui=dbgui.py'])
762 ... def prompt(server):
763 ... readchannel(server)
764 ... interactive = [b'--config', b'ui.interactive=True']
765 ... runcommand(server, [b'debugprompt'] + interactive,
766 ... input=stringio(b'5678\n'))
767 ... runcommand(server, [b'debugpromptchoice'] + interactive,
768 ... input=stringio(b'n\n'))
769 *** runcommand debugprompt --config ui.interactive=True
770 message: '\xa3DdataGprompt:GdefaultAyDtypeFprompt'
771 5678
772 *** runcommand debugpromptchoice --config ui.interactive=True
773 message: '\xa4Gchoices\x82\x82AyCYes\x82AnBNoDdataTpromptchoice (y/n)? GdefaultAyDtypeFprompt'
774 1
775
754 bad message encoding:
776 bad message encoding:
755
777
756 $ hg serve --cmdserver pipe --config ui.message-output=channel
778 $ hg serve --cmdserver pipe --config ui.message-output=channel
General Comments 0
You need to be logged in to leave comments. Login now