Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Aug 22, 2024
1 parent 9f66043 commit 7a9ab93
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions docs/examples/guide/command_palette/command01.py
Original file line number Diff line number Diff line change
@@ -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)!


Expand Down
5 changes: 3 additions & 2 deletions docs/guide/command_palette.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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.

Expand Down
2 changes: 0 additions & 2 deletions docs/widgets/footer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |

Expand Down
9 changes: 5 additions & 4 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/textual/system_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7a9ab93

Please sign in to comment.