This commit is contained in:
Will McGugan
2024-08-14 16:39:08 +01:00
parent a44eb0b217
commit 888d8d9283
4 changed files with 33 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ from sys import argv
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.reactive import var
from textual.widgets import Footer, KeyPanel, MarkdownViewer
from textual.widgets import Footer, MarkdownViewer
class MarkdownApp(App):
@@ -33,7 +33,6 @@ class MarkdownApp(App):
def compose(self) -> ComposeResult:
yield Footer()
yield MarkdownViewer()
yield KeyPanel()
async def on_mount(self) -> None:
"""Go to the first path when the app starts."""

View File

@@ -3504,6 +3504,19 @@ class App(Generic[ReturnType], DOMNode):
"""An [action](/guide/actions) to focus the previous widget."""
self.screen.focus_previous()
def action_hide_keys(self) -> None:
"""Hide the keys panel (if present)."""
self.screen.query("KeyPanel").remove()
def action_show_keys(self) -> None:
"""Show the keys panel."""
from .widgets import KeyPanel
try:
self.query_one(KeyPanel)
except NoMatches:
self.mount(KeyPanel())
def _on_terminal_supports_synchronized_output(
self, message: messages.TerminalSupportsSynchronizedOutput
) -> None:

View File

@@ -24,9 +24,9 @@ class SystemCommands(Provider):
"""
@property
def _system_commands(self) -> tuple[tuple[str, IgnoreReturnCallbackType, str], ...]:
def _system_commands(self) -> list[tuple[str, IgnoreReturnCallbackType, str]]:
"""The system commands to reveal to the command palette."""
return (
commands = [
(
"Toggle light/dark mode",
self.app.action_toggle_dark,
@@ -37,7 +37,22 @@ class SystemCommands(Provider):
self.app.action_quit,
"Quit the application as soon as possible",
),
)
]
if self.screen.query("KeyPanel"):
commands.append(
("Hide keys", self.app.action_hide_keys, "Hide the keys panel")
)
else:
commands.append(
(
"Show keys",
self.app.action_show_keys,
"Show a summary of available keys",
)
)
commands.sort(key=lambda command: command[0])
return commands
async def discover(self) -> Hits:
"""Handle a request for the discovery commands for this provider.

View File

@@ -10,7 +10,7 @@ from ._directory_tree import DirectoryTree as DirectoryTree
from ._footer import Footer as Footer
from ._header import Header as Header
from ._input import Input as Input
from ._key_panel import KeyPanel
from ._key_panel import KeyPanel as KeyPanel
from ._label import Label as Label
from ._list_item import ListItem as ListItem
from ._list_view import ListView as ListView