textual_enhanced.commands
Provides code related to 'commands' in a Textual application.
CommandHits
module-attribute
CommandHits = Iterator[CommandHit | Command]
The result of looking for commands to make into hits.
ChangeTheme
Command
Bases: Message
Base class for all application command messages.
ACTION
class-attribute
instance-attribute
ACTION = None
The action to call when the command is executed.
By default the action will be:
action_{snake-case-of-command}_command
There are some commands that will result in unhelpful snake-case names,
and also times where you want the action method named in a better way;
in such cases use ACTION
to override the method name.
BINDING_KEY
class-attribute
instance-attribute
BINDING_KEY = None
The binding key for the command.
This can either be a string, which is the keys to bind, a tuple of the
keys and also an overriding display value, or None
.
COMMAND
class-attribute
instance-attribute
COMMAND = None
The text for the command.
Notes
If no COMMAND
is provided the class name will be used.
FOOTER_TEXT
class-attribute
instance-attribute
FOOTER_TEXT = None
The text to show in the footer.
Notes
If no FOOTER_TEXT
is provided the
command
will be used.
SHOW_IN_FOOTER
class-attribute
instance-attribute
SHOW_IN_FOOTER = False
context_command
property
context_command
The command in context.
context_tooltip
property
context_tooltip
The tooltip for the command, in context.
has_binding
property
has_binding
Does this command have a binding?
action_name
classmethod
action_name()
binding
classmethod
binding()
Create a binding object for the command.
Returns:
Type | Description |
---|---|
Binding
|
A |
Raises:
Type | Description |
---|---|
ValueError
|
If the command has no key binding. |
bindings
staticmethod
bindings(*bindings)
Create bindings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
BindingType | type[Command]
|
Normal Textual bindings or a command class. |
()
|
Returns:
Type | Description |
---|---|
list[BindingType]
|
A list of bindings that can be used with |
command
classmethod
command()
key_binding
classmethod
key_binding()
tooltip
classmethod
tooltip()
The tooltip for the command.
CommandHit
Bases: NamedTuple
A command hit for use in building a command palette hit.
command
instance-attribute
command
The command.
description
instance-attribute
description
The description of the command.
message
instance-attribute
message
The message to emit when the command is chosen.
CommandsProvider
Bases: Provider
A base class for command-message-oriented command palette commands.
commands
abstractmethod
commands()
Provide the command data for the command palette.
Yields:
Type | Description |
---|---|
CommandHits
|
A tuple of the command, the command description and a command message. |
discover
async
discover()
Handle a request to discover commands.
Yields:
Type | Description |
---|---|
Hits
|
Command discovery hits for the command palette. |
maybe
maybe(command)
Yield a command if it's applicable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
type[Command]
|
The type of the command to maybe yield. |
required |
Yields:
Type | Description |
---|---|
CommandHits
|
The command if it can be used right now. |
This method takes the command, looks at its action_name
and uses
Textual's check_action
to see if the action can be performed right
now. If it can it will yield
an instance of the command, otherwise
it does nothing.
prompt
classmethod
prompt()
The prompt for the command provider.
CommonCommands
Bases: CommandsProvider
Provides some common top-level commands for the application.
commands
commands()
Provide the main application commands for the command palette.
Yields:
Type | Description |
---|---|
CommandHits
|
The commands for the command palette. |
Help
Quit
Provides helper code for dealing with bindings.
all_keys_for
Get all the keys for the given command or binding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
DOMNode
|
The node we're working from. |
required |
|
type[Command] | Binding
|
The command or binding to get the keys for. |
required |
Yields:
Type | Description |
---|---|
str
|
The display names of all the keys for the command/binding. |
primary_key_for
Get the primary key for the given command or binding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
DOMNode
|
The node we're working from. |
required |
|
type[Command] | Binding
|
The command or binding to get the keys for. |
required |
Returns:
Type | Description |
---|---|
str
|
The display name of the primary key for the command/binding. |