excellent

This commit is contained in:
Tim Bendt
2025-05-02 01:16:13 -04:00
parent fe22010a68
commit 615aeda3b9
20 changed files with 313 additions and 161 deletions

View File

@@ -1,19 +1,36 @@
from textual.widgets import Static
import subprocess
import asyncio
import logging
from maildir_gtd.actions.next import action_next
def action_archive(app) -> None:
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."""
app.show_status(f"Archiving message {app.current_message_id}...")
try:
result = subprocess.run(
["himalaya", "message", "move", "Archives", str(app.current_message_id)],
capture_output=True,
text=True
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
)
if result.returncode == 0:
action_next(app) # Automatically show the next message
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 + 1
app.action_next() # Automatically show the next message
else:
app.show_status(f"Error archiving message: {result.stderr}", "error")
app.show_status(f"Error archiving message: {stderr.decode()}", "error")
except Exception as e:
app.show_status(f"Error: {e}", "error")