Skip to content

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

ProviderSource = "Iterable[type[Provider] | Callable[[], type[Provider]]]"

The type used to declare the providers for a CommandPalette.

Command

Command(prompt, hit, id=None, disabled=False)

Bases: Option

Class that holds a hit in the CommandList.

Parameters:

Name Type Description Default

prompt

VisualType

The prompt for the option.

required

hit

DiscoveryHit | Hit

The details of the hit 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

hit instance-attribute

hit = hit

The details of the hit associated with the option.

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,
    select_on_focus=True,
    name=None,
    id=None,
    classes=None,
    disabled=False,
    tooltip=None,
    compact=False
)

Bases: Input

The command palette input control.

CommandList

CommandList(
    *content,
    name=None,
    id=None,
    classes=None,
    disabled=False,
    markup=True,
    compact=False
)

Bases: OptionList

The command palette command list.

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

providers

ProviderSource | None

An optional list of providers to use. If None, the providers supplied in the App or Screen will be used.

None

placeholder

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

COMPONENT_CLASSES = {
    "command-palette--help-text",
    "command-palette--highlight",
}
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

run_on_select = True

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

Closed(option_selected)

Bases: Message

Posted to App when the command palette is closed.

option_selected instance-attribute

option_selected

True if an option was selected, False if the palette was closed without selecting an option.

Opened dataclass

Opened()

Bases: Message

Posted to App when the command palette is opened.

OptionHighlighted dataclass

OptionHighlighted(highlighted_event)

Bases: Message

Posted to App when an option is highlighted in the command palette.

highlighted_event instance-attribute

highlighted_event

The option highlighted event from the OptionList within the command palette.

is_open staticmethod