feat: replace footer with custom top bar
This commit is contained in:
@@ -6,10 +6,12 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
from textual import work
|
from textual import work
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.containers import Horizontal
|
||||||
from textual.events import Key, Resize
|
from textual.events import Key, Resize
|
||||||
from textual.widgets import DataTable, Footer, Header, ProgressBar, Static
|
from textual.widgets import DataTable, ProgressBar, Static
|
||||||
from textual.worker import get_current_worker
|
from textual.worker import get_current_worker
|
||||||
|
|
||||||
|
from . import __version__
|
||||||
from .constants import (
|
from .constants import (
|
||||||
PROGRESS_COLUMN_INDEX,
|
PROGRESS_COLUMN_INDEX,
|
||||||
SEEK_SECONDS,
|
SEEK_SECONDS,
|
||||||
@@ -77,7 +79,12 @@ class Auditui(App):
|
|||||||
self.progress_column_index = PROGRESS_COLUMN_INDEX
|
self.progress_column_index = PROGRESS_COLUMN_INDEX
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header()
|
yield Horizontal(
|
||||||
|
Static("? Help", id="top_left"),
|
||||||
|
Static(f"Auditui v{__version__}", id="top_center"),
|
||||||
|
Static("q Quit", id="top_right"),
|
||||||
|
id="top_bar",
|
||||||
|
)
|
||||||
yield Static("Loading...", id="status")
|
yield Static("Loading...", id="status")
|
||||||
table: DataTable = DataTable()
|
table: DataTable = DataTable()
|
||||||
table.zebra_stripes = True
|
table.zebra_stripes = True
|
||||||
@@ -85,7 +92,6 @@ class Auditui(App):
|
|||||||
yield table
|
yield table
|
||||||
yield Static("", id="progress_info")
|
yield Static("", id="progress_info")
|
||||||
yield ProgressBar(id="progress_bar", show_eta=False, show_percentage=False, total=100)
|
yield ProgressBar(id="progress_bar", show_eta=False, show_percentage=False, total=100)
|
||||||
yield Footer(show_command_palette=False)
|
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
"""Initialize the table and start fetching library data."""
|
"""Initialize the table and start fetching library data."""
|
||||||
@@ -161,6 +167,7 @@ class Auditui(App):
|
|||||||
def update_status(self, message: str) -> None:
|
def update_status(self, message: str) -> None:
|
||||||
"""Update the status message in the UI."""
|
"""Update the status message in the UI."""
|
||||||
status = self.query_one("#status", Static)
|
status = self.query_one("#status", Static)
|
||||||
|
status.display = True
|
||||||
status.update(message)
|
status.update(message)
|
||||||
|
|
||||||
def _apply_column_widths(self, table: DataTable) -> None:
|
def _apply_column_widths(self, table: DataTable) -> None:
|
||||||
@@ -171,19 +178,19 @@ class Auditui(App):
|
|||||||
column_keys = list(table.columns.keys())
|
column_keys = list(table.columns.keys())
|
||||||
ratios = [ratio for _, ratio in TABLE_COLUMN_DEFS]
|
ratios = [ratio for _, ratio in TABLE_COLUMN_DEFS]
|
||||||
total_ratio = sum(ratios) or len(column_keys)
|
total_ratio = sum(ratios) or len(column_keys)
|
||||||
available_width = table.size.width - 2 - (len(column_keys) - 1)
|
content_width = table.scrollable_content_region.width
|
||||||
|
available_width = content_width
|
||||||
if available_width <= 0:
|
if available_width <= 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
remaining = available_width
|
|
||||||
widths: list[int] = []
|
widths: list[int] = []
|
||||||
for ratio in ratios:
|
for ratio in ratios:
|
||||||
width = max(1, (available_width * ratio) // total_ratio)
|
width = max(1, (available_width * ratio) // total_ratio)
|
||||||
widths.append(width)
|
widths.append(width)
|
||||||
remaining -= width
|
|
||||||
|
|
||||||
if remaining > 0:
|
remainder = available_width - sum(widths)
|
||||||
widths[0] += remaining
|
for i in range(remainder):
|
||||||
|
widths[i % len(widths)] += 1
|
||||||
|
|
||||||
for column_key, width in zip(column_keys, widths):
|
for column_key, width in zip(column_keys, widths):
|
||||||
column = table.columns[column_key]
|
column = table.columns[column_key]
|
||||||
@@ -235,8 +242,8 @@ class Auditui(App):
|
|||||||
progress, downloaded, key=title)
|
progress, downloaded, key=title)
|
||||||
|
|
||||||
self.current_items = items
|
self.current_items = items
|
||||||
mode = "all" if self.show_all_mode else "unfinished"
|
status = self.query_one("#status", Static)
|
||||||
self.update_status(f"Showing {len(items)} books ({mode})")
|
status.display = False
|
||||||
|
|
||||||
def _refresh_table(self) -> None:
|
def _refresh_table(self) -> None:
|
||||||
"""Refresh the table with current items."""
|
"""Refresh the table with current items."""
|
||||||
@@ -392,8 +399,7 @@ class Auditui(App):
|
|||||||
is_currently_finished = self.library_client.is_finished(selected_item)
|
is_currently_finished = self.library_client.is_finished(selected_item)
|
||||||
|
|
||||||
if is_currently_finished:
|
if is_currently_finished:
|
||||||
success = self.library_client.mark_as_unfinished(
|
success = self.library_client.mark_as_unfinished(asin)
|
||||||
asin, selected_item)
|
|
||||||
message = "Marked as unfinished" if success else "Failed to mark as unfinished"
|
message = "Marked as unfinished" if success else "Failed to mark as unfinished"
|
||||||
else:
|
else:
|
||||||
success = self.library_client.mark_as_finished(asin, selected_item)
|
success = self.library_client.mark_as_finished(asin, selected_item)
|
||||||
|
|||||||
Reference in New Issue
Block a user