From 7e23fdcd8eccff9c00a45d2bee99e9190feb4aac Mon Sep 17 00:00:00 2001 From: SirBlob Date: Sun, 1 Nov 2026 22:58:56 -0500 Subject: [PATCH] Show cache status in the TUI --- tools/content/tui/books_pane.py | 12 +++++++++++- tools/content/tui/cache_indicator.py | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tools/content/tui/cache_indicator.py diff --git a/tools/content/tui/books_pane.py b/tools/content/tui/books_pane.py index d26d386..5b6d4e2 100644 --- a/tools/content/tui/books_pane.py +++ b/tools/content/tui/books_pane.py @@ -7,9 +7,11 @@ from textual.binding import Binding from textual.containers import Horizontal, VerticalScroll from textual.widgets import DataTable, Static +import book_cache import books import goodreads import goodreads_series +from tui.cache_indicator import cache_state, cache_text from tui.content_pane import ContentPane from tui.dialogs import ConfirmDialog, FormDialog, FormField from tui.series_picker import SeriesPicker @@ -27,6 +29,7 @@ def book_details(book: dict) -> str: ("Published", book.get("published")), ("Genres", ", ".join(book.get("genres") or [])), ("Added", book.get("added")), + ("Cache", book_cache_state(book)), ] lines = [f"[b]{escape(book.get('title', ''))}[/b]", escape(", ".join(book.get("authors") or [])), ""] lines += [f"[dim]{label:<12}[/dim]{escape(str(value))}" for label, value in rows if value] @@ -36,6 +39,11 @@ def book_details(book: dict) -> str: return "\n".join(lines) +def book_cache_state(book: dict) -> str: + has_details = bool(book.get("authors")) or bool(book.get("description")) + return cache_state(has_details, book_cache.is_local_cover(book.get("cover"))) + + class BooksPane(ContentPane): BINDINGS = [ Binding("a", "add", "Add"), @@ -63,6 +71,7 @@ class BooksPane(ContentPane): table.add_column("Rating", key="rating") table.add_column("Title", key="title") table.add_column("Authors", key="authors") + table.add_column("Cache", key="cache") self.reload() def book_by_id(self, identifier: str | None) -> dict | None: @@ -75,7 +84,8 @@ class BooksPane(ContentPane): sorted_books = sorted(books.load_books(), key=lambda book: (shelf_order.get(book.get("shelf"), 99), -(book.get("rating") or -1))) for book in sorted_books: rating = f"{book['rating']}/10" if book.get("rating") is not None else "-" - table.add_row(book.get("shelf", ""), rating, book.get("title", ""), ", ".join(book.get("authors") or []), key=book["goodreadsId"]) + authors = ", ".join(book.get("authors") or []) + table.add_row(book.get("shelf", ""), rating, book.get("title", ""), authors, cache_text(book_cache_state(book)), key=book["goodreadsId"]) self.restore_cursor(focus_key) self.show_details(self.selected_key()) diff --git a/tools/content/tui/cache_indicator.py b/tools/content/tui/cache_indicator.py new file mode 100644 index 0000000..bf7b3ec --- /dev/null +++ b/tools/content/tui/cache_indicator.py @@ -0,0 +1,16 @@ +from rich.text import Text + +CACHED = "cached" +PARTIAL = "partial" +MISSING = "missing" +STATE_STYLES = {CACHED: "green", PARTIAL: "yellow", MISSING: "red"} + + +def cache_state(has_details: bool, has_local_image: bool) -> str: + if not has_details: + return MISSING + return CACHED if has_local_image else PARTIAL + + +def cache_text(state: str) -> Text: + return Text(state, style=STATE_STYLES[state])