comparison sat_frontends/jp/base.py @ 3409:4ca5bc6b44b6

jp: new `confirm` method: it completes `confirmOrQuit` method to ask confirmation without quitting.
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:16 +0100
parents 19bc03743aeb
children 7b4ae3dbc041
comparison
equal deleted inserted replaced
3408:19bc03743aeb 3409:4ca5bc6b44b6
683 loop = asyncio.get_running_loop() 683 loop = asyncio.get_running_loop()
684 stdin_fut = loop.create_future() 684 stdin_fut = loop.create_future()
685 loop.add_reader(sys.stdin, self._read_stdin, stdin_fut) 685 loop.add_reader(sys.stdin, self._read_stdin, stdin_fut)
686 return await stdin_fut 686 return await stdin_fut
687 687
688 async def confirm(self, message):
689 """Request user to confirm action, return answer as boolean"""
690 res = await self.ainput(f"{message} (y/N)? ")
691 return res in ("y", "Y")
692
688 async def confirmOrQuit(self, message, cancel_message=_("action cancelled by user")): 693 async def confirmOrQuit(self, message, cancel_message=_("action cancelled by user")):
689 """Request user to confirm action, and quit if he doesn't""" 694 """Request user to confirm action, and quit if he doesn't"""
690 695 confirmed = await self.confirm(message)
691 res = await self.ainput(f"{message} (y/N)? ") 696 if not confirmed:
692 if res not in ("y", "Y"):
693 self.disp(cancel_message) 697 self.disp(cancel_message)
694 self.quit(C.EXIT_USER_CANCELLED) 698 self.quit(C.EXIT_USER_CANCELLED)
695 699
696 def quitFromSignal(self, exit_code=0): 700 def quitFromSignal(self, exit_code=0):
697 r"""Same as self.quit, but from a signal handler 701 r"""Same as self.quit, but from a signal handler