Browse Source

tw.view: new `post_action_cleanup()` method

The MMGen Project 1 week ago
parent
commit
b62bebc7b8
3 changed files with 16 additions and 18 deletions
  1. 2 5
      mmgen/proto/xmr/tw/view.py
  2. 3 7
      mmgen/tw/prune.py
  3. 11 6
      mmgen/tw/view.py

+ 2 - 5
mmgen/proto/xmr/tw/view.py

@@ -222,8 +222,7 @@ class MoneroTwView:
 	class action(TwView.action):
 	class action(TwView.action):
 
 
 		async def a_sync_wallets(self, parent):
 		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('')
 			msg('')
 			try:
 			try:
 				op = xmrwallet_op('sync', parent.cfg, None, None, compat_call=True)
 				op = xmrwallet_op('sync', parent.cfg, None, None, compat_call=True)
@@ -232,11 +231,9 @@ class MoneroTwView:
 					import asyncio
 					import asyncio
 					ymsg(str(e))
 					ymsg(str(e))
 					await asyncio.sleep(2)
 					await asyncio.sleep(2)
-					msg_r(CUR_HOME + ERASE_ALL)
 					return False
 					return False
 				raise
 				raise
 			await op.restart_wallet_daemon()
 			await op.restart_wallet_daemon()
 			await op.main()
 			await op.main()
 			await parent.get_data()
 			await parent.get_data()
-			if parent.scroll:
-				msg_r(CUR_HOME + ERASE_ALL)
+			return 'erase'

+ 3 - 7
mmgen/tw/prune.py

@@ -12,11 +12,10 @@
 tw.prune: Tracking wallet pruned listaddresses class for the MMGen suite
 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 ..color import red, green, gray, yellow
 from ..obj import ListItemAttr
 from ..obj import ListItemAttr
 from .addresses import TwAddresses
 from .addresses import TwAddresses
-from .view import CUR_HOME, ERASE_ALL
 
 
 class TwAddressesPrune(TwAddresses):
 class TwAddressesPrune(TwAddresses):
 
 
@@ -155,15 +154,12 @@ class TwAddressesPrune(TwAddresses):
 				else:
 				else:
 					e.tag = True
 					e.tag = True
 
 
-			if parent.scroll:
-				msg_r(CUR_HOME + ERASE_ALL)
+			return 'erase'
 
 
 		async def a_unprune(self, parent):
 		async def a_unprune(self, parent):
 			for addrnum in self.get_addrnums(parent, 'unprune'):
 			for addrnum in self.get_addrnums(parent, 'unprune'):
 				parent.disp_data[addrnum-1].tag = False
 				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):
 		async def a_clear_prune_list(self, parent):
 			for d in parent.data:
 			for d in parent.data:

+ 11 - 6
mmgen/tw/view.py

@@ -692,11 +692,19 @@ class TwView(MMGenObject, metaclass=AsyncInit):
 					return ur(idx, None)
 					return ur(idx, None)
 			await do_error_msg()
 			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:
 	class action:
 
 
 		@enable_echo
 		@enable_echo
 		async def run(self, parent, action_method):
 		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):
 		async def a_print_detail(self, parent):
 			return await self._print(parent, output_type='detail')
 			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
 				#  None:   action aborted by user or no action performed
 				#  'redo': user will be re-prompted for item number
 				#  'redo': user will be re-prompted for item number
 				#  'redraw': action successfully performed, screen will be redrawn
 				#  '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__):
 				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)
 					ret = await action_method(parent, usr_ret.idx, usr_ret.acct_addr_idx)
 				else:
 				else:
@@ -771,11 +780,7 @@ class TwView(MMGenObject, metaclass=AsyncInit):
 					break
 					break
 				await asyncio.sleep(0.5)
 				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):
 		async def i_balance_refresh(self, parent, idx, acct_addr_idx=None):
 			if not parent.keypress_confirm(
 			if not parent.keypress_confirm(