Files
luk/maildir_gtd/actions/delete.py
2025-05-05 17:08:01 -06:00

26 lines
1.0 KiB
Python

import asyncio
from textual import work
from textual.widgets import ListView
@work(exclusive=False)
async def delete_current(app) -> None:
app.show_status(f"Deleting message {app.current_message_id}...")
try:
index = app.current_message_index
process = await asyncio.create_subprocess_shell(
f"himalaya message delete {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")
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"Failed to delete message {app.current_message_id}. {stderr.decode()}", "error")
except Exception as e:
app.show_status(f"Error: {e}", "error")