jp: new confirm method:
it completes `confirmOrQuit` method to ask confirmation without quitting.
This commit is contained in:
parent
ed39d5340d
commit
f1ec7b4d43
1 changed files with 7 additions and 3 deletions
|
|
@ -685,11 +685,15 @@ class Jp(object):
|
||||||
loop.add_reader(sys.stdin, self._read_stdin, stdin_fut)
|
loop.add_reader(sys.stdin, self._read_stdin, stdin_fut)
|
||||||
return await 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")):
|
async def confirmOrQuit(self, message, cancel_message=_("action cancelled by user")):
|
||||||
"""Request user to confirm action, and quit if he doesn't"""
|
"""Request user to confirm action, and quit if he doesn't"""
|
||||||
|
confirmed = await self.confirm(message)
|
||||||
res = await self.ainput(f"{message} (y/N)? ")
|
if not confirmed:
|
||||||
if res not in ("y", "Y"):
|
|
||||||
self.disp(cancel_message)
|
self.disp(cancel_message)
|
||||||
self.quit(C.EXIT_USER_CANCELLED)
|
self.quit(C.EXIT_USER_CANCELLED)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue