Files
gniza4linux/tui/screens/snapshots.py
shuki 587149f062 Add Python Textual TUI replacing gum-based bash TUI
New tui/ package with 14 screens (main menu, backup, restore, targets,
remotes, snapshots, verify, retention, schedule, logs, settings, wizard),
3 custom widgets (folder picker, confirm dialog, operation log), async
backend wrapper, pure-Python config parser, and TCSS theme.

bin/gniza now launches Textual TUI when available, falls back to gum.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 23:39:48 +02:00

69 lines
2.6 KiB
Python

from textual.app import ComposeResult
from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, Select, DataTable
from textual.containers import Vertical, Horizontal
from textual import work
from tui.config import list_conf_dir
from tui.backend import run_cli
class SnapshotsScreen(Screen):
BINDINGS = [("escape", "go_back", "Back")]
def compose(self) -> ComposeResult:
yield Header()
targets = list_conf_dir("targets.d")
remotes = list_conf_dir("remotes.d")
with Vertical(id="snapshots-screen"):
yield Static("Snapshots", id="screen-title")
if not targets or not remotes:
yield Static("Targets and remotes must be configured to browse snapshots.")
else:
yield Static("Target:")
yield Select([(t, t) for t in targets], id="snap-target", prompt="Select target")
yield Static("Remote:")
yield Select([(r, r) for r in remotes], id="snap-remote", prompt="Select remote")
yield Button("Load Snapshots", id="btn-load", variant="primary")
yield DataTable(id="snap-table")
yield Button("Back", id="btn-back")
yield Footer()
def on_mount(self) -> None:
try:
table = self.query_one("#snap-table", DataTable)
table.add_columns("Snapshot")
except Exception:
pass
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-load":
self._load_snapshots()
@work
async def _load_snapshots(self) -> None:
target_sel = self.query_one("#snap-target", Select)
remote_sel = self.query_one("#snap-remote", Select)
if target_sel.value is Select.BLANK or remote_sel.value is Select.BLANK:
self.notify("Select target and remote first", severity="error")
return
target = str(target_sel.value)
remote = str(remote_sel.value)
rc, stdout, stderr = await run_cli("snapshots", "list", f"--target={target}", f"--remote={remote}")
table = self.query_one("#snap-table", DataTable)
table.clear()
lines = [l.strip() for l in stdout.splitlines() if l.strip() and not l.startswith("===")]
if lines:
for s in lines:
table.add_row(s)
else:
self.notify("No snapshots found", severity="warning")
if stderr:
self.notify(stderr.strip(), severity="error")
def action_go_back(self) -> None:
self.app.pop_screen()