jp: new confirm method:

it completes `confirmOrQuit` method to ask confirmation without quitting.
This commit is contained in:
Goffi 2020-11-12 14:53:16 +01:00
commit f1ec7b4d43

View file

@ -685,11 +685,15 @@ class Jp(object):
loop.add_reader(sys.stdin, self._read_stdin, stdin_fut)
return await stdin_fut
async def confirm(self, message):
"""Request user to confirm action, return answer as boolean"""
res = await self.ainput(f"{message} (y/N)? ")
return res in ("y", "Y")
async def confirmOrQuit(self, message, cancel_message=_("action cancelled by user")):
"""Request user to confirm action, and quit if he doesn't"""
res = await self.ainput(f"{message} (y/N)? ")
if res not in ("y", "Y"):
confirmed = await self.confirm(message)
if not confirmed:
self.disp(cancel_message)
self.quit(C.EXIT_USER_CANCELLED)