basic nav status counts
This commit is contained in:
@@ -5,7 +5,8 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
import logging
|
||||
from typing import Iterable
|
||||
from textual import on
|
||||
from textual.app import App, ComposeResult, SystemCommand
|
||||
from textual.widget import Widget
|
||||
from textual.app import App, ComposeResult, SystemCommand, RenderResult
|
||||
from textual.logging import TextualHandler
|
||||
from textual.screen import Screen
|
||||
from textual.widgets import Header, Footer, Static, Label, Input, Button
|
||||
@@ -27,13 +28,29 @@ logging.basicConfig(
|
||||
handlers=[TextualHandler()],
|
||||
)
|
||||
|
||||
class Hello(Widget):
|
||||
"""Display a greeting."""
|
||||
|
||||
def render(self) -> RenderResult:
|
||||
return "Hello, [b]World[/b]!"
|
||||
|
||||
class StatusTitle(Static):
|
||||
total_messages: Reactive[int] = Reactive(0)
|
||||
current_message_index: Reactive[int] = Reactive(0)
|
||||
current_message_id: Reactive[int] = Reactive(1)
|
||||
|
||||
def render(self) -> RenderResult:
|
||||
return f"Inbox Message ID: {self.current_message_id} | [b]{self.current_message_index}[/b]/{self.total_messages}"
|
||||
|
||||
|
||||
|
||||
|
||||
class EmailViewerApp(App):
|
||||
"""A simple email viewer app using the Himalaya CLI."""
|
||||
title = "Maildir GTD Reader"
|
||||
CSS_PATH = "email_viewer.tcss" # Optional: For styling
|
||||
|
||||
current_message_id: Reactive[int] = Reactive(1)
|
||||
CSS_PATH = "email_viewer.tcss"
|
||||
|
||||
|
||||
def get_system_commands(self, screen: Screen) -> Iterable[SystemCommand]:
|
||||
yield from super().get_system_commands(screen)
|
||||
@@ -64,12 +81,43 @@ class EmailViewerApp(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
"""Create child widgets for the app."""
|
||||
yield Header(show_clock=True)
|
||||
yield Footer(Label("[n] Next | [p] Previous | [d] Delete | [a] Archive | [o] Open | [q] Quit | [c] Create Task"))
|
||||
yield ScrollableContainer(Static(Label("Email Viewer App"), id="main_content"))
|
||||
yield StatusTitle().data_bind(EmailViewerApp.current_message_id)
|
||||
yield ScrollableContainer(Static(Label("Loading Email Viewer App"), id="main_content"))
|
||||
yield Footer()
|
||||
|
||||
def watch_current_message_id(self, message_id: int, old_message_id: int) -> None:
|
||||
"""Called when the current message ID changes."""
|
||||
if (message_id == old_message_id):
|
||||
return
|
||||
# self.notify("Current message ID changed", title="Status", severity="information")
|
||||
logging.info(f"Current message ID changed to {message_id}")
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["himalaya", "envelope", "list", "-o", "json"],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
if result.returncode == 0:
|
||||
import json
|
||||
envelopes = json.loads(result.stdout)
|
||||
if envelopes:
|
||||
status = self.query_one(StatusTitle)
|
||||
status.total_messages = len(envelopes) # Get the first envelope's ID
|
||||
status.current_message_index = next(
|
||||
(index + 1 for index, envelope in enumerate(envelopes) if int(envelope['id']) == message_id),
|
||||
0 # Default to 0 if no match is found
|
||||
)
|
||||
else:
|
||||
self.query_one("#main_content", Static).update("Failed to fetch the most recent message ID.")
|
||||
except Exception as e:
|
||||
self.query_one("#main_content", Static).update(f"Error: {e}")
|
||||
|
||||
|
||||
def on_mount(self) -> None:
|
||||
"""Called when the app is mounted."""
|
||||
self.alert_timer: Timer | None = None # Timer to throttle alerts
|
||||
self.theme = "monokai"
|
||||
|
||||
# self.watch(self.query_one(StatusTitle), "current_message_id", update_progress)
|
||||
# Fetch the ID of the most recent message using the Himalaya CLI
|
||||
try:
|
||||
result = subprocess.run(
|
||||
@@ -81,7 +129,7 @@ class EmailViewerApp(App):
|
||||
import json
|
||||
envelopes = json.loads(result.stdout)
|
||||
if envelopes:
|
||||
self.current_message_id = int(envelopes[0]['id']) # Get the first envelope's ID
|
||||
self.current_message_id = int(envelopes[0]['id'])
|
||||
else:
|
||||
self.query_one("#main_content", Static).update("Failed to fetch the most recent message ID.")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user