textual.app
Here you will find the App class, which is the base class for Textual apps.
See app basics for how to build Textual apps.
AutopilotCallbackType
module-attribute
¶
Signature for valid callbacks that can be used to control apps.
CommandCallback
module-attribute
¶
Signature for callbacks used in get_system_commands
RenderResult
module-attribute
¶
Result of Widget.render()
ScreenType
module-attribute
¶
Type var for a Screen, used in get_screen.
App
¶
App(
driver_class=None,
css_path=None,
watch_css=False,
ansi_color=False,
)
Bases: Generic[ReturnType], DOMNode
The base class for Textual Applications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Type[Driver] | None
|
Driver class or |
None
|
|
CSSPathType | None
|
Path to CSS or |
None
|
|
bool
|
Reload CSS if the files changed. This is set automatically if
you are using |
False
|
|
bool
|
Allow ANSI colors if |
False
|
Raises:
| Type | Description |
|---|---|
CssPathError
|
When the supplied CSS path(s) are an unexpected type. |
ALLOW_IN_MAXIMIZED_VIEW
class-attribute
¶
The default value of Screen.ALLOW_IN_MAXIMIZED_VIEW.
ALLOW_SELECT
class-attribute
¶
A switch to toggle arbitrary text selection for the app.
Note that this doesn't apply to Input and TextArea which have builtin support for selection.
AUTO_FOCUS
class-attribute
¶
A selector to determine what to focus automatically when a screen is activated.
The widget focused is the first that matches the given CSS selector.
Setting to None or "" disables auto focus.
BINDINGS
class-attribute
¶
BINDINGS = [
Binding(
"ctrl+q",
"quit",
"Quit",
tooltip="Quit the app and return to the command prompt.",
show=False,
priority=True,
),
Binding("ctrl+c", "help_quit", show=False, system=True),
]
The default key bindings.
BINDING_GROUP_TITLE
class-attribute
instance-attribute
¶
Set to text to show in the key panel.
CLICK_CHAIN_TIME_THRESHOLD
class-attribute
¶
The maximum number of seconds between clicks to upgrade a single click to a double click, a double click to a triple click, etc.
CLOSE_TIMEOUT
class-attribute
instance-attribute
¶
Timeout waiting for widget's to close, or None for no timeout.
COMMANDS
class-attribute
¶
COMMANDS = {get_system_commands_provider}
Command providers used by the command palette.
Should be a set of command.Provider classes.
COMMAND_PALETTE_BINDING
class-attribute
¶
The key that launches the command palette (if enabled by App.ENABLE_COMMAND_PALETTE).
COMMAND_PALETTE_DISPLAY
class-attribute
¶
How the command palette key should be displayed in the footer (or None for default).
CSS
class-attribute
¶
Inline CSS, useful for quick scripts. This is loaded after CSS_PATH, and therefore takes priority in the event of a specificity clash.
ENABLE_COMMAND_PALETTE
class-attribute
¶
Should the command palette be enabled for the application?
ESCAPE_TO_MINIMIZE
class-attribute
¶
Use escape key to minimize widgets (potentially overriding bindings).
This is the default value, used if the active screen's ESCAPE_TO_MINIMIZE is not changed from None.
HORIZONTAL_BREAKPOINTS
class-attribute
instance-attribute
¶
List of horizontal breakpoints for responsive classes.
This allows for styles to be responsive to the dimensions of the terminal. For instance, you might want to show less information, or fewer columns on a narrow displays -- or more information when the terminal is sized wider than usual.
A breakpoint consists of a tuple containing the minimum width where the class should applied, and the name of the class to set.
Note that only one class name is set, and if you should avoid having more than one breakpoint set for the same size.
MODES
class-attribute
¶
NOTIFICATION_TIMEOUT
class-attribute
¶
Default number of seconds to show notifications before removing them.
SUB_TITLE
class-attribute
instance-attribute
¶
A class variable to set the default sub-title for the application.
To update the sub-title while the app is running, you can set the sub_title attribute.
See also the Screen.SUB_TITLE attribute.
SUSPENDED_SCREEN_CLASS
class-attribute
¶
Class to apply to suspended screens, or empty string for no class.
TITLE
class-attribute
instance-attribute
¶
A class variable to set the default title for the application.
To update the title while the app is running, you can set the title attribute.
See also the Screen.TITLE attribute.
TOOLTIP_DELAY
class-attribute
instance-attribute
¶
The time in seconds after which a tooltip gets displayed.
VERTICAL_BREAKPOINTS
class-attribute
instance-attribute
¶
List of vertical breakpoints for responsive classes.
Contents are the same as HORIZONTAL_BREAKPOINTS, but the integer is compared to the height, rather than the width.
active_bindings
property
¶
Get currently active bindings.
If no widget is focused, then app-level bindings are returned. If a widget is focused, then any bindings present in the active screen and app are merged and returned.
This property may be used to inspect current bindings.
Returns:
| Type | Description |
|---|---|
dict[str, ActiveBinding]
|
A dict that maps keys on to binding information. |
animation_level
instance-attribute
¶
animation_level = TEXTUAL_ANIMATIONS
Determines what type of animations the app will display.
ansi_color
class-attribute
instance-attribute
¶
ansi_color = Reactive(False)
Allow ANSI colors in UI?
ansi_theme
property
¶
The ANSI TerminalTheme currently being used.
Defines how colors defined as ANSI (e.g. magenta) inside Rich renderables
are mapped to hex codes.
ansi_theme_dark
class-attribute
instance-attribute
¶
Maps ANSI colors to hex colors using a Rich TerminalTheme object while using a dark theme.
ansi_theme_light
class-attribute
instance-attribute
¶
Maps ANSI colors to hex colors using a Rich TerminalTheme object while using a light theme.
app_focus
class-attribute
instance-attribute
¶
Indicates if the app has focus.
When run in the terminal, the app always has focus. When run in the web, the app will get focus when the terminal widget has focus.
app_resume_signal
instance-attribute
¶
app_resume_signal = Signal(self, 'app-resume')
The signal that is published when the app is resumed after a suspend.
When the app is resumed after a
App.suspend call this signal will be
published;
subscribe to this signal to
perform work after the app has resumed.
app_suspend_signal
instance-attribute
¶
app_suspend_signal = Signal(self, 'app-suspend')
The signal that is published when the app is suspended.
When App.suspend is called this signal
will be published;
subscribe to this signal to
perform work before the suspension takes place.
available_themes
property
¶
All available themes (all built-in themes plus any that have been registered).
A dictionary mapping theme names to Theme instances.
children
property
¶
A view onto the app's immediate children.
This attribute exists on all widgets. In the case of the App, it will only ever contain a single child, which will be the currently active screen.
Returns:
| Type | Description |
|---|---|
Sequence['Widget']
|
A sequence of widgets. |
clipboard
property
¶
The value of the local clipboard.
Note, that this only contains text copied in the app, and not text copied from elsewhere in the OS.
console_options
property
¶
Get options for the Rich console.
Returns:
| Type | Description |
|---|---|
ConsoleOptions
|
Console options (same object returned from |
cursor_position
instance-attribute
¶
The position of the terminal cursor in screen-space.
This can be set by widgets and is useful for controlling the positioning of OS IME and emoji popup menus.
escape_to_minimize
property
¶
Use the escape key to minimize?
When a widget is maximized, this boolean determines if the escape key will
minimize the widget (potentially overriding any bindings).
The default logic is to use the screen's ESCAPE_TO_MINIMIZE classvar if it is set to True or False.
If the classvar on the screen is not set (and left as None), then the app's ESCAPE_TO_MINIMIZE is used.
focused
property
¶
The widget that is focused on the currently active screen, or None.
Focused widgets receive keyboard input.
Returns:
| Type | Description |
|---|---|
Widget | None
|
The currently focused widget, or |
hover_over
instance-attribute
¶
The first widget with a hover style under the mouse.
is_headless
property
¶
Is the app running in 'headless' mode?
Headless mode is used when running tests with run_test.