# HG changeset patch # User Goffi # Date 1605189196 -3600 # Node ID 4ca5bc6b44b62a52effa7249890c64cb897a0a92 # Parent 19bc03743aeb514c10f212822b62319decc00641 jp: new `confirm` method: it completes `confirmOrQuit` method to ask confirmation without quitting. diff -r 19bc03743aeb -r 4ca5bc6b44b6 sat_frontends/jp/base.py --- a/sat_frontends/jp/base.py Thu Nov 12 14:53:16 2020 +0100 +++ b/sat_frontends/jp/base.py Thu Nov 12 14:53:16 2020 +0100 @@ -685,11 +685,15 @@ 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)