If you don't have the
textual command on your path, you may have forgotten to install with the
See getting started for details.
Textual comes with a command line application of the same name. The
textual command is a super useful tool that will help you to build apps.
Take a moment to look through the available sub-commands. There will be even more helpful tools here in the future.
You can run Textual apps with the
run subcommand. If you supply a path to a Python file it will load and run the application.
run sub-command will first look for a
App instance called
app in the global scope of your Python file. If there is no
app, it will create an instance of the first
App class it finds and run that.
Alternatively, you can add the name of an
App instance or class after a colon to run a specific app in the Python file. Here's an example:
If the Python file contains a call to app.run() then you can launch the file as you normally would any other Python program. Running your app via
textual run will give you access to a few Textual features such as live editing of CSS files.
If you combine the
run command with the
--dev switch your app will run in development mode.
One of the features of dev mode is live editing of CSS files: any changes to your CSS will be reflected in the terminal a few milliseconds later.
This is a great feature for iterating on your app's look and feel. Open the CSS in your editor and have your app running in a terminal. Edits to your CSS will appear almost immediately after you save.
When building a typical terminal application you are generally unable to use
To use the console, open up two terminal emulators. Run the following in one of the terminals:
You should see the Textual devtools welcome message:
In the other console, run your application with
textual run and the
Textual writes log messages to inform you about certain events, such as when the user presses a key or clicks on the terminal. To avoid swamping you with too much information, some events are marked as "verbose" and will be excluded from the logs. If you want to see these log messages, you can add the
In addition to simple strings, Textual console supports Rich formatting. To write rich logs, import
log as follows:
This method will pretty print data structures (like lists and dicts) as well as Rich renderables. Here are some examples:
Textual log messages may contain console Markup:
There's a convenient shortcut to
log available on the
Widget objects. This is useful in event handlers. Here's an example: