From b62bebc7b8494bd1b57e6e4892fb9000e330df3d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 21 Jan 2026 09:06:50 +0000 Subject: [PATCH] tw.view: new `post_action_cleanup()` method --- mmgen/proto/xmr/tw/view.py | 7 ++----- mmgen/tw/prune.py | 10 +++------- mmgen/tw/view.py | 17 +++++++++++------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/mmgen/proto/xmr/tw/view.py b/mmgen/proto/xmr/tw/view.py index 314c1bce..b96db7ff 100755 --- a/mmgen/proto/xmr/tw/view.py +++ b/mmgen/proto/xmr/tw/view.py @@ -222,8 +222,7 @@ class MoneroTwView: class action(TwView.action): async def a_sync_wallets(self, parent): - from ....util import msg, msg_r, ymsg - from ....tw.view import CUR_HOME, ERASE_ALL + from ....util import msg, ymsg msg('') try: op = xmrwallet_op('sync', parent.cfg, None, None, compat_call=True) @@ -232,11 +231,9 @@ class MoneroTwView: import asyncio ymsg(str(e)) await asyncio.sleep(2) - msg_r(CUR_HOME + ERASE_ALL) return False raise await op.restart_wallet_daemon() await op.main() await parent.get_data() - if parent.scroll: - msg_r(CUR_HOME + ERASE_ALL) + return 'erase' diff --git a/mmgen/tw/prune.py b/mmgen/tw/prune.py index e8fd7e2b..1a4c2a9e 100755 --- a/mmgen/tw/prune.py +++ b/mmgen/tw/prune.py @@ -12,11 +12,10 @@ tw.prune: Tracking wallet pruned listaddresses class for the MMGen suite """ -from ..util import msg, msg_r, rmsg, ymsg +from ..util import msg, rmsg, ymsg from ..color import red, green, gray, yellow from ..obj import ListItemAttr from .addresses import TwAddresses -from .view import CUR_HOME, ERASE_ALL class TwAddressesPrune(TwAddresses): @@ -155,15 +154,12 @@ class TwAddressesPrune(TwAddresses): else: e.tag = True - if parent.scroll: - msg_r(CUR_HOME + ERASE_ALL) + return 'erase' async def a_unprune(self, parent): for addrnum in self.get_addrnums(parent, 'unprune'): parent.disp_data[addrnum-1].tag = False - - if parent.scroll: - msg_r(CUR_HOME + ERASE_ALL) + return 'erase' async def a_clear_prune_list(self, parent): for d in parent.data: diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 09919540..6e381bbf 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -692,11 +692,19 @@ class TwView(MMGenObject, metaclass=AsyncInit): return ur(idx, None) await do_error_msg() + async def post_action_cleanup(self, ret): + if self.scroll and (ret is False or ret in ('redraw', 'erase')): + # error messages could leave screen in messy state, so do complete redraw: + msg_r( + CUR_HOME + ERASE_ALL + ( + '' if ret == 'erase' else + await self.format(display_type='squeezed', interactive=True, scroll=True))) + class action: @enable_echo async def run(self, parent, action_method): - return await action_method(parent) + await parent.post_action_cleanup(await action_method(parent)) async def a_print_detail(self, parent): return await self._print(parent, output_type='detail') @@ -763,6 +771,7 @@ class TwView(MMGenObject, metaclass=AsyncInit): # None: action aborted by user or no action performed # 'redo': user will be re-prompted for item number # 'redraw': action successfully performed, screen will be redrawn + # 'erase': action successfully performed, screen will be erased if usr_ret := await parent.get_idx_from_user(action_method.__name__): ret = await action_method(parent, usr_ret.idx, usr_ret.acct_addr_idx) else: @@ -771,11 +780,7 @@ class TwView(MMGenObject, metaclass=AsyncInit): break await asyncio.sleep(0.5) - if parent.scroll and (ret is False or ret == 'redraw'): - # error messages could leave screen in messy state, so do complete redraw: - msg_r( - CUR_HOME + ERASE_ALL + - await parent.format(display_type='squeezed', interactive=True, scroll=True)) + await parent.post_action_cleanup(ret) async def i_balance_refresh(self, parent, idx, acct_addr_idx=None): if not parent.keypress_confirm(