Skip to content

Textual 0.37.0 adds a command palette

Textual version 0.37.0 has landed! The highlight of this release is the new command palette.

A command palette gives users quick access to features in your app. If you hit ctrl+backslash in a Textual app, it will bring up the command palette where you can start typing commands. The commands are matched with a fuzzy search, so you only need to type two or three characters to get to any command.

Here's a video of it in action:

Adding your own commands to the command palette is a piece of cake. Here's the (command) Provider class used in the example above:

class ColorCommands(Provider):
    """A command provider to select colors."""

    async def search(self, query: str) -> Hits:
        """Called for each key."""
        matcher = self.matcher(query)
        for color in COLOR_NAME_TO_RGB.keys():
            score = matcher.match(color)
            if score > 0:
                yield Hit(
                    score,
                    matcher.highlight(color),
                    partial(self.app.post_message, SwitchColor(color)),
                )

And here is how you add a provider to your app:

class ColorApp(App):
    """Experiment with the command palette."""

    COMMANDS = App.COMMANDS | {ColorCommands}

We're excited about this feature because it is a step towards bringing a common user interface to Textual apps.

Quote

It's a Textual app. I know this.

— You, maybe.

The goal is to be able to build apps that may look quite different, but take no time to learn, because once you learn how to use one Textual app, you can use them all.

See the Guide for details on how to work with the command palette.

What else?

Also in 0.37.0 we have a new Collapsible widget, which is a great way of adding content while avoiding a cluttered screen.

And of course, bug fixes and other updates. See the release page for the full details.

What's next?

Coming very soon, is a new TextEditor widget. This is a super powerful widget to enter arbitrary text, with beautiful syntax highlighting for a number of languages. We're expecting that to land next week. Watch this space, or join the Discord server if you want to be the first to try it out.

Join us

Join our Discord server if you want to discuss Textual with the Textualize devs, or the community.