diff --git a/docs/examples/guide/command_palette/command01.py b/docs/examples/guide/command_palette/command01.py index dfe3b2c62c..fe7b64d836 100644 --- a/docs/examples/guide/command_palette/command01.py +++ b/docs/examples/guide/command_palette/command01.py @@ -1,11 +1,12 @@ from textual.app import App, SystemCommandsResult +from textual.screen import Screen class BellCommandApp(App): """An app with a 'bell' command.""" - def get_system_commands(self) -> SystemCommandsResult: - yield from super().get_system_commands() # (1)! + def get_system_commands(self, screen: Screen) -> SystemCommandsResult: + yield from super().get_system_commands(screen) # (1)! yield ("Bell", "Ring the bell", self.bell) # (2)! diff --git a/docs/guide/command_palette.md b/docs/guide/command_palette.md index d7bc88cfff..b327ddeeec 100644 --- a/docs/guide/command_palette.md +++ b/docs/guide/command_palette.md @@ -36,7 +36,8 @@ Textual apps have a number of *system* commands enabled by default. These are declared in the [`App.get_system_commands`][textual.app.App.get_system_commands] method. You can implement this method in your App class to add more commands. -To declare a command `yield` a tuple of `(TITLE, HELP TEXT, CALLABLE)`. +To declare a command, define a `get_system_commands` method, which will receive the screen that was active when the user summoned the command palette. +You can add a command by yielding a tuple of `(TITLE, HELP TEXT, CALLABLE)`. The `TITLE` and `HELP TEXT` values are shown in the command palette. If the user selects that command, then Textual will invoke `CALLABLE`. @@ -47,7 +48,7 @@ Here's how we would add a command to ring the terminal bell (a super useful piec ```python title="command01.py" hl_lines="18-24 29" --8<-- "docs/examples/guide/command_palette/command01.py" ``` - + 1. Adds the default commands from the base class. 2. Adds a new command. diff --git a/docs/widgets/footer.md b/docs/widgets/footer.md index 3d9b0b47de..1227791b8d 100644 --- a/docs/widgets/footer.md +++ b/docs/widgets/footer.md @@ -32,8 +32,6 @@ widget. Notice how the `Footer` automatically displays the keybinding. | Name | Type | Default | Description | | ---------------------- | ------ | ------- | ------------------------------------------------------------------------------------------ | -| `upper_case_keys` | `bool` | `False` | Display the keys in upper case. | -| `ctrl_to_caret` | `bool` | `True` | Replace "ctrl+" with "^" to denote a key that requires holding ++CTRL++ | | `compact` | `bool` | `False` | Display a more compact footer. | | `show_command_palette` | `bool` | `True` | Display the key to invoke the command palette (show on the right hand side of the footer). | diff --git a/src/textual/app.py b/src/textual/app.py index 384f07785f..531a7f82b0 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -928,11 +928,12 @@ def active_bindings(self) -> dict[str, ActiveBinding]: """ return self.screen.active_bindings - def get_system_commands( - self, - ) -> SystemCommandsResult: + def get_system_commands(self, screen: Screen) -> SystemCommandsResult: """A generator of system commands used in the command palette. + Args: + screen: The screen where the command palette was invoked from. + Implement this method in your App subclass if you want to add custom commands. Here is an example: @@ -967,7 +968,7 @@ def get_system_commands(self): self.action_quit, ) - if self.screen.query("HelpPanel"): + if screen.query("HelpPanel"): yield ( "Hide keys and help panel", "Hide the keys and widget help panel", diff --git a/src/textual/system_commands.py b/src/textual/system_commands.py index fa1e8d7884..b01d97cf2c 100644 --- a/src/textual/system_commands.py +++ b/src/textual/system_commands.py @@ -28,7 +28,7 @@ class SystemCommandsProvider(Provider): @property def _system_commands(self) -> Iterable[tuple[str, str, IgnoreReturnCallbackType]]: """The system commands to reveal to the command palette.""" - yield from self.app.get_system_commands() + yield from self.app.get_system_commands(self.screen) async def discover(self) -> Hits: """Handle a request for the discovery commands for this provider.