feat: help screen now is scrollable and looks better

This commit is contained in:
2025-12-16 06:02:22 +01:00
parent 080c731fd7
commit cbf6bff779

View File

@@ -6,7 +6,7 @@ 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 Container from textual.containers import Container, Horizontal, ScrollableContainer
from textual.events import Key from textual.events import Key
from textual.screen import ModalScreen from textual.screen import ModalScreen
from textual.widgets import DataTable, Footer, Header, ProgressBar, Static from textual.widgets import DataTable, Footer, Header, ProgressBar, Static
@@ -34,24 +34,21 @@ class HelpScreen(ModalScreen):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
with Container(id="help_container"): with Container(id="help_container"):
yield Static("Help - Key Bindings", id="help_title") yield Static("Key Bindings", id="help_title")
help_table = DataTable(id="help_table") with ScrollableContainer(id="help_content"):
help_table.add_columns("Key", "Action") bindings = self.app.BINDINGS
help_table.show_header = True for binding in bindings:
help_table.zebra_stripes = False if isinstance(binding, tuple):
help_table.cursor_type = "none" key, action, description = binding
bindings = self.app.BINDINGS else:
for binding in bindings: key = binding.key
if isinstance(binding, tuple): description = binding.description
key, action, description = binding key_display = key.replace(
else: "ctrl+", "^").replace("left", "").replace("right", "").replace("space", "Space").replace("enter", "Enter")
key = binding.key with Horizontal(classes="help_row"):
description = binding.description yield Static(f"[bold #f9e2af]{key_display}[/]", classes="help_key")
key_display = key.replace( yield Static(description, classes="help_action")
"ctrl+", "^").replace("left", "").replace("right", "").replace("space", "Space") yield Static("Press [bold #f9e2af]?[/] or [bold #f9e2af]Escape[/] to close", id="help_footer")
help_table.add_row(f"[bold]{key_display}[/]", description)
yield help_table
yield Static("Press ? or Escape to close", id="help_footer")
def action_dismiss(self) -> None: def action_dismiss(self) -> None:
self.dismiss() self.dismiss()