working good state

This commit is contained in:
Tim Bendt
2025-05-01 11:59:28 -04:00
parent 7a5b911414
commit 1f75a03553
20 changed files with 173 additions and 78 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -12,9 +12,8 @@ def action_archive(app) -> None:
text=True
)
if result.returncode == 0:
app.query_one("#main_content", Static).update(f"Message {app.current_message_id} archived.")
action_next(app) # Automatically show the next message
else:
app.query_one("#main_content", Static).update(f"Failed to archive message {app.current_message_id}.")
app.show_status(f"Error archiving message: {result.stderr}", "error")
except Exception as e:
app.query_one("#main_content", Static).update(f"Error: {e}")
app.show_status(f"Error: {e}", "error")

View File

@@ -14,10 +14,9 @@ def action_delete(app) -> None:
text=True
)
if result.returncode == 0:
app.query_one("#main_content", Static).loading = False
app.query_one("#main_content", Static).update(f"Message {app.current_message_id} deleted.")
app.query_one("#main_content").loading = False
action_next(app) # Automatically show the next message
else:
app.query_one("#main_content", Static).update(f"Failed to delete message {app.current_message_id}.")
app.show_status(f"Failed to delete message {app.current_message_id}.", "error")
except Exception as e:
app.query_one("#main_content", Static).update(f"Error: {e}")
app.show_status(f"Error: {e}", "error")

View File

@@ -0,0 +1,23 @@
import subprocess
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)
app.current_message_id = ids[0]
app.show_message(app.current_message_id)
return
else:
app.show_status("Failed to fetch envelope list.", severity="error")
except Exception as e:
app.show_status(f"Error: {e}", severity="error")

View File

@@ -15,7 +15,7 @@ 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"],
["himalaya", "envelope", "list", "-o", "json", "-s", "9999"],
capture_output=True,
text=True
)
@@ -23,13 +23,13 @@ def action_next(app) -> None:
import json
envelopes = json.loads(result.stdout)
ids = sorted(int(envelope['id']) for envelope in envelopes)
for index, envelope_id in enumerate(ids):
for envelope_id in ids:
if envelope_id > int(app.current_message_id):
app.show_message(envelope_id)
return
app.show_status("No newer messages found.", severity="warning")
app.show_message(envelopes[-1]['id']) # Automatically show the previous message
app.action_newest()
else:
app.show_status("Failed to fetch envelope list.", severity="error")
except Exception as e:

View File

@@ -0,0 +1,23 @@
import subprocess
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))
app.current_message_id = ids[0]
app.show_message(app.current_message_id)
return
else:
app.show_status("Failed to fetch envelope list.", severity="error")
except Exception as e:
app.show_status(f"Error: {e}", severity="error")

View File

@@ -1,11 +1,11 @@
from textual.widgets import Static
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"],
["himalaya", "envelope", "list", "-o", "json", "-s", "9999"],
capture_output=True,
text=True
)
@@ -19,6 +19,7 @@ def action_previous(app) -> None:
app.show_message(app.current_message_id)
return
app.show_status("No older messages found.", severity="warning")
app.action_oldest()
else:
app.show_status("Failed to fetch envelope list.", severity="error")
except Exception as e:

View File

@@ -1,23 +1,14 @@
from textual.widgets import Static
from rich.markdown import Markdown
import logging
import subprocess
from textual.logging import TextualHandler
logging.basicConfig(
level="NOTSET",
handlers=[TextualHandler()],
)
def show_message(app, message_id: int) -> None:
"""Fetch and display the email message by ID."""
app.current_message_id = message_id
app.query_one("#main_content", Static).loading = True
try:
result = subprocess.run(
["himalaya", "message", "read", str(message_id)],
capture_output=True,
text=True
)
if result.returncode == 0:
# Render the email content as Markdown
markdown_content = Markdown(result.stdout, justify=True)
app.query_one("#main_content", Static).loading = False
app.query_one("#main_content", Static).update(markdown_content)
else:
app.query_one("#main_content", Static).update(f"Failed to fetch message {message_id}.")
except Exception as e:
app.query_one("#main_content", Static).update(f"Error: {e}")
logging.info("Showing message ID: " + str(message_id))