feat: redesign help as two-column cheat sheet
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
"""UI components for the Auditui application."""
|
"""UI components for the Auditui application."""
|
||||||
|
|
||||||
from textual.app import ComposeResult
|
from textual.app import ComposeResult
|
||||||
from textual.containers import Container, Horizontal, ScrollableContainer
|
from textual.containers import Container, Horizontal
|
||||||
from textual.screen import ModalScreen
|
from textual.screen import ModalScreen
|
||||||
from textual.widgets import Static
|
from textual.widgets import Label, ListItem, ListView, Static
|
||||||
|
|
||||||
|
|
||||||
KEY_DISPLAY_MAP = {
|
KEY_DISPLAY_MAP = {
|
||||||
@@ -17,6 +17,7 @@ KEY_DISPLAY_MAP = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KEY_COLOR = "#f9e2af"
|
KEY_COLOR = "#f9e2af"
|
||||||
|
DESC_COLOR = "#cdd6f4"
|
||||||
|
|
||||||
|
|
||||||
class HelpScreen(ModalScreen):
|
class HelpScreen(ModalScreen):
|
||||||
@@ -42,17 +43,34 @@ class HelpScreen(ModalScreen):
|
|||||||
description = binding.description
|
description = binding.description
|
||||||
return key, description
|
return key, description
|
||||||
|
|
||||||
|
def _make_item(self, binding: tuple | object) -> ListItem:
|
||||||
|
"""Create a ListItem for a single binding."""
|
||||||
|
key, description = self._parse_binding(binding)
|
||||||
|
key_display = self._format_key_display(key)
|
||||||
|
text = f"[bold {KEY_COLOR}]{key_display:>12}[/] [{DESC_COLOR}]{description}[/]"
|
||||||
|
return ListItem(Label(text))
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
|
bindings = list(self.app.BINDINGS)
|
||||||
|
mid = (len(bindings) + 1) // 2
|
||||||
|
left_bindings = bindings[:mid]
|
||||||
|
right_bindings = bindings[mid:]
|
||||||
|
|
||||||
with Container(id="help_container"):
|
with Container(id="help_container"):
|
||||||
yield Static("Key Bindings", id="help_title")
|
yield Static("Key Bindings", id="help_title")
|
||||||
with ScrollableContainer(id="help_content"):
|
with Horizontal(id="help_content"):
|
||||||
for binding in self.app.BINDINGS:
|
yield ListView(
|
||||||
key, description = self._parse_binding(binding)
|
*[self._make_item(b) for b in left_bindings],
|
||||||
key_display = self._format_key_display(key)
|
classes="help_list",
|
||||||
with Horizontal(classes="help_row"):
|
)
|
||||||
yield Static(f"[bold {KEY_COLOR}]{key_display}[/]", classes="help_key")
|
yield ListView(
|
||||||
yield Static(description, classes="help_action")
|
*[self._make_item(b) for b in right_bindings],
|
||||||
yield Static(f"Press [bold {KEY_COLOR}]?[/] or [bold {KEY_COLOR}]Escape[/] to close", id="help_footer")
|
classes="help_list",
|
||||||
|
)
|
||||||
|
yield Static(
|
||||||
|
f"Press [bold {KEY_COLOR}]?[/] or [bold {KEY_COLOR}]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