Show cache status in the TUI

This commit is contained in:
SirBlob committed 2026-11-01 22:58:56 -05:00
1 parent dfe3955604
commit 7e23fdcd8e
2 files changed
+27 -1

No files matched your search

+11 -1
View File
@@ -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())
+16
View File
@@ -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])