excellent
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
import subprocess
|
||||
from textual.widgets import Static
|
||||
from maildir_gtd.actions.next import action_next
|
||||
import asyncio
|
||||
from textual import work
|
||||
from textual.widgets import ListView
|
||||
|
||||
|
||||
def action_delete(app) -> None:
|
||||
"""Delete the current email message."""
|
||||
@work(exclusive=False)
|
||||
async def delete_current(app) -> None:
|
||||
app.show_status(f"Deleting message {app.current_message_id}...")
|
||||
app.query_one("#main_content", Static).loading = True
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["himalaya", "message", "delete", str(app.current_message_id)],
|
||||
capture_output=True,
|
||||
text=True
|
||||
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
|
||||
)
|
||||
if result.returncode == 0:
|
||||
app.query_one("#main_content").loading = False
|
||||
action_next(app) # Automatically show the next message
|
||||
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 + 1
|
||||
app.action_next() # Automatically show the next message
|
||||
else:
|
||||
app.show_status(f"Failed to delete message {app.current_message_id}.", "error")
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user