textual.command
This module contains classes for working with Textual's command palette.
See the guide on the Command Palette for full details.
Hits
module-attribute
¶
Hits = AsyncIterator['DiscoveryHit | Hit']
Return type for the command provider's search
method.
ProviderSource
module-attribute
¶
The type used to declare the providers for a CommandPalette.
Command
¶
Bases: Option
Class that holds a hit in the CommandList
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
VisualType
|
The prompt for the option. |
required |
|
DiscoveryHit | Hit
|
The details of the hit associated with the option. |
required |
|
str | None
|
The optional ID for the option. |
None
|
|
bool
|
The initial enabled/disabled state. Enabled by default. |
False
|
CommandInput
¶
CommandInput(
value=None,
placeholder="",
highlighter=None,
password=False,
*,
restrict=None,
type="text",
max_length=0,
suggester=None,
validators=None,
validate_on=None,
valid_empty=False,
name=None,
id=None,
classes=None,
disabled=False,
tooltip=None
)
Bases: Input
The command palette input control.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str | None
|
An optional default value for the input. |
None
|
|
str
|
Optional placeholder text for the input. |
''
|
|
Highlighter | None
|
An optional highlighter for the input. |
None
|
|
bool
|
Flag to say if the field should obfuscate its content. |
False
|
|
str | None
|
A regex to restrict character inputs. |
None
|
|
InputType
|
The type of the input. |
'text'
|
|
int
|
The maximum length of the input, or 0 for no maximum length. |
0
|
|
Suggester | None
|
|
None
|
|
Validator | Iterable[Validator] | None
|
An iterable of validators that the Input value will be checked against. |
None
|
|
Iterable[InputValidationOn] | None
|
Zero or more of the values "blur", "changed", and "submitted", which determine when to do input validation. The default is to do validation for all messages. |
None
|
|
bool
|
Empty values are valid. |
False
|
|
str | None
|
Optional name for the input widget. |
None
|
|
str | None
|
Optional ID for the widget. |
None
|
|
str | None
|
Optional initial classes for the widget. |
None
|
|
bool
|
Whether the input is disabled or not. |
False
|
|
RenderableType | None
|
Optional tooltip. |
None
|
CommandList
¶
CommandPalette
¶
CommandPalette(
providers=None,
*,
placeholder="Search for commands…",
name=None,
id=None,
classes=None
)
Bases: SystemModalScreen[None]
The Textual command palette.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ProviderSource | None
|
An optional list of providers to use. If None, the providers supplied in the App or Screen will be used. |
None
|
|
str
|
The placeholder text for the command palette. |
'Search for commands…'
|
BINDINGS
class-attribute
¶
BINDINGS = [
Binding(
"ctrl+end, shift+end",
"command_list('last')",
"Go to bottom",
show=False,
),
Binding(
"ctrl+home, shift+home",
"command_list('first')",
"Go to top",
show=False,
),
Binding(
"down", "cursor_down", "Next command", show=False
),
Binding("escape", "escape", "Exit the command palette"),
Binding(
"pagedown",
"command_list('page_down')",
"Next page",
show=False,
),
Binding(
"pageup",
"command_list('page_up')",
"Previous page",
show=False,
),
Binding(
"up",
"command_list('cursor_up')",
"Previous command",
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.
Closed
dataclass
¶
OptionHighlighted
dataclass
¶
DiscoveryHit
dataclass
¶
Holds the details of a single command search hit.
prompt
property
¶
The prompt to use when displaying the discovery hit in the command palette.
score
property
¶
A discovery hit always has a score of 0.
The order in which discovery hits are displayed is determined by the order in which they are yielded by the Provider. It's up to the developer to yield DiscoveryHits in the .
Hit
dataclass
¶
Matcher
¶
Matcher(query, *, match_style=None, case_sensitive=False)
A fuzzy matcher.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
A query as typed in by the user. |
required |
|
Style | None
|
The style to use to highlight matched portions of a string. |
None
|
|
bool
|
Should matching be case sensitive? |
False
|
Provider
¶
Provider(screen, match_style=None)
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[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
.
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
¶
matcher(user_input, case_sensitive=False)
Create a fuzzy matcher for the given user input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The text that the user has input. |
required |
|
bool
|
Should matching be case sensitive? |
False
|
Returns:
Type | Description |
---|---|
Matcher
|
A fuzzy matcher object for matching against candidate hits. |
shutdown
async
¶
Called when the Provider is shutdown.
Use this method to perform an cleanup, if required.
SearchIcon
¶
SimpleCommand
¶
Bases: NamedTuple
A simple command.