Open the info screen with Enter and move edit into it
Enter on a guest now opens its info screen, replacing i. The guest table shows Enter as "Info" in the footer. A priority binding at app level would have taken Enter away from buttons and lists in the dialogs, so the hint comes from the table's own binding instead. Editing cores, memory and disk moved from the main screen into the info screen (key e). When the edit dialog closes, you are back on the info screen. Test helpers that pressed i or e on the main screen now go through Enter, because the requirement changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
9ff00e425f
commit
0c3669271c
3 files changed
+82
-22
No files matched your search
+18
-7
@@ -7,6 +7,7 @@ from datetime import datetime
|
||||
from rich.text import Text
|
||||
from textual import work
|
||||
from textual.app import App, ComposeResult, SuspendNotSupported
|
||||
from textual.binding import Binding
|
||||
from textual.containers import Horizontal, Vertical
|
||||
from textual.screen import ModalScreen
|
||||
from textual.widgets import (
|
||||
@@ -381,6 +382,7 @@ class InfoScreen(ModalScreen):
|
||||
("a", "toggle_all", "All backups"),
|
||||
("n", "net", "Edit network"),
|
||||
("u", "undo", "Undo network"),
|
||||
("e", "edit", "Edit resources"),
|
||||
]
|
||||
DEFAULT_CSS = """
|
||||
InfoScreen DataTable { height: auto; max-height: 12; }
|
||||
@@ -543,6 +545,9 @@ class InfoScreen(ModalScreen):
|
||||
else ""
|
||||
)
|
||||
|
||||
def action_edit(self) -> None:
|
||||
self.app.edit_guest(self.guest)
|
||||
|
||||
def action_toggle_all(self) -> None:
|
||||
self.show_all = not self.show_all
|
||||
self._show_backups()
|
||||
@@ -621,14 +626,18 @@ def _job_text(job: dict) -> str:
|
||||
)
|
||||
|
||||
|
||||
class GuestTable(DataTable):
|
||||
"""The guest table; shows its Enter (row selected -> info screen) in the footer."""
|
||||
|
||||
BINDINGS = [Binding("enter", "select_cursor", "Info")] # noqa: RUF012 - Textual idiom
|
||||
|
||||
|
||||
class GuestApp(App):
|
||||
BINDINGS = [ # noqa: RUF012 - Textual idiom
|
||||
("s", "act('start')", "Start"),
|
||||
("S", "act('shutdown')", "Shutdown"),
|
||||
("x", "act('stop')", "Stop"),
|
||||
("r", "act('reboot')", "Reboot"),
|
||||
("e", "edit", "Edit"),
|
||||
("i", "info", "Info"),
|
||||
("t", "shell", "Shell"),
|
||||
("g", "reload", "Refresh"),
|
||||
("c", "context", "Context"),
|
||||
@@ -655,7 +664,7 @@ class GuestApp(App):
|
||||
yield Header()
|
||||
with Vertical(id="guests_section") as section:
|
||||
section.border_title = "Guests"
|
||||
yield DataTable(id="guests", cursor_type="row")
|
||||
yield GuestTable(id="guests", cursor_type="row")
|
||||
yield Footer()
|
||||
|
||||
def on_mount(self) -> None:
|
||||
@@ -841,10 +850,8 @@ class GuestApp(App):
|
||||
lambda ok: self._start_job(guest, name, run) if ok else None,
|
||||
)
|
||||
|
||||
def action_edit(self) -> None:
|
||||
guest = self._selected()
|
||||
if guest is None:
|
||||
return
|
||||
def edit_guest(self, guest: dict) -> None:
|
||||
"""Opened from the info screen (key e)."""
|
||||
if guest["vmid"] in self.busy:
|
||||
self.notify(
|
||||
f"{guest['name']} ({guest['vmid']}) is busy", severity="warning"
|
||||
@@ -857,6 +864,10 @@ class GuestApp(App):
|
||||
if guest is not None:
|
||||
self.push_screen(InfoScreen(guest))
|
||||
|
||||
def on_data_table_row_selected(self, event: DataTable.RowSelected) -> None:
|
||||
if event.data_table.id == "guests": # Enter on a guest row
|
||||
self.action_info()
|
||||
|
||||
def start_backup(self, guest: dict, storage: str) -> None:
|
||||
who = f"{guest['name']} ({guest['vmid']})"
|
||||
if guest["vmid"] in self.busy:
|
||||
|
||||
Reference in new issue
Block a user