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")

View File

@@ -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")

View File

@@ -1,18 +1,13 @@
import subprocess
import asyncio
def action_newest(app) -> None:
async def action_newest(app) -> None:
"""Show the previous email message by finding the next lower ID from the list of envelope IDs."""
try:
result = subprocess.run(
["himalaya", "envelope", "list", "-o", "json", "-s", "9999"],
capture_output=True,
text=True
)
if result.returncode == 0:
import json
envelopes = json.loads(result.stdout)
ids = sorted((int(envelope['id']) for envelope in envelopes), reverse=True)
if (app.reload_needed):
await app.action_fetch_list()
ids = sorted((int(envelope['id']) for envelope in app.all_envelopes), reverse=True)
app.current_message_id = ids[0]
app.show_message(app.current_message_id)
return

View File

@@ -9,20 +9,14 @@ from textual.reactive import Reactive
from textual.binding import Binding
from textual.timer import Timer
from textual.containers import ScrollableContainer, Horizontal, Vertical, Grid
import subprocess
import asyncio
def action_next(app) -> None:
async def action_next(app) -> None:
"""Show the next email message by finding the next higher ID from the list of envelope IDs."""
try:
result = subprocess.run(
["himalaya", "envelope", "list", "-o", "json", "-s", "9999"],
capture_output=True,
text=True
)
if result.returncode == 0:
import json
envelopes = json.loads(result.stdout)
ids = sorted(int(envelope['id']) for envelope in envelopes)
if (app.reload_needed):
app.action_fetch_list()
ids = sorted(int(envelope['id']) for envelope in app.all_envelopes)
for envelope_id in ids:
if envelope_id > int(app.current_message_id):
app.show_message(envelope_id)

View File

@@ -1,18 +1,13 @@
import subprocess
import asyncio
def action_oldest(app) -> None:
"""Show the previous email message by finding the next lower ID from the list of envelope IDs."""
try:
result = subprocess.run(
["himalaya", "envelope", "list", "-o", "json", "-s", "9999"],
capture_output=True,
text=True
)
if result.returncode == 0:
import json
envelopes = json.loads(result.stdout)
ids = sorted((int(envelope['id']) for envelope in envelopes))
if (app.reload_needed):
app.action_fetch_list()
ids = sorted((int(envelope['id']) for envelope in app.all_envelopes))
app.current_message_id = ids[0]
app.show_message(app.current_message_id)
return

View File

@@ -6,9 +6,9 @@ def action_open(app) -> None:
def check_id(message_id: str) -> bool:
try:
int(message_id)
app.current_message_id = message_id
app.show_message(app.current_message_id)
app.show_message(message_id)
except ValueError:
app.bell()
app.show_status("Invalid message ID. Please enter an integer.", severity="error")
return True
return False

View File

@@ -4,15 +4,10 @@ import subprocess
def action_previous(app) -> None:
"""Show the previous email message by finding the next lower ID from the list of envelope IDs."""
try:
result = subprocess.run(
["himalaya", "envelope", "list", "-o", "json", "-s", "9999"],
capture_output=True,
text=True
)
if result.returncode == 0:
import json
envelopes = json.loads(result.stdout)
ids = sorted((int(envelope['id']) for envelope in envelopes), reverse=True)
if (app.reload_needed):
app.action_fetch_list()
ids = sorted((int(envelope['id']) for envelope in app.all_envelopes), reverse=True)
for envelope_id in ids:
if envelope_id < int(app.current_message_id):
app.current_message_id = envelope_id

View File

@@ -10,5 +10,5 @@ logging.basicConfig(
def show_message(app, message_id: int) -> None:
"""Fetch and display the email message by ID."""
app.current_message_id = message_id
logging.info("Showing message ID: " + str(message_id))
app.current_message_id = message_id