Skip to content

How to implement screen commands? #5615

Answered by TomJGooding
TomJGooding asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for being my rubber duck! Turns out I had missed something obvious after all.

Here's a quick example in case it helps anyone who stumbles across this:

from textual.app import App, ComposeResult
from textual.command import DiscoveryHit, Hit, Hits, Provider, SimpleCommand
from textual.screen import Screen
from textual.widgets import Footer


class DeepThoughtCommands(Provider):
    @property
    def commands(self) -> list[SimpleCommand]:
        screen = self.screen
        assert isinstance(screen, DeepThoughtScreen)
        commands = [
            SimpleCommand(
                "Calculate the answer to the Ultimate Question",
                screen.ultimate_answer,
                "…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TomJGooding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant