Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- 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)