Refactor footer setup: enhance footer item management based on keybindings for improved usability and clarity.

This commit is contained in:
Philip Henning 2025-08-16 22:23:39 +02:00
parent 49dd015d53
commit 3f0892fb7b
2 changed files with 45 additions and 26 deletions

View file

@ -137,21 +137,36 @@ class HostsManagerApp(App):
self.update_status(f"❌ Error loading hosts file: {e}") self.update_status(f"❌ Error loading hosts file: {e}")
def _setup_footer(self) -> None: def _setup_footer(self) -> None:
"""Setup the footer with initial content.""" """Setup the footer with initial content based on keybindings."""
try: try:
footer = self.query_one("#custom-footer", CustomFooter) footer = self.query_one("#custom-footer", CustomFooter)
# Left section - common actions # Clear existing items
footer.add_right_item("^e: Edit Mode") footer.clear_left_items()
footer.add_right_item("c: Config") footer.clear_right_items()
footer.add_right_item("?: Help")
footer.add_right_item("q: Quit")
# Right section - sort and edit actions # Process keybindings and add to appropriate sections
footer.add_left_item("i: Sort IP") for binding in self.BINDINGS:
footer.add_left_item("n: Sort Host") # Only show bindings marked with show=True
footer.add_left_item("r: Reload") if hasattr(binding, "show") and binding.show:
# Get the display key
key_display = getattr(binding, "key_display", None) or binding.key
# Get the description
description = binding.description or binding.action
# Format the item
item = f"{key_display}: {description}"
# Determine positioning from id attribute
binding_id = getattr(binding, "id", None)
if binding_id and binding_id.startswith("left:"):
footer.add_left_item(item)
elif binding_id and binding_id.startswith("right:"):
footer.add_right_item(item)
else:
# Default to right if no specific positioning
footer.add_right_item(item)
# Status section will be updated by update_status # Status section will be updated by update_status
self._update_footer_status() self._update_footer_status()
@ -190,11 +205,6 @@ class HostsManagerApp(App):
pass pass
# Always update the header subtitle with current status # Always update the header subtitle with current status
mode = "Edit mode" if self.edit_mode else "Read-only mode"
entry_count = len(self.hosts_file.entries)
active_count = len(self.hosts_file.get_active_entries())
# Format: "29 entries (6 active) | Read-only mode"
# Update the footer status # Update the footer status
self._update_footer_status() self._update_footer_status()

View file

@ -9,17 +9,26 @@ from textual.binding import Binding
# Key bindings for the hosts manager application # Key bindings for the hosts manager application
HOSTS_MANAGER_BINDINGS = [ HOSTS_MANAGER_BINDINGS = [
Binding("a", "add_entry", "Add new entry", show=True, id="left:add_entry"),
Binding("d", "delete_entry", "Delete entry", show=True, id="left:delete_entry"),
Binding("e", "edit_entry", "Edit entry", show=True, id="left:edit_entry"),
Binding("space", "toggle_entry", "Toggle active/inactive", show=True, id="left:toggle_entry"),
Binding("ctrl+e", "toggle_edit_mode", "Toggle edit mode", show=True, id="left:toggle_edit_mode"),
Binding("c", "config", "Configuration", show=True, id="right:config"),
Binding(
"question_mark",
"help",
"Show help",
show=True,
key_display="?",
id="right:help",
),
Binding("q", "quit", "Quit", show=True, id="right:quit"), Binding("q", "quit", "Quit", show=True, id="right:quit"),
Binding("r", "reload", "Reload hosts file", show=True, id="right:reload"), Binding("r", "reload", "Reload hosts file", show=False),
Binding("question_mark", "help", "Show help", show=True, key_display="?", id="right:help"), Binding("i", "sort_by_ip", "Sort by IP address", show=False),
Binding("i", "sort_by_ip", "Sort by IP address", show=True, id="left:quit"), Binding(
Binding("n", "sort_by_hostname", "Sort by hostname", show=True, id="left:quit"), "h", "sort_by_hostname", "Sort by hostname", show=False
Binding("c", "config", "Configuration", show=True), ),
Binding("ctrl+e", "toggle_edit_mode", "Toggle edit mode", show=True),
Binding("a", "add_entry", "Add new entry", show=False),
Binding("d", "delete_entry", "Delete entry", show=False),
Binding("e", "edit_entry", "Edit entry", show=False),
Binding("space", "toggle_entry", "Toggle active/inactive", show=False),
Binding("ctrl+s", "save_file", "Save hosts file", show=False), Binding("ctrl+s", "save_file", "Save hosts file", show=False),
Binding("shift+up", "move_entry_up", "Move entry up", show=False), Binding("shift+up", "move_entry_up", "Move entry up", show=False),
Binding("shift+down", "move_entry_down", "Move entry down", show=False), Binding("shift+down", "move_entry_down", "Move entry down", show=False),