Command
The Textual command palette.
See the guide on the Command Palette for full details.
Hits
module-attribute
¶
Return type for the command provider's search
method.
Command
class
¶
Bases: Option
Class that holds a command in the CommandList
.
Parameters
Name | Type | Description | Default |
---|---|---|---|
prompt |
RenderableType
|
The prompt for the option. |
required |
command |
Hit
|
The details of the command associated with the option. |
required |
id |
str | None
|
The optional ID for the option. |
None
|
disabled |
bool
|
The initial enabled/disabled state. Enabled by default. |
False
|
command
instance-attribute
¶
The details of the command associated with the option.
CommandList
class
¶
CommandPalette
class
¶
Bases: ModalScreen[CallbackType]
The Textual command palette.
BINDINGS
class-attribute
¶
BINDINGS: list[BindingType] = [
Binding(
"ctrl+end, shift+end",
"command_list('last')",
show=False,
),
Binding(
"ctrl+home, shift+home",
"command_list('first')",
show=False,
),
Binding("down", "cursor_down", show=False),
Binding("escape", "escape", "Exit the command palette"),
Binding(
"pagedown", "command_list('page_down')", show=False
),
Binding(
"pageup", "command_list('page_up')", show=False
),
Binding("up", "command_list('cursor_up')", show=False),
]
Key(s) | Description |
---|---|
ctrl+end, shift+end | Jump to the last available commands. |
ctrl+home, shift+home | Jump to the first available commands. |
down | Navigate down through the available commands. |
escape | Exit the command palette. |
pagedown | Navigate down a page through the available commands. |
pageup | Navigate up a page through the available commands. |
up | Navigate up through the available commands. |
COMPONENT_CLASSES
class-attribute
¶
Class | Description |
---|---|
command-palette--help-text |
Targets the help text of a matched command. |
command-palette--highlight |
Targets the highlights of a matched command. |
run_on_select
class-attribute
¶
A flag to say if a command should be run when selected by the user.
If True
then when a user hits Enter
on a command match in the result
list, or if they click on one with the mouse, the command will be
selected and run. If set to False
the input will be filled with the
command and then Enter
should be pressed on the keyboard or the 'go'
button should be pressed.
is_open
staticmethod
¶
Hit
class
¶
Holds the details of a single command search hit.
command
instance-attribute
¶
The function to call when the command is chosen.
help
class-attribute
instance-attribute
¶
Optional help text for the command.
match_display
instance-attribute
¶
A string or Rich renderable representation of the hit.
score
instance-attribute
¶
The score of the command hit.
The value should be between 0 (no match) and 1 (complete match).
Matcher
class
¶
A fuzzy matcher.
Parameters
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
A query as typed in by the user. |
required |
match_style |
Style | None
|
The style to use to highlight matched portions of a string. |
None
|
case_sensitive |
bool
|
Should matching be case sensitive? |
False
|
Provider
class
¶
Bases: ABC
Base class for command palette command providers.
To create new command provider, inherit from this class and implement
search
.
Parameters
Name | Type | Description | Default |
---|---|---|---|
screen |
Screen[Any]
|
A reference to the active screen. |
required |
focused
property
¶
The currently-focused widget in the currently-active screen in the application.
If no widget has focus this will be None
.
match_style
property
¶
The preferred style to use when highlighting matching portions of the match_display
.
matcher
method
¶
Create a fuzzy matcher for the given user input.
Parameters
Name | Type | Description | Default |
---|---|---|---|
user_input |
str
|
The text that the user has input. |
required |
case_sensitive |
bool
|
Should matching be case sensitive? |
False
|
Returns
Type | Description |
---|---|
Matcher
|
A fuzzy matcher object for matching against candidate hits. |
search
async
abstractmethod
¶
shutdown
async
¶
Called when the Provider is shutdown.
Use this method to perform an cleanup, if required.
startup
async
¶
Called after the Provider is initialized, but before any calls to search
.