excellent
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user