import asyncio import logging from textual import work from textual.logging import TextualHandler from textual.widgets import ListView logging.basicConfig( level="NOTSET", handlers=[TextualHandler()], ) @work(exclusive=False) async def archive_current(app) -> None: """Archive the current email message.""" try: index = app.current_message_index logging.info("Archiving message ID: " + str(app.current_message_id)) process = await asyncio.create_subprocess_shell( f"himalaya message move Archives {app.current_message_id}", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) stdout, stderr = await process.communicate() # app.reload_needed = True app.show_status(f"{stdout.decode()}", "info") logging.info(stdout.decode()) if process.returncode == 0: await app.query_one(ListView).pop(index) app.query_one(ListView).index = index # app.action_next() # Automatically show the next message else: app.show_status(f"Error archiving message: {stderr.decode()}", "error") except Exception as e: app.show_status(f"Error: {e}", "error")