Skip to content

Conversation

davidfokkema
Copy link
Contributor

Simple Textual apps place a lot of logic in the App class, but you can also
use a Screen as the main screen. This example shows how to do that, and how to
push modal screens from the main screen, and show a modal confirmation screen
when quitting the app. You'll never leave the main screen until you quit the
application, but you can still use the App class to manage a (few)
application-wide bindings.

Copy link
Member

@edward-jazzhands edward-jazzhands left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome. Just need one small change, need a main guard on the script. My apologies for not having a contribution guide already to explain this. Just add this to the bottom, as well as import sys:

if __name__ == "__main__":
    app = MainApp()
    app.run()
    sys.exit(app.return_code)

The main guard itself is required for the pytest validation to work, while the sys.exit thing makes the scripts return an error code to the recipe runner if a script crashes (Textual apps don't do this by default). Which of course you would never see for working scripts, but it makes it easier to play around with them, etc. Its meant to be a convenience for people using the cookbook. I need to write this all out in a contribution guide very soon.

@davidfokkema
Copy link
Contributor Author

Of course!

Copy link
Member

@edward-jazzhands edward-jazzhands left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect

@edward-jazzhands edward-jazzhands merged commit 382be6e into ttygroup:main Aug 16, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants