feat: help screen now is scrollable and looks better
This commit is contained in:
@@ -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,12 +34,8 @@ 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")
|
|
||||||
help_table.show_header = True
|
|
||||||
help_table.zebra_stripes = False
|
|
||||||
help_table.cursor_type = "none"
|
|
||||||
bindings = self.app.BINDINGS
|
bindings = self.app.BINDINGS
|
||||||
for binding in bindings:
|
for binding in bindings:
|
||||||
if isinstance(binding, tuple):
|
if isinstance(binding, tuple):
|
||||||
@@ -48,10 +44,11 @@ class HelpScreen(ModalScreen):
|
|||||||
key = binding.key
|
key = binding.key
|
||||||
description = binding.description
|
description = binding.description
|
||||||
key_display = key.replace(
|
key_display = key.replace(
|
||||||
"ctrl+", "^").replace("left", "←").replace("right", "→").replace("space", "Space")
|
"ctrl+", "^").replace("left", "←").replace("right", "→").replace("space", "Space").replace("enter", "Enter")
|
||||||
help_table.add_row(f"[bold]{key_display}[/]", description)
|
with Horizontal(classes="help_row"):
|
||||||
yield help_table
|
yield Static(f"[bold #f9e2af]{key_display}[/]", classes="help_key")
|
||||||
yield Static("Press ? or Escape to close", id="help_footer")
|
yield Static(description, classes="help_action")
|
||||||
|
yield Static("Press [bold #f9e2af]?[/] or [bold #f9e2af]Escape[/] to close", id="help_footer")
|
||||||
|
|
||||||
def action_dismiss(self) -> None:
|
def action_dismiss(self) -> None:
|
||||||
self.dismiss()
|
self.dismiss()
|
||||||
|
|||||||
Reference in New Issue
Block a user