From f1ec7b4d431ccb0e217ebe7d0c712ce447895e75 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 12 Nov 2020 14:53:16 +0100 Subject: [PATCH] jp: new `confirm` method: it completes `confirmOrQuit` method to ask confirmation without quitting. --- sat_frontends/jp/base.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sat_frontends/jp/base.py b/sat_frontends/jp/base.py index d2c2db0e..b394e12c 100644 --- a/sat_frontends/jp/base.py +++ b/sat_frontends/jp/base.py @@ -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)