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
Parameter | Default | Description |
---|---|---|
prompt
RenderableType
|
required | The prompt for the option. |
command
DiscoveryHit | Hit
|
required | The details of the command associated with the option. |
id
str | None
|
None
|
The optional ID for the option. |
disabled
bool
|
False
|
The initial enabled/disabled state. Enabled by default. |
command
instance-attribute
¶
The details of the command associated with the option.
CommandList
class
¶
CommandPalette
class
¶
Bases: _SystemModalScreen[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.
DiscoveryHit
class
¶
Holds the details of a single command search hit.
command
instance-attribute
¶
The function to call when the command is chosen.
display
instance-attribute
¶
A string or Rich renderable representation of the hit.
help
instance-attribute
class-attribute
¶
Optional help text for the command.
prompt
property
¶
The prompt to use when displaying the discovery hit in the command palette.
Hit
class
¶
Holds the details of a single command search hit.
command
instance-attribute
¶
The function to call when the command is chosen.
help
instance-attribute
class-attribute
¶
Optional help text for the command.
match_display
instance-attribute
¶
A string or Rich renderable representation of the hit.
prompt
property
¶
The prompt to use when displaying the hit in the command palette.
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
Parameter | Default | Description |
---|---|---|
query
str
|
required | A query as typed in by the user. |
match_style
Style | None
|
None
|
The style to use to highlight matched portions of a string. |
case_sensitive
bool
|
False
|
Should matching be case sensitive? |
Provider
class
¶
Bases: ABC
Base class for command palette command providers.
To create new command provider, inherit from this class and implement
search
.
Parameters
Parameter | Default | Description |
---|---|---|
screen
Screen[Any]
|
required | A reference to the active screen. |
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
.
discover
async
¶
A default collection of hits for the provider.
Yields:
Type | Description |
---|---|
Hits
|
Instances of |
Note
This is different from
search
in that it should
yield DiscoveryHit
s that
should be shown by default (before user input).
It is permitted to not implement this method.
matcher
method
¶
Create a fuzzy matcher for the given user input.
Parameters
Parameter | Default | Description |
---|---|---|
user_input
str
|
required | The text that the user has input. |
case_sensitive
bool
|
False
|
Should matching be case sensitive? |
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
.