diff --git a/src/hosts/tui/app.py b/src/hosts/tui/app.py index deb5b1b..c903be0 100644 --- a/src/hosts/tui/app.py +++ b/src/hosts/tui/app.py @@ -137,21 +137,36 @@ class HostsManagerApp(App): self.update_status(f"❌ Error loading hosts file: {e}") def _setup_footer(self) -> None: - """Setup the footer with initial content.""" + """Setup the footer with initial content based on keybindings.""" try: footer = self.query_one("#custom-footer", CustomFooter) - # Left section - common actions - footer.add_right_item("^e: Edit Mode") - footer.add_right_item("c: Config") - footer.add_right_item("?: Help") - footer.add_right_item("q: Quit") + # Clear existing items + footer.clear_left_items() + footer.clear_right_items() - # Right section - sort and edit actions - footer.add_left_item("i: Sort IP") - footer.add_left_item("n: Sort Host") - footer.add_left_item("r: Reload") - + # Process keybindings and add to appropriate sections + for binding in self.BINDINGS: + # Only show bindings marked with show=True + 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 self._update_footer_status() @@ -190,11 +205,6 @@ class HostsManagerApp(App): pass # 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 self._update_footer_status() diff --git a/src/hosts/tui/keybindings.py b/src/hosts/tui/keybindings.py index 5768fe4..c84d63d 100644 --- a/src/hosts/tui/keybindings.py +++ b/src/hosts/tui/keybindings.py @@ -9,17 +9,26 @@ from textual.binding import Binding # Key bindings for the hosts manager application 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("r", "reload", "Reload hosts file", show=True, id="right:reload"), - Binding("question_mark", "help", "Show help", show=True, key_display="?", id="right:help"), - Binding("i", "sort_by_ip", "Sort by IP address", show=True, id="left:quit"), - Binding("n", "sort_by_hostname", "Sort by hostname", show=True, id="left:quit"), - 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("r", "reload", "Reload hosts file", show=False), + Binding("i", "sort_by_ip", "Sort by IP address", show=False), + Binding( + "h", "sort_by_hostname", "Sort by hostname", 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+down", "move_entry_down", "Move entry down", show=False),