
    AHjε                   h   U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlmZmZmZ ddlmZ ddlmZmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4Z4ddl5Z4ddl6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZBmCZC ddlDmEZE ddlFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZO ddlPmQZQmRZRmSZSmTZT ddlUmVZVmWZW ddlXmYZYmZZZ ddl[m\Z\ ddl]m^Z^ ddl_m`Z` ddlambZbmcZc ddlamdZe ddlfmgZg ddlhmiZimjZj ddlkmlZl ddlmmnZnmoZompZp ddlqmrZr dd lsmtZt dd!lumvZvmwZw dd"lxmyZy dd#lzm{Z{ dd$l|m}Z}m~Z~mZmZ dd%lmZmZmZmZ dd&lmZ dd'lmZ dd(lmZ dd)lmZ dd*lmZmZ dd+lmZmZ dd,lmZ dd-lmZ dd.lmZmZ dd/lmZ dd0lmZmZmZmZ dd1lmZmZmZ dd2lmZmZmZmZmZ dd3lmZmZ dd4lmZmZmZmZ dd5lmZ dd6lmZ dd7lmZmZmZmZmZ dd8lmZ dd9lmZmZmZ dd:lmZ dd;lmZmZ dd<lmZmZ dd=lmZ dd>lmZmZ dd?lmZ er<dd@lmZ ddAlmZmZmZmZ ddBlqmZ ddClmZ ddDlmZ ddElmZ ddFlmZ ddGlmZ ddHlmZ e
j                  dIk(  ZeKj                  r ej                  dJe       e
j                  dKk\  Ze(e   ZdLZdMedN<   	 dOZdMedP<   	 dQZdMedR<   	  e/dSeT      Z	  G dU dVe+      ZdtdWZ G dX dYe      Z G dZ d[e      Z G d\ d]e      Z G d^ d_e      Z G d` dae      Z G db dce      Z G dd dee      Z G df dge      Z G dh die      Z G dj dke      Z e/dl      Z e/dm      Z G dn do      Z  G dp dq      Ze4j                  j                   G dr dse'e   e             Zy)uz

Here you will find the [App][textual.app.App] class, which is the base class for Textual apps.

See [app basics](/guide/app) for how to build Textual apps.
    )annotationsN)AbstractEventLoopTaskcreate_task)Future)asynccontextmanagercontextmanagerredirect_stderrredirect_stdout)partial)Path)perf_counter)TYPE_CHECKINGAnyAsyncGenerator	AwaitableBinaryIOCallableClassVar	GeneratorGenericIterableIteratorMapping
NamedTupleSequenceTextIOTypeTypeVaroverload)WeakKeyDictionaryWeakSet)user_downloads_path)ConsoleConsoleDimensionsConsoleOptionsRenderableType)Controlis_renderable)SegmentSegments)TerminalTheme)	LoggerLogGroupLogVerbosityactions	constantseventslogmessageson)DEFAULT_EASING
AnimatableAnimatorEasingFunction)SYNC_END
SYNC_START)	ALABASTERMONOKAI)invoke)cached_property)CompositorUpdate)
active_appactive_message_pump)message_hook)dispatch_key)	NoHandlerextract_handler_actions)generate_datetime_filename)CSSPathType_css_path_type_as_list_make_path_object_relative)AnimationLevel)wait_for_idle)ActionParseResult
SkipAction)AwaitComplete)AwaitRemove)BindingBindingsMapBindingTypeKeymap)CommandListItemCommandPaletteProviderSimpleProvider)compose)Content)StylesheetError)	NoMatches)RulesMap
Stylesheet)DOMNodeNoScreen)Driver)NoWidget)FeatureFlagparse_features)FileMonitor)ANSIToTruecolor	DimFilter
MonochromeNoColor)OffsetRegionSize)REPLACED_KEYS_character_to_key_get_unicode_name_from_key_normalize_key_list
format_key)CallbackTypePrune)NotificationNotificationsNotifySeverityLevel)Reactive)Blank)ActiveBindingScreenScreenResultCallbackTypeScreenResultTypeSystemModalScreen)Signal)BUILTIN_THEMESThemeThemeProvider)Timer)SupportsVisualVisual)
AwaitMountWidget)	ToastRack)NoActiveWorkerget_current_worker)WorkerManagerDevtoolsClient)	CoroutineLiteralSelf	TypeAlias)MessageTarget)	WrongType)
LineFilter)MessagePilotSystemCommandsProvider)
MountErrorwin32always)   
   r   z(RenderableType | Visual | SupportsVisualr   RenderResultz4Callable[[Pilot[object]], Coroutine[Any, Any, None]]AutopilotCallbackTypez0Callable[[], Awaitable[Any]] | Callable[[], Any]CommandCallback
ScreenTypeboundc                  D    e Zd ZU dZded<   	 ded<   	 ded<   	 dZded	<   y
)SystemCommandzDefines a system command used in the command palette (yielded from [`get_system_commands`][textual.app.App.get_system_commands]).strtitlehelpr   callbackTbooldiscoverN)__name__
__module____qualname____doc____annotations__r        C/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/app.pyr   r      s.     LJ4
I6<Hd;r   r   c                     ddl m}  | S )z\Callable to lazy load the system commands.

    Returns:
        System commands class.
    r   r   )textual.system_commandsr   r   s    r   get_system_commands_providerr      s     ?!!r   c                      e Zd ZdZy)AppErrorz.Base class for general App related exceptions.Nr   r   r   r   r   r   r   r   r          8r   r   c                      e Zd ZdZy)ActionErrorz.Base class for exceptions relating to actions.Nr   r   r   r   r   r      r   r   r   c                      e Zd ZdZy)ScreenErrorz1Base class for exceptions that relate to screens.Nr   r   r   r   r   r      s    ;r   r   c                      e Zd ZdZy)ScreenStackErrorz>Raised when trying to manipulate the screen stack incorrectly.Nr   r   r   r   r   r      s    Hr   r   c                      e Zd ZdZy)	ModeErrorz+Base class for exceptions related to modes.Nr   r   r   r   r   r      s    5r   r   c                      e Zd ZdZy)InvalidModeErrorz-Raised if there is an issue with a mode name.Nr   r   r   r   r   r      s    7r   r   c                      e Zd ZdZy)UnknownModeErrorz7Raised when attempting to use a mode that is not known.Nr   r   r   r   r   r      s    Ar   r   c                      e Zd ZdZy)ActiveModeErrorz;Raised when attempting to remove the currently active mode.Nr   r   r   r   r   r      s    Er   r   c                      e Zd ZdZy)SuspendNotSupportedzRaised if suspending the application is not supported.

    This exception is raised if [`App.suspend`][textual.app.App.suspend] is called while
    the application is running in an environment where this isn't supported.
    Nr   r   r   r   r   r      s    r   r   c                      e Zd ZdZy)InvalidThemeErrorz$Raised when an invalid theme is set.Nr   r   r   r   r   r      s    .r   r   
ReturnTypeCallThreadReturnTypec                  (    e Zd ZdZddZddZddZy)		_NullFilez$A file-like where writes go nowhere.c                     y Nr   selftexts     r   writez_NullFile.write       r   c                     y r   r   r   s    r   flushz_NullFile.flush   r   r   c                     yNTr   r   s    r   isattyz_NullFile.isatty   s    r   Nr   r   returnNoner   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r      s    .r   r   c                  :    e Zd ZdZdd	dZd
dZddZddZddZy)_PrintCapturez"A file-like which captures output.c                     || _         || _        y)z^

        Args:
            app: App instance.
            stderr: Write from stderr.
        N)appstderr)r   r   r   s      r   __init__z_PrintCapture.__init__  s     r   c                R    | j                   j                  || j                         y)zkCalled when writing to stdout or stderr.

        Args:
            text: Text that was "printed".
        r   N)r   _printr   r   s     r   r   z_PrintCapture.write  s     	T[[1r   c                P    | j                   j                  | j                         y)z)Called when stdout or stderr was flushed.r   N)r   _flushr   r   s    r   r   z_PrintCapture.flush  s    t{{+r   c                     y)zPretend we're a terminal.Tr   r   s    r   r   z_PrintCapture.isatty       r   c                     y)zReturn invalid fileno.r   r   s    r   filenoz_PrintCapture.fileno"  s    r   NF)r   Appr   r   r   r   r   r   r   r   int)	r   r   r   r   r   r   r   r   r   r   r   r   r   r     s    ,2,
r   r   c                      e Zd ZU dZdZded<   	 ded<   dZi Zded<   	 d	Zded
<   	 i Z	ded<   	 dZ
ded<   	 dZded<   	 dZded<   dZded<   	 dZded<   	 dZded<   	 dZded<   	 dZded<   	 ehZded<   	 d Zded!<   	 dZded"<   	 d#Zded$<   	 d%Zded&<   	  ed'd(d)d*d+d,       ed-d.d+d/      gZd0ed1<   	 d2Zd3ed4<   	 d%Zd5ed6<   	 dZded7<   	 dZded8<   	 d9Zd:ed;<   	 dZded<<   	 g Z d=ed><   	 g Z!d=ed?<   	 d@ dA dB dC dD dE dF dGZ"dHedI<    e#dd+J      Z$dKedL<   	  e#dd+J      Z%dKedM<   	  e#dd+J      Z&	  e#e'jP                        Z)dKedN<   	  e#e*d+O      Z+	  e#e,d+O      Z-	  e#d+      Z.	 	 	 	 	 d=	 	 	 	 	 	 	 d> fdPZ/d?dQZ0e1d@dR       Z2e3dAdS       Z4dB fdTZ5dU Z6dCdVZ7dDdWZ8dEdXZ9e1dFdY       Z:e1dGdZ       Z;e1dHd[       Z<e1dId\       Z=e1dJd]       Z>e1dKd^       Z?dLd_Z@eAdMd`       ZBdBdaZCdBdbZDdNdOdcZEeAdMdd       ZFdPdeZGdfdddgeHddhdi	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dQdjZIdRdSdkZJe1d@dl       ZKe1d@dm       ZLe1d@dn       ZMe1d@do       ZNe1d@dp       ZOe1d@dq       ZPe1dTdr       ZQe1dTds       ZRe1dKdt       ZSe1dUdu       ZT	 	 	 dV	 	 	 	 	 	 	 dWdvZUe1dXdw       ZVe1dYdx       ZWdZdyZXdFdzZYd[d{ZZd\d|Z[d\d}Z\d]d~Z]d^dZ^d_dZ_e1d`d       Z`e1dad       ZadbdZbd_dZcdBdZddcdZedcdZfe1ddd       ZgdcdZhdedZidfdZje1dgd       Zke1dhd       Zle1did       Zme1djd       Zne1djd       ZodkdZpe1dld       Zq	 	 	 	 	 	 	 	 	 	 dmdZrdndZsdodZt	 	 	 	 	 	 	 	 dpdZudBdZv	 dq	 	 	 	 	 drdZwdd+d	 	 	 	 	 dsdZx	 	 	 dt	 	 	 	 	 	 	 dudZy	 	 	 dt	 	 	 	 	 	 	 dvdZz	 dw	 	 	 	 	 dxdZ{dBdZ|dddd	 	 	 	 	 	 	 	 	 	 	 dydZ}dzdZ~d{dZd|d}dZd|d~dZ	 d	 	 	 	 	 	 	 ddZddZeddd+d+dd	 	 	 	 	 	 	 	 	 	 	 dd       Zd+d+d+dddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd+d+d+ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdBdZddZ ede      Zeredd       Ze	 	 	 	 	 	 dd       Z	 d	 	 	 	 	 ddZeredd       Ze	 	 	 	 	 	 dd       Z	 d	 	 	 	 	 ddZddZddZddd	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 ddZddZddZddZddZddZedd       ZeddÄ       Ze	 d	 	 	 	 	 ddĄ       Ze	 d	 	 	 	 	 ddń       Z	 d	 	 	 	 	 ddƄZddǄZddȄZddɄZer*e	 	 d	 	 	 	 	 	 	 ddʄ       Ze	 	 d	 	 	 	 	 	 	 dd˄       Z	 	 d	 	 	 	 	 	 	 dd̄Zere	 	 	 	 dd̈́       Zedd΄       Z	 	 	 	 ddτZddЄZddфZdd҄ZddӄZddԄZdRddՄZ	 	 	 	 	 	 ddքZddׄZdd؄ZddلZddڄZdBdۄZdBd܄Z	 	 	 	 	 	 	 	 	 	 dd݄Zdބ Z	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd߄Zd@dZdBdZdBdZdBdZdBdZ	 	 	 	 	 	 	 	 	 	 ddZdddd	 	 	 	 	 	 	 	 	 	 	 ddZddZd ZddZddZdBdZdBdZdBdZdd+d+d	 	 	 	 	 	 	 ddZdRddZddZdBdZddZdBdZe1dd       ZĐddZŐd|ddZƐdBdZeȐdd       ZɐddZʐddZ	 	 	 	 	 	 ddZ̐d fdZe1d@d       Z	 d	 	 	 	 	 	 	 dd Z	 	 	 	 	 	 ddZ	 	 dq	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 dÐdZӐdĐdZԐdŐdZՐdƐdZ֐dǐdZאdȐd	Zؐdɐd
ZdddʐdZڐdːdZېddZܐdBdZݐdBdZސd̐dZߐd͐dZd͐dZdBdZdΐdZdBdZdϐdZdϐdZdϐdZdBdZdBdZdBdZdBdZdBdZ	 d	 	 	 	 	 	 	 dѐd Z	 	 	 	 dҐd!ZdBd"ZdBd#ZdBd$ZdBd%Zddddd&	 	 	 	 	 	 	 	 	 	 	 dӐd'ZdԐd(ZdRdՐd)ZdBd*ZdBd+ZdBd,Z eej                        dBd-       ZeAd֐d.       ZdBd/Zdd0dאd1Zddd2dddd3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dؐd4Z ddd2ddd5	 	 	 	 	 	 	 	 	 	 	 	 	 dِd6Zdddd7	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dڐd8Z eej                        dېd9       Z eej                        dېd:       Z eej                        dܐd;       Z
dBd<Z xZS (  r   z(The base class for Textual Applications. zClassVar[str]CSSDEFAULT_CSSa%  
    App {
        background: $background;
        color: $foreground;

        &:ansi {
            background: ansi_default;
            color: ansi_default;

            .-ansi-scrollbar {
                scrollbar-background: ansi_default;
                scrollbar-background-hover: ansi_default;
                scrollbar-background-active: ansi_default;
                scrollbar-color: ansi_blue;
                scrollbar-color-active: ansi_bright_blue;
                scrollbar-color-hover: ansi_bright_blue;    
                scrollbar-corner-color: ansi_default;           
            }

            .bindings-table--key {
                color: ansi_magenta;
            }
            .bindings-table--description {
                color: ansi_default;
            }

            .bindings-table--header {
                color: ansi_default;
            }

            .bindings-table--divider {
                color: transparent;
                text-style: dim;
            }
        }

        /* When a widget is maximized */
        Screen.-maximized-view {                    
            layout: vertical !important;
            hatch: right $panel;
            overflow-y: auto !important;
            align: center middle;
            .-maximized {
                dock: initial !important;                
            }
        }
        /* Fade the header title when app is blurred */
        &:blur HeaderTitle {           
            text-opacity: 50%;           
        }
    }
    *:disabled:can-focus {
        opacity: 0.7;
    }
    z/ClassVar[dict[str, str | Callable[[], Screen]]]MODES_defaultDEFAULT_MODEz.ClassVar[dict[str, Callable[[], Screen[Any]]]]SCREENS*zClassVar[str | None]
AUTO_FOCUSTzClassVar[bool]ALLOW_SELECTN
str | None
_BASE_PATHzClassVar[CSSPathType | None]CSS_PATHTITLE	SUB_TITLEENABLE_COMMAND_PALETTE   zClassVar[float]NOTIFICATION_TIMEOUTz<ClassVar[set[type[Provider] | Callable[[], type[Provider]]]]COMMANDSzctrl+pCOMMAND_PALETTE_BINDINGCOMMAND_PALETTE_DISPLAYFooterALLOW_IN_MAXIMIZED_VIEWg      ?CLICK_CHAIN_TIME_THRESHOLDzctrl+qquitQuitz.Quit the app and return to the command prompt.F)tooltipshowpriorityzctrl+c	help_quit)r  systemzClassVar[list[BindingType]]BINDINGSg      @float | NoneCLOSE_TIMEOUTfloatTOOLTIP_DELAYBINDING_GROUP_TITLEESCAPE_TO_MINIMIZE   zClassVar[int]INLINE_PADDINGSUSPENDED_SCREEN_CLASSz&ClassVar[list[tuple[int, str]]] | NoneHORIZONTAL_BREAKPOINTSVERTICAL_BREAKPOINTSc                    | j                   S r   	app_focusr   s    r   <lambda>zApp.<lambda>  s
    S]] r   c                    | j                    S r   r&  r(  s    r   r)  zApp.<lambda>  s    - r   c                .    | j                   j                  S r   current_themedarkr(  s    r   r)  zApp.<lambda>  s    C--22 r   c                0    | j                   j                   S r   r,  r(  s    r   r)  zApp.<lambda>  s    !2!2!7!77 r   c                    | j                   S r   )	is_inliner(  s    r   r)  zApp.<lambda>  s
    cmm r   c                    | j                   S r   )
ansi_colorr(  s    r   r)  zApp.<lambda>  s
    CNN r   c                    | j                   S r   )no_colorr(  s    r   r)  zApp.<lambda>  s
    s|| r   )focusblurr.  lightinlineansinocolorz/ClassVar[dict[str, Callable[[App[Any]], bool]]]_PSEUDO_CLASSES)computezReactive[str]r   	sub_titletheme)initc                   t               | _        t        |   | j                         t        t        j                  dd            | _        i | _	        	 t        j                         D ]  }| j                  |        | j                  j                  r| j                  n| j                   }| j#                  t$        j&                  |       t)        ||       g| _        t-        t        j.                        }|j1                  dd      du| _        | j2                  r9| j*                  j5                  | j&                  r
t7               n	t9                      t:        j<                  j?                  d      D ]I  }|jA                         jC                         }	|	dk(  s'| j*                  j5                  tE                      K tG        t:        jH                  tK               d	d
d
d
|d	d
d

      | _&        tO        |       | _(        tG        d
d
d	      | _)        |xs | jU                         | _+        | jX                  g i| _-        	 | jX                  | _.        	 d
| _/        d| _0        	 d| _1        	 d| _2        d| _3        g | _4        h d| _5        tm        |       | _7        | jn                  jq                  |       | _9        tu        dd      | _;        d| _<        	 d| _=        	 d| _>        	 d| _?        	 tu        dd      | _@        	 tu        dd      | _A        	 d| _B        	 | j                  | j                  n| j                  j                   | _F        	 | j                  | j                  nd| _H        	 | j                  | _J        	 t        | j                  |       | _M        d
| _N        i | _O        	 t        | j                               | _R        |xs | j                  }|t        |      ng D cg c]  }t        ||        }
}|
| _V        t               | _X        i | _Y        d| _Z        	 d| _[        	 i | _\         | j                  j                  d#i | j                   | j                  j                         | _a        	 g | _b        g | _c        d
| _d        d| _e        d| _f        d| j                  v r?	 ddlgmh} ddlimj}  |t:        j                        | _e         || j                        | _f        d| _m        d| _n        	 d| _o        	 d
| _p        d
| _q        d
| _r        |s| j                  r t        | j                  | j                        nd| _v        d| _w        d
| _x        d| _y        t               | _{        t               | _}        	 t        | d
      | _        	 t        | d	      | _        	 t        j                  | _        	 t        j                  | _        	 t        | d      | _        	 t        | d      | _        	 t        | d      | _        	 | j                  | j                  j                  dd
       | j                  | j                  j                   dd
       t:        j                  | _        	 d| _        	 d| _        	 d| _        	 d| _        d| _        	 d| _        	 d
| _        	 d| _        	 | j                  rk| j*                  D ]  \  }}|j,                  dv s y | j*                  j/                  t1        | j2                  dd d
| j4                  d	d!"             yyc c}w # t        $ r Y Vw xY w)$a  Create an instance of an app.

        Args:
            driver_class: Driver class or `None` to auto-detect.
                This will be used by some Textual tools.
            css_path: Path to CSS or `None` to use the `CSS_PATH` class variable.
                To load multiple CSS files, pass a list of strings or paths which
                will be loaded in order.
            watch_css: Reload CSS if the files changed. This is set automatically if
                you are using `textual run` with the `dev` switch.
            ansi_color: Allow ANSI colors if `True`, or convert ANSI colors to to RGB if `False`.

        Raises:
            CssPathError: When the supplied CSS path(s) are an unexpected type.
        )classesTEXTUALr   enabledNO_COLORN,dimTF)
color_systemfilemarkup	highlightemojilegacy_windows_environforce_terminalsafe_box	soft_wrap)rK  rL  r   >   r   screenfocusedr   r   r(  )	variablesg      @g       @devtoolsr   )StdoutRedirectorr   ztheme-changedzapp-suspendz
app-resume
-dark-modeupdate-light-mode>   app.command_palettecommand_paletter]  palettezOpen the command palette)r  key_displayr  r  r   )r   _start_timesuperr   DEFAULT_CLASSESre   osgetenvfeatures_registered_themesr   valuesregister_themer-  r.  ansi_theme_darkansi_theme_lightset_reactiver   r3  rg   _filtersdictenvironpopr5  appendrj   ri   r2   FILTERSsplitlowerstriprh   r$   COLOR_SYSTEMr   consoler   _workerserror_consoleget_driver_classdriver_classr   _screen_stacks_current_mode_sync_available
mouse_over
hover_overmouse_captured_driver_exit_renderables_action_targetsr9   	_animatorbind_animaterk   mouse_position_mouse_down_widget_click_chain_last_offset_click_chain_last_time_chained_clicks_previous_cursor_positioncursor_position
_exceptionr  	__class__r   r   r  r>  r	  use_command_paletter.   _log_logger_css_has_errorstheme_variablesr_   get_css_variables
stylesheetr  rJ   rK   css_pathr"   	_registry_keymapscroll_sensitivity_xscroll_sensitivity_y_installed_screensrZ  r   r   copy_modes_compose_stacks	_composed_recompose_requiredrV  _devtools_redirectortextual_dev.clientr   textual_dev.redirect_outputrW  DEVTOOLS_HOSTImportError_loop_return_value_return_code_exit_disable_tooltips_disable_notificationsdebugrf   _on_css_changecss_monitor_screenshot
_dom_ready_batch_countrv   _notificationsr!   _capture_printr   _capture_stdout_capture_stderrsys
__stdout___original_stdout
__stderr___original_stderrr   theme_changed_signalapp_suspend_signalapp_resume_signal	set_classTEXTUAL_ANIMATIONSanimation_level_last_focused_on_app_blur_previous_inline_height_resize_event_size_css_update_count
_clipboardsupports_smooth_scrolling_compose_screen	_bindingsaction_add_bindingrR   r  r  )r   rz  r  	watch_cssr3  r?  
ansi_themern  filter_namefilter	css_pathsr   rW  _keybindingr  s                  r   r   zApp.__init__#  s   , (>!5!560>ryyTV?W0X46	. $**, 	'E&	' %)$6$6$;$;D  AVAV 	 	#..*5JJ?+
 rzz"J5TA==MM  doo:<P$,,2237 	2K &&(..0F$$Y[1	2
 "// 
 &d+$EU4P(CD,A,A,C=A=N=NPR<S*"&"3"3-$)-2)-B-1&*79;!$++D1$Ql15[7;%I48#6$%J)/1&*%a|	8
 -1	M **0DJJ9P9P8Q 	
	 ,0>>+E2
	 *.)D)D 	 diiT2$/19 %t/E/E/GH,t}} 5=4H&x0b
 'x6
	 
 "+29! ,/!T+.!RLN&&&66=AZZ__=NI35-/#( /3=A!&L=H
 !/y/F/F G,<T]],K)7;
04J(,I
!&&+# DJJ t':':; 	
 (,+o  	 	[,T%@@,T$?@ #B #B39$3P!	
 06dM/J	 /5T<.H	 	t))..UK4--222M%P/8/K/K	
 9=&	 48$-373"&
&'2!*/4&9.21&&!% g>>%OO ++44)!"$($@$@!% :
 'K
D  s   +\/,\4 4	] ]c                Z    | j                   D cg c]  }|j                  s| c}S c c}w )zGet currently enabled line filters.

        Returns:
            A list of [LineFilter][textual.filters.LineFilter] instances.
        )rl  rE  )r   r  s     r   get_line_filterszApp.get_line_filtersT  s"     &*]]E6fnnEEEs   ((c                N    | j                   duxr | j                   j                  S )z%Is the app connected to the devtools?N)rV  is_connectedr   s    r   _is_devtools_connectedzApp._is_devtools_connected\  s"     }}D(GT]]-G-GGr   c                *    t        j                         S )zBAn event that will be set when the first exception is encountered.)asyncioEventr   s    r   _exception_eventzApp._exception_eventa  s     }}r   c           
     \   d| j                   fd| j                  ffD ]~  \  }}|j                         D ]f  \  }}t        |t              rt        |      r#t        |t              r't        | dt        |      j                   d|d      t        d|        t        | 0  |i |S )Nr   r   zL should contain a Screen type or callable, not an instance (got instance of  for )z#expected a callable or string, got )r   r   items
isinstancer   callabler|   
ValueErrortyper   	TypeErrorra  __init_subclass__)clsargskwargsvariable_namescreen_collectionscreen_namescreen_objectr  s          r   r  zApp.__init_subclass__f  s    $cii 1
 	,M, /@.E.E.G 	*]"=#6(=:Q!-8(,o .115m1D1M1M0NeT_Sbbce  $=m=NO 			 w($9&99r   c                ~    | j                    | j                   | j                   t        j                         | _        y)z|Initialize threading primitives for the current thread.

        https://github.com/Textualize/textual/issues/5845

        N)_message_queue_mounted_eventr  	threading	get_ident
_thread_idr   s    r   _thread_initzApp._thread_initx  s/     	#--/r   c                    | j                   S )z@When querying from the app, we want to query the default screen.)default_screenr   s    r   _get_dom_basezApp._get_dom_base  s    """r   c                    t        |      S )z'Make sure the title is set to a string.r   )r   r   s     r   validate_titlezApp.validate_title  s    5zr   c                    t        |      S )z*Make sure the subtitle is set to a string.r  )r   r>  s     r   validate_sub_titlezApp.validate_sub_title  s    9~r   c                J    | j                   | j                  S | j                   S )zThe default screen instance.)r  rS  r   s    r   r  zApp.default_screen  s$     #22:t{{T@T@TTr   c                    | j                   S )zjThe [worker](/guide/workers/) manager.

        Returns:
            An object to manage workers.
        )rw  r   s    r   workerszApp.workers  s     }}r   c                    | j                   S )zThe return value of the app, or `None` if it has not yet been set.

        The return value is set when calling [exit][textual.app.App.exit].
        )r  r   s    r   return_valuezApp.return_value  s     !!!r   c                    | j                   S )a  The return code with which the app exited.

        Non-zero codes indicate errors.
        A value of 1 means the app exited with a fatal error.
        If the app hasn't exited yet, this will be `None`.

        Example:
            The return code can be used to exit the process via `sys.exit`.
            ```py
            my_app.run()
            sys.exit(my_app.return_code)
            ```
        )r  r   s    r   return_codezApp.return_code  s        r   c                n    	 t        d t        | j                        D              fS # t        $ r Y yw xY w)a  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:
            A sequence of widgets.
        c              3  @   K   | ]  }t        |t              s|  y wr   )r  r   ).0rS  s     r   	<genexpr>zApp.children.<locals>.<genexpr>  s#      %f.?@ s   r   )nextreversed_screen_stackStopIterationr   s    r   childrenzApp.children  sE    		 "*4+=+=">    		s   %( 	44c                    | j                   S )zThe value of the local clipboard.

        Note, that this only contains text copied in the app, and not
        text copied from elsewhere in the OS.
        )r  r   s    r   	clipboardzApp.clipboard  s     r   c                    t        |      }t        |      }|r&t        j                  |d|j                  d            S |S )zFormat the title for display.

        Args:
            title: The title.
            sub_title: The sub title.

        Returns:
            Content instance with title and subtitle.
        )u    — rH  rH  )r[   assemblestylize)r   r   r>  title_contentsub_title_contents        r   format_titlezApp.format_title  sJ      #I.## !))%0  ! r   c              #     K   | j                          	 d | j                          y# | j                          w xY ww)zEA context manager to suspend all repaints until the end of the batch.N)_begin_batch
_end_batchr   s    r   batch_updatezApp.batch_update  s0      		OODOOs   >) >;>c                .    | xj                   dz  c_         y)zBegin a batch update.r   N)r  r   s    r   r  zApp._begin_batch  s    Qr   c                    | xj                   dz  c_         | j                   dk\  sJ d       | j                   s| j                          yy)zEnd a batch update.r   r   z+This won't happen if you use `batch_update`N)r  
check_idler   s    r   r  zApp._end_batch  sE    Q  A%T'TT%  OO !r   c                Z      j                          d fd} j                  ||d       y)zDelay updates for a short period of time.

        May be used to mask a brief transition.
        Consider this method only if you aren't able to use `App.batch_update`.

        Args:
            delay: Delay before updating.
        c                 t     j                           j                  s j                  j                          yy)z&Re-enable updates, and refresh screen.N)r  r  rS  refreshr   s   r   	end_batchz#App.delay_update.<locals>.end_batch	  s+    OO$$##% %r   delay_updatenameNr   )r  	set_timer)r   delayr  s   `  r   r   zApp.delay_update  s*     		& 	uin=r   c              #    K   t        j                  |       }t        j                  |       }	 d t        j                  |       t        j                  |       y# t        j                  |       t        j                  |       w xY ww)z#Context manager to set ContextVars.N)rB   setrC   reset)r   app_reset_tokenmessage_pump_reset_tokens      r   _contextzApp._context  sl      %...#6#:#:4#@ 	.%%&>?_-  %%&>?_-s   +BA +B,B		Bc                X    | j                   D ]  }t        |t              s| |_         y)z@Enable or disable the truecolor filter when the reactive changesN)rl  r  rg   rE  )r   r3  r  s      r   _watch_ansi_colorzApp._watch_ansi_color  s(    mm 	0F&/2%/	0r   .g        fullfinal_valuedurationspeedr$  easingon_completelevelc               8    | j                  |||||||||		       y)a  Animate an attribute.

        See the guide for how to use the [animation](/guide/animation) system.

        Args:
            attribute: Name of the attribute to animate.
            value: The value to animate to.
            final_value: The final value of the animation.
            duration: The duration (in seconds) of the animation.
            speed: The speed of the animation.
            delay: A delay (in seconds) before the animation starts.
            easing: An easing method.
            on_complete: A callable to invoke when the animation is finished.
            level: Minimum level required for the animation to take place (inclusive).
        r.  N)r  )
r   	attributevaluer/  r0  r1  r$  r2  r3  r4  s
             r   animatezApp.animate"  s0    8 	## 	 
	
r   c                Z   K   | j                   j                  | ||       d{    y7 w)a+  Stop an animation on an attribute.

        Args:
            attribute: Name of the attribute whose animation should be stopped.
            complete: Should the animation be set to its final value?

        Note:
            If there is no animation scheduled or running, this is a no-op.
        N)r  stop_animation)r   r6  completes      r   r:  zApp.stop_animationJ  s$      nn++D)XFFFs   !+)+c                     y)z#Is this a root node (i.e. the App)?Tr   r   s    r   is_dom_rootzApp.is_dom_rootV  r   r   c                     y)z/Is this node linked to the app through the DOM?Tr   r   s    r   is_attachedzApp.is_attached[  r   r   c                B    d| j                   v xs t        j                  S )zIs debug mode enabled?r  )re  r2   DEBUGr   s    r   r  z	App.debug`  s     $--':9??:r   c                J    | j                   dS | j                   j                  S )zIs the app running in 'headless' mode?

        Headless mode is used when running tests with [run_test][textual.app.App.run_test].
        F)r  is_headlessr   s    r   rC  zApp.is_headlesse  s"     ,uJ$,,2J2JJr   c                J    | j                   dS | j                   j                  S )z$Is the app running in 'inline' mode?F)r  r1  r   s    r   r1  zApp.is_inlinem  s"     ,uH$,,2H2HHr   c                J    | j                   dS | j                   j                  S )z/Is the app running in 'web' mode via a browser?F)r  is_webr   s    r   rF  z
App.is_webr  s"     ,uE$,,2E2EEr   c                P    | j                   | j                     j                         S )zA snapshot of the current screen stack.

        Returns:
            A snapshot of the current state of the screen stack.
        )r{  r|  r  r   s    r   screen_stackzApp.screen_stackw  s$     ""4#5#56;;==r   c                4    | j                   | j                     S )zA reference to the current screen stack.

        Note:
            Consider using [`screen_stack`][textual.app.App.screen_stack] instead.

        Returns:
            A reference to the current screen stack.
        )r{  r|  r   s    r   r
  zApp._screen_stack  s     ""4#5#566r   c                    | j                   S )z&The name of the currently active mode.)r|  r   s    r   current_modezApp.current_mode  s     !!!r   c           	         t        | j                   }| j                  }t        |j                  ||j
                  d|j                  |j                  |j                        S )zGet options for the Rich console.

        Returns:
            Console options (same object returned from `console.options`).
        r   )
max_heightsizerN  	min_width	max_widthencodingis_terminal)	r%   rN  rv  r&   heightrN  widthrQ  rR  )r   rN  rv  s      r   console_optionszApp.console_options  sW     !$)),,,{{"11jj%%++
 	
r   c                    d| _         || _        || _        | j                  t	        j
                                |r| j                  j                  |       yy)zExit the app, and return the supplied result.

        Args:
            result: Return value.
            return_code: The return code. Use non-zero values for error codes.
            message: Optional message to display on exit.
        TN)r  r  r  post_messager5   ExitAppr  rp  )r   resultr  messages       r   exitzApp.exit  sN     
#'(**,-""))'2 r   c                P    | j                   j                  }||j                  ry|S )zThe widget that is focused on the currently active screen, or `None`.

        Focused widgets receive keyboard input.

        Returns:
            The currently focused widget, or `None` if nothing is focused.
        N)rS  rT  loading)r   rT  s     r   rT  zApp.focused  s'     ++%%7??r   c                .    | j                   j                  S )an  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:
            A dict that maps keys on to binding information.
        )rS  active_bindingsr   s    r   r_  zApp.active_bindings  s     {{***r   c              #     K    j                   st        dd j                         t        dd j                         |j	                  d      rt        dd j
                         nt        dd	 j                         |j                  t        dd|j                         n;|j                  /|j                  j                  rt        dd|j                         t        dd fd       y
w)a  A generator of system commands used in the command palette.

        Args:
            screen: The screen where the command palette was invoked from.

        Implement this method in your App subclass if you want to add custom commands.
        Here is an example:

        ```python
        def get_system_commands(self, screen: Screen) -> Iterable[SystemCommand]:
            yield from super().get_system_commands(screen)
            yield SystemCommand("Bell", "Ring the bell", self.bell)
        ```

        !!! note
            Requires that [`SystemCommandsProvider`][textual.system_commands.SystemCommandsProvider] is in `App.COMMANDS` class variable.

        Yields:
            [SystemCommand][textual.app.SystemCommand] instances.
        zChange themezChange the current themezQuit the applicationz(Quit the application as soon as possible	HelpPanelzHide keys and help panelz#Hide the keys and widget help panelzShow keys and help panelz@Show help for the focused widget and a summary of available keysNMinimizez.Minimize the widget and restore to normal sizeMaximizezMaximize the focused widgetzSave screenshotz.Save an SVG 'screenshot' of the current screenc                 <     j                  d j                        S )Ng?)r#  deliver_screenshotr   s   r   r)  z)App.get_system_commands.<locals>.<lambda>  s    DNN3(?(?@ r   )r3  r   action_change_themeaction_quitqueryaction_hide_help_panelaction_show_help_panel	maximizedaction_minimizerT  allow_maximizeaction_maximizer   rS  s   ` r   get_system_commandszApp.get_system_commands  s    * *(( 
 "6
 	
 <<$*5++   *R++  '@&& 
 ^^'FNN,I,I96;Q;Q  <@
 	
s   C7C:c                    t        d      S )a4  Get the default screen.

        This is called when the App is first composed. The returned screen instance
        will be the first screen on the stack.

        Implement this method if you would like to use a custom Screen as the default screen.

        Returns:
            A screen instance.
        r   id)r|   r   s    r   get_default_screenzApp.get_default_screen  s     $$r   c              #  $   K   dE d{    y7 w)zgYield child widgets for a container.

        This method should be implemented in a subclass.
        r   Nr   r   s    r   rZ   zApp.compose   s     
 s   c                    i S )a  Get the default values for the `variables` used in a theme.

        If the currently specified theme doesn't define a value for a variable,
        the value specified here will be used as a fallback.

        If a variable is referenced in CSS but does not appear either here
        or in the theme, the CSS will fail to parse on startup.

        This method allows applications to define their own variables, beyond
        those offered by Textual, which can then be overridden by a Theme.

        Returns:
            A mapping of variable name (e.g. "my-button-background-color") to value.
            Values can be any valid CSS value, e.g. "red 50%", "auto 90%",
            "#ff0000", "rgb(255, 0, 0)", etc.
        r   r   s    r   get_theme_variable_defaultszApp.get_theme_variable_defaults'  s	    " 	r   c                    | j                   }|j                         j                         }i ||j                  }| j	                         }i ||}|| _        |S )zGet a mapping of variables used to pre-populate CSS.

        May be implemented in a subclass to add new CSS variables.

        Returns:
            A mapping of variable name to value.
        )r-  to_color_systemgeneraterU  rw  r  )r   r?  rU  r  combined_variabless        r   r  zApp.get_css_variables:  sg     "" ))+446	6y6U__6	::<==9=1!!r   c                    |j                  d      D cg c]  }|j                          }}|D ]!  }|| j                  v s| j                  |   c S  yc c}w )a  Get a theme by name.

        Args:
            theme_name: The name of the theme to get. May also be a comma
                separated list of names, to pick the first available theme.

        Returns:
            A Theme instance and None if the theme doesn't exist.
        rG  N)rr  rt  available_themes)r   
theme_nametokentheme_namess       r   	get_themezApp.get_themeN  sa     3=2B2B32GHu{{}HH% 	9JT222,,Z88	9 	 Is   Ac                6    || j                   |j                  <   y)aK  Register a theme with the app.

        If the theme already exists, it will be overridden.

        After registering a theme, you can activate it by setting the
        `App.theme` attribute. To retrieve a registered theme, use the
        `App.get_theme` method.

        Args:
            theme: The theme to register.
        N)rf  r"  r   r?  s     r   rh  zApp.register_theme^  s     /4

+r   c                <    || j                   v r| j                   |= yy)zuUnregister a theme with the app.

        Args:
            theme_name: The name of the theme to unregister.
        Nrf  )r   r~  s     r   unregister_themezApp.unregister_themel  s%     000''
3 1r   c                    i | j                   S )zAll available themes (all built-in themes plus any that have been registered).

        A dictionary mapping theme names to Theme instances.
        r  r   s    r   r}  zApp.available_themesu  s     +$))**r   c                j    | j                  | j                        }|| j                  d      }|J |S )Ntextual-dark)r  r?  r  s     r   r-  zApp.current_theme}  s8    tzz*=NN>2E   r   c                D    || j                   vrd|d}t        |      |S )NzTheme z] has not been registered. Call 'App.register_theme' before setting the 'App.theme' attribute.)r}  r   )r   r~  rZ  s      r   _validate_themezApp._validate_theme  s;    T222 'V V  $G,,r   c                   | j                   }|j                  }|dk(  | _        | j                  |dd       | j                  | dd       | j	                  | j
                         | j                          | j                  t        | j                  d             | j                  | j                  j                  |       y)zsApply a theme to the application.

        This method is called when the theme reactive attribute is set.
        ztextual-ansirX  FrY  r[  r8  N)r-  r.  r3  r  _refresh_truecolor_filterr  _invalidate_css	call_nextr   refresh_cssr  publish)r   r~  r?  r.  s       r   _watch_themezApp._watch_theme  s    
 ""zz$6t\%84xu=&&t7wt//?@t0088%@r   c                .    | xj                   dz  c_         y)z(Invalidate CSS, so it will be refreshed.r   N)r  r   s    r   r  zApp._invalidate_css  s    !#r   c                    | j                   j                  r=| j                  |       | j                          | j	                  | j
                         y y r   r-  r.  r  r  r  r  r  s     r   watch_ansi_theme_darkzApp.watch_ansi_theme_dark  sB    ""**51  "NN4++, #r   c                    | j                   j                  s=| j                  |       | j                          | j	                  | j
                         y y r   r  r  s     r   watch_ansi_theme_lightzApp.watch_ansi_theme_light  sB    !!&&**51  "NN4++, 'r   c                ^    | j                   j                  r| j                  S | j                  S )zThe ANSI TerminalTheme currently being used.

        Defines how colors defined as ANSI (e.g. `magenta`) inside Rich renderables
        are mapped to hex codes.
        )r-  r.  ri  rj  r   s    r   r  zApp.ansi_theme  s.     %)$6$6$;$;D  	
AEAVAV	
r   c                    | j                   }t        |      D ]2  \  }}t        |t              st        || j                         ||<    y y)zUpdate the ANSI to Truecolor filter, if available, with a new theme mapping.

        Args:
            theme: The new terminal theme to use for mapping ANSI to truecolor.
        rD  N)rl  	enumerater  rg   r3  )r   r?  filtersindexr  s        r   r  zApp._refresh_truecolor_filter  sI     --&w/ 	ME6&/2!0DOO@S!T	r   c                8   t         j                  }|o|j                  d      \  }}}t        j                  |      }t        ||      }t        j                  |      rt        |t              st        d|d|d      |S t        r
ddlm} |}|S ddlm} |}|S )zGet a driver class for this platform.

        This method is called by the constructor, and unlikely to be required when
        building a Textual app.

        Returns:
            A Driver class which manages input and display.
        :zUnable to import z; z is not a Driver class r   )WindowsDriver)LinuxDriver)r2   DRIVER	partition	importlibimport_modulegetattrinspectisclass
issubclassrb   RuntimeErrorWINDOWStextual.drivers.windows_driverr  textual.drivers.linux_driverr  )	r   driver_importmodule_import_driver_symboldriver_modulerz  r  r  s	            r   ry  zApp.get_driver_class  s     "(($ /<.E.Ec.J+M1m%33MBM"=-@L??<0
f9 #''8<:JJab   D(L
  A&Lr   c              #    K   d| j                   f d| j                  d f | j                  rd| j                  f | j                  rdt	        | j                        f | j
                  }|rdt	        |      f y y w)Nr   rs  r"  rB  pseudo_classes)r   rs  r"  rB  r&  r  )r   r  s     r   __rich_repr__zApp.__rich_repr__  sz     tzz!!DGGT!!99$))##<<S...,,"C$777 s   BBc                    | j                   S )zThe animator object.)r  r   s    r   animatorzApp.animator  s     ~~r   c                    	 | j                   d   S # t        $ r t        d| j                        dt        $ r t        d      dw xY w)zThe current active screen.

        Returns:
            The currently active (visible) screen.

        Raises:
            ScreenStackError: If there are no screens on the stack.
        r   No known mode NzNo screens on stack)r
  KeyErrorr   r|  
IndexErrorr   r   s    r   rS  z
App.screen  s]    	D%%b)) 	V"^D4F4F3I#JKQUU 	D"#89tC	Ds	    7Ac                    g }t        | j                  dd       D ]8  }|j                  |       |j                  j                  j
                  dk(  s8 n |ddd   }|S )zoA list of screens that may be visible due to background opacity (top-most first, not including current screen).Nr   r   )r	  r
  rp  styles
backgrounda)r   screensrS  background_screenss       r   _background_screenszApp._background_screens
  sg     !#t11#267 	FNN6"}}''))Q.	 %TrT]!!r   c                    | j                   | j                   S | j                  0| j                  j                   | j                  j                   \  }}n| j                  j                  \  }}t	        ||      S )zVThe size of the terminal.

        Returns:
            Size of the terminal.
        )r  r  rv  rN  rm   )r   rT  rS  s      r   rN  zApp.size  sd     ::!::<<#(:(:(F LL..ME6 LL--ME6E6""r   c                r    	 | j                   j                  S # t        t        f$ r | j                  cY S w xY w)z+Get the viewport size (size of the screen).)rS  rN  r   ra   r   s    r   viewport_sizezApp.viewport_size$  s5    	;;### (+ 	99	s    66c                X    | j                   t        fd| j                  D              S )zkGet the inline height (height when in inline mode).

        Returns:
            Height in lines.
        c              3  @   K   | ]  }|j                          y wr   )_get_inline_height)r  rS  rN  s     r   r  z)App._get_inline_height.<locals>.<genexpr>3  s     Tv6,,T2Ts   )rN  maxr
  )r   rN  s    @r   r  zApp._get_inline_height,  s%     yyTASASTTTr   c                    | j                   S )zThe textual logger.

        Example:
            ```python
            self.log("Hello, World!")
            self.log(self.tree)
            ```

        Returns:
            A Textual logger.
        )r  r   s    r   r4   zApp.log5  s     ||r   c                "   | j                   }||j                  sy|j                  t        j                  j                  kD  r|j
                  sy	 ddlm} t        |      dk(  r|s|j                   |||      ||       ydj                  d |D              }|r1dj                  d |j                         D              }	|r| d|	 n|	}|j                   |||      ||       y# t        $ r}
| j                  |
       Y d}
~
yd}
~
ww xY w)	av  Write to logs or devtools.

        Positional args will be logged. Keyword args will be prefixed with the key.

        Example:
            ```python
            data = [1,2,3]
            self.log("Hello, World", state=data)
            self.log(self.tree)
            self.log(locals())
            ```

        Args:
            verbosity: Verbosity level 0-3.
        Nr   )DevtoolsLogr   )caller c              3  2   K   | ]  }t        |        y wr   r  )r  args     r   r  zApp._log.<locals>.<genexpr>m  s     !>s#c(!>   c              3  0   K   | ]  \  }}| d |  yw)=Nr   )r  keyr7  s      r   r  zApp._log.<locals>.<genexpr>o  s$      */9sE3%q	**s   )rV  r  r7  r0   NORMALverboser  r  lenr4   joinr  	Exception_handle_exception)r   group	verbosity_textual_calling_frameobjectsr  rV  r  output
key_valueserrors              r   r  zApp._logD  s   0 ==8#8#8??\00666x?O?O	*67|q 0FG !>g!>>!$ *=C\\^* "J :@xq5ZF/EF
  	*""5))	*s   1C* A&C* *	D3D		Dc                    ddl m}  |       S )zGet a widget to be used as a loading indicator.

        Extend this method if you want to display the loading state a little differently.

        Returns:
            A widget to display a loading state.
        r   )LoadingIndicator)textual.widgetsr  )r   r  s     r   get_loading_widgetzApp.get_loading_widget{  s     	5!!r   c                    || _         | j                  yddl}|j                  |j	                  d            j                  d      }| j                  j                  d| d       y)zCopy text to the clipboard.

        !!! note

            This does not work on macOS Terminal, but will work on most other terminals.

        Args:
            text: Text you wish to copy to the clipboard.
        Nr   utf-8z]52;c;)r  r  base64	b64encodeencodedecoder   )r   r   r  base64_texts       r   copy_to_clipboardzApp.copy_to_clipboard  sZ     <<&&t{{7';<CCGLZ}B78r   c                (     j                   t        d       j                  t        j                         k(  rt        d      t        |g|i |d fd}t        j                   |        j                         }|j                         }|S )aO  Run a callable from another thread, and return the result.

        Like asyncio apps in general, Textual apps are not thread-safe. If you call methods
        or set attributes on Textual objects from a thread, you may get unpredictable results.

        This method will ensure that your code runs within the correct context.

        !!! tip

            Consider using [post_message][textual.message_pump.MessagePump.post_message] which is also thread-safe.

        Args:
            callback: A callable to run.
            *args: Arguments to the callback.
            **kwargs: Keyword arguments for the callback.

        Raises:
            RuntimeError: If the app isn't running or if this method is called from the same
                thread where the app is running.

        Returns:
            The result of the callback.
        zApp is not runningzIThe `call_from_thread` method must run in a different thread from the appc                    K   j                         5  t                d{   cddd       S 7 # 1 sw Y   yxY ww)z8Run the callback, set the result or error on the future.N)r*  r?   )callback_with_argsr   s   r   run_callbackz*App.call_from_thread.<locals>.run_callback  s9      8#$6778 878 8s    ?313
?3<?loop)r   r   )	r  r  r  r  r  r   r  run_coroutine_threadsaferY  )r   r   r  r  r  futurerY  r  s   `      @r   call_from_threadzApp.call_from_thread  s    < ::344??i1133[  %X???	8 07/O/ON0
 r   c                $    | j                          y)z8An [action](/guide/actions) to change the current theme.N)search_themesr   s    r   rf  zApp.action_change_theme  s    r   c                (    | j                  ||       y)a  This [action](/guide/actions) will save an SVG file containing the current contents of the screen.

        Args:
            filename: Filename of screenshot, or None to auto-generate.
            path: Path to directory. Defaults to the user's Downloads directory.
        N)re  )r   filenamepaths      r   action_screenshotzApp.action_screenshot  s     	$/r   )r   simplifyc          
     j   | j                   J d       | j                  \  }}t        ||t        j                         ddddd      }| j
                  j                  j                  d| j                  j                  |      }|j                  |       |j                  |xs | j                        S )aw  Export an SVG screenshot of the current screen.

        See also [save_screenshot][textual.app.App.save_screenshot] which writes the screenshot to a file.

        Args:
            title: The title of the exported screenshot or None
                to use app title.
            simplify: Simplify the segments by combining contiguous segments with the same style.
        zApp must be runningT	truecolorF)rT  rS  rJ  rP  rI  recordrN  rQ  )r-  rH  r  r   )r  rN  r$   ioStringIOrS  _compositorrender_updater   r  print
export_svgr   )r   r   r  rT  rS  rv  screen_renders          r   export_screenshotzApp.export_screenshot  s     ||'>)>>'		v$ 	
 //==DHH$@$@8 > 
 	m$!!(;!<<r   c                N   |xs d}|st        | j                  d|      }n|}t        j                  j	                  t        j                  j                  ||            }| j                         }t        |dd      5 }|j                  |       ddd       |S # 1 sw Y   |S xY w)a  Save an SVG screenshot of the current screen.

        Args:
            filename: Filename of SVG screenshot, or None to auto-generate
                a filename with the date and time.
            path: Path to directory for output. Defaults to current working directory.
            time_format: Date and time format to use if filename is None.
                Defaults to a format like ISO 8601 with some reserved characters replaced with underscores.

        Returns:
            Filename of screenshot.
        z./.svgwr  )rQ  N)	rH   r   rc  r  
expanduserr  r  openr   )r   r  r  time_formatsvg_filenamesvg_pathscreenshot_svgsvg_files           r   save_screenshotzApp.save_screenshot  s    $ |t5djj&+VL#L77%%bggll4&FG//1(C'2 	+hNN>*	+	+s   >BB$c                    |st        | j                  d|      }n|}| j                         }| j                  t	        j
                  |      ||ddd      S )a  Deliver a screenshot of the app.

        This with save the screenshot when running locally, or serve it when the app
        is running in a web browser.

        Args:
            filename: Filename of SVG screenshot, or None to auto-generate
                a filename with the date and time.
            path: Path to directory for output when saving locally (not used when app is running in the browser).
                Defaults to current working directory.
            time_format: Date and time format to use if filename is None.
                Defaults to a format like ISO 8601 with some reserved characters replaced with underscores.

        Returns:
            The delivery key that uniquely identifies the file delivery.
        r  browserzimage/svg+xml
screenshotsave_directorysave_filenameopen_method	mime_typer"  )rH   r   r  deliver_textr  r  )r   r  r  r  r  r  s         r   re  zApp.deliver_screenshot  s_    , 5djj&+VL#L//1  KK'&!% ! 
 	
r   c                d    | j                  t        t        | j                  |      g|            S )a  Show a list of commands in the app.

        Args:
            commands: A list of SimpleCommand instances.
            placeholder: Placeholder text for the search field.

        Returns:
            AwaitMount: An awaitable that resolves when the commands are shown.
        	providersplaceholder)push_screenrW   rY   rS  )r   commandsr#  s      r   search_commandszApp.search_commands?  s3     )$++x@A'
 	
r   c                F    | j                  t        t        gd             y)zShow a fuzzy search command palette containing all registered themes.

        Selecting a theme in the list will change the app's theme.
        u   Search for themes…r!  N)r$  rW   r   r   s    r   r  zApp.search_themesT  s"    
 	(/2	
r   )descriptionr  r_  c               D    | j                   j                  |||||       y)a  Bind a key to an action.

        !!! warning
            This method may be private or removed in a future version of Textual.
            See [dynamic actions](/guide/actions#dynamic-actions) for a more flexible alternative to updating bindings.

        Args:
            keys: A comma separated list of keys, i.e.
            action: Action to bind to.
            description: Short description of action.
            show: Show key in UI.
            key_display: Replacement text for key, or None to use default.
        )r  r_  N)r  r  )r   keysr  r(  r  r_  s         r   r  zApp.bind`  s&    , 	&+Dk 	 	
r   c                    |j                   r|j                   S |j                         \  }}t        |      }d|v r%|j                  |j	                  d             d| }||gz   }dj                  |      S )a0  Format a bound key for display in footer / key panel etc.

        !!! note
            You can implement this in a subclass if you want to change how keys are displayed in your app.

        Args:
            binding: A Binding.

        Returns:
            A string used to represent the key.
        ctrl^+)r_  	parse_keyrr   ro  r  r  )r   r  	modifiersr  
key_tokenss        r   get_key_displayzApp.get_key_displayz  s}     &&& !**,	3 o YMM)//&12cU)C#&
xx
##r   c                8  K   ddl }| }|j                  }|J |D ]N  }|j                  d      r`|j                  d      \  }}t	        j
                  t        |      dz         d{    |j                  j                          d{    ut        |      dk(  r|j                         st        |      }t        j                  ||      }	 |j                  t        |            }	t#        j$                  ||	      }
|
j'                  |       |j)                  |
       t+        d       d{    |j                  j                          d{    t+        d       d{    Q y7 7 # t         $ r t        |      dk(  r|nd}	Y w xY w7 c7 C7 2w)zA task to send key events.r   Nzwait:r    r   )unicodedatar  
startswithrr  r  sleepr  r  wait_until_completer  isalnumro   rn   getlookuprp   r  r3   Key
set_sendersend_messagerM   )r   r*  r5  r   driverr  r  wait_msoriginal_keychar	key_events              r   _press_keyszApp._press_keys  sb    !!! 	'C~~g& YYs^
7mmE'NT$9:::mm77999s8q=+C0C,00c::&--.H.VWD #JJsD1	$$S)##I.#A&&&mm77999#A&&&'	' ;9   :"%c(a-3TD:
 '9&sz   A&F(E.)!F
E1AFE3*AF0F1!FFF%F&	F1F3FFFFFFc                R    | j                   | j                   j                          yy)zCalled when stdout or stderr is flushed.

        Args:
            stderr: True if the print was to stderr, or False for stdout.

        N)r  r   )r   r   s     r   r   z
App._flush  s'     $$0%%++- 1r   c                   | j                   >t        j                         }| j                   j                  |||j                  nd       | j
                  r+|r| j                  n| j                  }|j                  |       | j                  j                         D ]8  \  }\  }}|r|s|s|r|j                  t        j                  ||             : y)a1  Called with captured print.

        Dispatches printed content to appropriate destinations: devtools,
        widgets currently capturing output, stdout/stderr.

        Args:
            text: Text that has been printed.
            stderr: True if the print was to stderr, or False for stdout.
        Nr   )r  r  currentframer   f_backrC  r  r  r  r  rW  r3   Print)r   r   r   current_frametarget_streamtarget_stdout_stderrs           r   r   z
App._print  s     $$0#002M%%++m.Gm**T
 5;D11AVAVM% +/*=*=*C*C*E 	G&F&WgF##FLLf$EF	Gr   c                R    |s|s| j                  |       y||f| j                  |<   y)aN  Capture content that is printed (or written to stdout / stderr).

        If printing is captured, the `target` will be sent an [events.Print][textual.events.Print] message.

        Args:
            target: The widget where print content will be sent.
            stdout: Capture stdout.
            stderr: Capture stderr.
        N)end_capture_printr  )r   rL  stdoutr   s       r   begin_capture_printzApp.begin_capture_print  s,     f""6*+16*:D'r   c                :    | j                   j                  |       y)zjEnd capturing of prints.

        Args:
            target: The widget that was capturing prints.
        N)r  ro  )r   rL  s     r   rP  zApp.end_capture_print  s     	'r   )P      )headlessrN  tooltipsnotificationsrD   c                K   ddl m} | }| |_        | |_        t	        j
                         dfdd	fd}t         ||      d|       x| _        }	j                          d{    |j                         5  	  ||      }
|
j                          d{    |
 t	        j                  d       d{    |j                          d{    |	 d{    | j                  r| j                  	 ddd       y7 7 l7 L7 67 .# t	        j                  d       d{  7   |j                          d{  7   |	 d{  7   | j                  r| j                  w xY w# 1 sw Y   yxY ww)
a{  An asynchronous context manager for testing apps.

        !!! tip

            See the guide for [testing](/guide/testing) Textual apps.

        Use this to run your app in "headless" mode (no output) and drive the app via a [Pilot][textual.pilot.Pilot] object.

        Example:

            ```python
            async with app.run_test() as pilot:
                await pilot.click("#Button.ok")
                assert ...
            ```

        Args:
            headless: Run in headless mode (no output or input).
            size: Force terminal size to `(WIDTH, HEIGHT)`,
                or None to auto-detect.
            tooltips: Enable tooltips when testing.
            notifications: Enable notifications when testing.
            message_hook: An optional callback that will be called each time any message arrives at any
                message pump in the app.
        r   r   c                 &     j                          y)z+Called when app is ready to process events.N)r&  )app_ready_events   r   on_app_readyz"App.run_test.<locals>.on_app_ready  s    !r   c                t  K   | j                         5  	 t        j                         t        j                         | _        t        j                         | _        | j                         d{    j                          	 ddd       y7 # j                          w xY w# 1 sw Y   yxY ww)z[Run the apps message loop.

            Args:
                app: App to run.
            N)ready_callbackrV  terminal_size)
r*  message_hook_context_varr&  r  get_running_loopr  r  r  r  _process_messages)r   r[  rV  rD   r\  rN  s    r   run_appzApp.run_test.<locals>.run_app  s       **#/044\B ' 8 8 :CI%.%8%8%:CN//'3!)&* 0    $'')* * $'')* *sF   B8B,A B6B7B;B,	B8BB))B,,B51B8z	run_test r!  Nr   )r   zApp[ReturnType]r   r   )textual.pilotr   r  r  r  r  r   _taskwaitr*  _wait_for_screenr7  	_shutdownr  )r   rV  rN  rW  rX  rD   r   r   rc  app_taskpilotr[  r\  s    ``  `     @@r   run_testzApp.run_test  sU    F 	($,)6%6"!--/	"	* 	*. !,GCL3%?P QQ
X ""$$$\\^ 	**c
,,...mmA&&&mmo%%??//) #	* 	* 	%
 / '% mmA&&&mmo%%??//) #	* 	*s   A-F4D5F	E:D&D'	D0E:D	E: D!	E:*D+E:
FDE:E:E:E74D7
5E7E

E7E
E77E::F?FrV  r9  inline_no_clearmouserN  
auto_pilotc          	        
K   ddl m
  d7t        j                  r't        j                  j	                  d      d	fd}|d

 fd} j                          t        j                         x}	_        t        t        d      r|	j                  t        j                         j                         5  	 j                  dn||||||       d{    	 
 d{    	 t        j                  j                                d{    d_        d_        	 ddd       j$                  S 7 `7 U7 +# t        j                   $ r Y >w xY w# 	 t        j                  j                                d{  7   w # t        j                   $ r Y w w xY wxY w# 	  d{  7   	 t        j                  j                                d{  7   nd# t        j                   $ r Y nOw xY w# 	 t        j                  j                                d{  7   w # t        j                   $ r Y w w xY wxY wd_        d_        w xY w# 1 sw Y   j$                  S xY ww)a  Run the app asynchronously.

        Args:
            headless: Run in headless mode (no output).
            inline: Run the app inline (under the prompt).
            inline_no_clear: Don't clear the app output when exiting an inline app.
            mouse: Enable mouse support.
            size: Force terminal size to `(WIDTH, HEIGHT)`,
                or None to auto-detect.
            auto_pilot: An autopilot coroutine.

        Returns:
            App return value.
        r   r   NrG  c                @   K    | j                     d{    y7 w)zAuto press keys.N)press)rj  r*  s    r   
press_keysz!App.run_async.<locals>.press_keysi  s     !ekk4(((s   c                 x   K   3	 	 	 	 	 	 dfd}        }t         | |      t        |            yyw)z1Called by the message loop when the app is ready.Nc                   K   j                         5  	  | |       d {    	 d d d        y 7 # t        $ r j                           w xY w# 1 sw Y   y xY wwr   )r*  r  r[  )ro  rj  r   r   s     r   run_auto_pilotz8App.run_async.<locals>.app_ready.<locals>.run_auto_pilotu  s\       """,U"333" "3( "HHJ!"" "s6   AA202	A2AAAAr!  )ro  r   rj  r   r   r   )r   repr)rv  rj  r   r   ro  auto_pilot_taskr   s     r   	app_readyz App.run_async.<locals>.app_readyo  sV      %" 5">C"" c
"-":u5DK# &s   7:eager_task_factory)r^  rV  r9  rm  rn  r_  )rj  zPilot[ReturnType]r   r   r   )rd  r   r2   PRESSrr  r  r  ra  r  hasattrset_task_factoryrz  r*  rb  shieldrh  CancelledErrorr  r  )r   rV  r9  rm  rn  rN  ro  rs  ry  r  r   r   rx  r*  s   `     `   @@@@r   	run_asynczApp.run_asyncI  s)    0 	('+)//??((-D) $J	 	* 	"3355sy701!!'"<"<=\\^ 	##+++5+=49%!$3"& ,   &2---%nnS]]_=== !	!")	#, ) . >"11 %nnS]]_==="11 &2---%nnS]]_==="11 %nnS]]_==="11  	!")	#, sJ  B8I5 IF+ E!F+&E -E.E 3&EEEI-I5F+E EEIEI F("&FF
	FF(F%	"F($F%	%F((I+I-H4F7
5H;&G(!G$
"G('I(G>	;I=G>	>II		&H0
)H,*H0
/I		0II		II			III2#I5)rV  r9  rm  rn  rN  ro  r  c               @    d fd}|Kt         rt        j                   |             S 	 t        j                         }	|	j	                   |             S |j	                   |             S # t
        $ r Y nw xY wt        j                   |             S )a  Run the app.

        Args:
            headless: Run in headless mode (no output).
            inline: Run the app inline (under the prompt).
            inline_no_clear: Don't clear the app output when exiting an inline app.
            mouse: Enable mouse support.
            size: Force terminal size to `(WIDTH, HEIGHT)`,
                or None to auto-detect.
            auto_pilot: An auto pilot coroutine.
            loop: Asyncio loop instance, or `None` to use default.
        Returns:
            App return value.
        c                 N   K   j                          d{   S 7 w)zRun the app.rl  N)r  )ro  rV  r9  rm  rn  r   rN  s   r   rc  zApp.run.<locals>.run_app  s9     ! /% (    s   %#%r   ReturnType | None)%_ASYNCIO_GET_EVENT_LOOP_IS_DEPRECATEDr  runget_event_looprun_until_completer  )
r   rV  r9  rm  rn  rN  ro  r  rc  global_loops
   ```````   r   r  zApp.run  s    4		 		 <4 {{79--	A%446 #55gi@@&&wy11   
  ;;wy))s   A7 7	BBc           	       K   | j                   | j                   j                  n| j                  }|r(	 t               }| j                  j                         }	 |j                  |       |j                          t               |z
  dz  }| j                  rCddlm} | j                  j                   |ddj!                  d |D              z   dd	             | j                  j                  d
t#        |       d|dd       d| _        || _        | j                  j%                  |        | j&                  D ]  }| j                  j%                  |        yy# t        $ r.}| j                  j                  t        |             Y d}~yd}~ww xY w# t(        $ r<}d| _        | j                  j+                  |       | j-                          Y d}~yd}~ww xY ww)z<Callback for the file monitor, called when CSS files change.Nr4  r   )Panelz7CSS files successfully loaded after previous error:

- z
- c              3  2   K   | ]  }t        |        y wr   r  )r  r  s     r   r  z%App._on_css_change.<locals>.<genexpr>  s     )J#d))Jr  green)styleborder_stylez<stylesheet> loaded z CSS files in z.0fz msFT)r  _pathsr  r   r  r  read_allr\   r4   warningr   parser  
rich.panelr  r  r  r  rZ  rH  r  r  bell)r   r  timer  r  elapsedr  rS  s           r   r  zApp._on_css_change  s     (,'7'7'CD## 	 &3#~!__113
''	2   "'>D0D8''0HHOOW$kk)J	)JJK"))0	 *3y>*:.QTUXY (-$",&&t,"// 3FOO**623M  ' 
 HH$$SZ0.  '+$u%			s`   2G$F E +BF AG	F&$F
F GFF 	G 2GGGGc                @    t        | j                  j                        S )zRender method, inherited from widget, to render the screen's background.

        May be overridden to customize background visuals.

        )rz   r  r  r   s    r   renderz
App.render	  s     T[[++,,r   
ExpectTyper   c                     y r   r   r   rs  s     r   get_child_by_idzApp.get_child_by_id	  s    69r   c                     y r   r   r   rs  expect_types      r   r  zApp.get_child_by_id	       r   c                t    || j                   j                  |      S | j                   j                  ||      S )a  Get the first child (immediate descendant) of this DOMNode with the given ID.

        Args:
            id: The ID of the node to search for.
            expect_type: Require the object be of the supplied type,
                or use `None` to apply no type restriction.

        Returns:
            The first child of this node with the specified ID.

        Raises:
            NoMatches: If no children could be found for this ID.
            WrongType: If the wrong type was found.
        )rS  r  r  s      r   r  zApp.get_child_by_id	  s>    & " KK''+	
 ,,R=	
r   c                     y r   r   r  s     r   get_widget_by_idzApp.get_widget_by_id4	  s    7:r   c                     y r   r   r  s      r   r  zApp.get_widget_by_id7	  r  r   c                t    || j                   j                  |      S | j                   j                  ||      S )a  Get the first descendant widget with the given ID.

        Performs a breadth-first search rooted at the current screen.
        It will not return the Screen if that matches the ID.
        To get the screen, use `self.screen`.

        Args:
            id: The ID to search for in the subtree
            expect_type: Require the object be of the supplied type, or None for any type.
                Defaults to None.

        Returns:
            The first descendant encountered with this ID.

        Raises:
            NoMatches: if no children could be found for this ID
            WrongType: if the wrong type was found.
        )rS  r  r  s      r   r  zApp.get_widget_by_id<	  s>    . " KK((,	
 --b+>	
r   c                8    | j                   j                  |      S )zGet a child of a give type.

        Args:
            expect_type: The type of the expected child.

        Raises:
            NoMatches: If no valid child is found.

        Returns:
            A widget.
        )rS  get_child_by_type)r   r  s     r   r  zApp.get_child_by_typeW	  s     {{,,[99r   c                b    |j                  d      }| j                  j                  |d       y)aC  Immediately update the styles of this node and all descendant nodes.

        Should be called whenever CSS classes / pseudo classes change.
        For example, when you hover over a button, the :hover pseudo class
        will be added, and this method is called to apply the corresponding
        :hover styles.
        T	with_selfr  N)walk_childrenr  update_nodes)r   nodedescendantss      r   update_styleszApp.update_stylese	  s.     ((4(8$$[$$?r   beforeafterc               <     | j                   j                  |||dS )aT  Mount the given widgets relative to the app's screen.

        Args:
            *widgets: The widget(s) to mount.
            before: Optional location to mount before. An `int` is the index
                of the child to mount before, a `str` is a `query_one` query to
                find the widget to mount before.
            after: Optional location to mount after. An `int` is the index
                of the child to mount after, a `str` is a `query_one` query to
                find the widget to mount after.

        Returns:
            An awaitable object that waits for widgets to be mounted.

        Raises:
            MountError: If there is a problem with the mount request.

        Note:
            Only one of ``before`` or ``after`` can be provided. If both are
            provided a ``MountError`` will be raised.
        r  )rS  mount)r   r  r  widgetss       r   r  z	App.mountp	  s    6 !t{{  '&FFr   c               (     | j                   |||dS )a=  Mount widgets from an iterable.

        Args:
            widgets: An iterable of widgets.
            before: Optional location to mount before. An `int` is the index
                of the child to mount before, a `str` is a `query_one` query to
                find the widget to mount before.
            after: Optional location to mount after. An `int` is the index
                of the child to mount after, a `str` is a `query_one` query to
                find the widget to mount after.

        Returns:
            An awaitable object that waits for widgets to be mounted.

        Raises:
            MountError: If there is a problem with the mount request.

        Note:
            Only one of ``before`` or ``after`` can be provided. If both are
            provided a ``MountError`` will be raised.
        r  )r  )r   r  r  r  s       r   	mount_allzApp.mount_all	  s    8 tzz76??r   c                P   | j                   j                  |g       }|rt        |d   g       S || j                  v r| j                  |   }t	        |t
              r%t        dt        |      j                   d|d      t        |      r |       n|}| j                  |      \  }}|j                  |       | j                  |       |j                  | j                  k7  r| j                          |j                  t!        j"                                ne| j%                         }|j                  |       | j'                  | |       |j                  t!        j"                                t        |d   g       }|j)                  | j*                         || j                   |<   |S )a  Do internal initialization of a new screen stack mode.

        Args:
            mode: Name of the mode.

        Returns:
            An optionally awaitable object which can be awaited until the screen
            associated with the mode has been mounted.
        r   zDMODES cannot contain instances, use a type instead (got instance of r  r  )r{  r:  r   r  r  r|   r  r  r   r  _get_screenrp  _load_screen_cssr  r  rW  r3   ScreenResumert  	_register_screen_resizedrN  )r   modestack_screen
new_screenrS  await_mounts          r   
_init_modezApp._init_mode	  sw    ##''b1 eAh++4;;kk$'G'6*((,W(>(>'?uTHAO  5=W4Ewy7J"&"2"2:">FKLL !!&)''4+A+AA  " 3 3 56 ,,.FLL NN4( 3 3 56$U1Xr2Ktyy)$)D!r   c                :   || j                   k(  rt        | j                  g       S || j                  vrt	        d|      | j                  j                  t        j                                | j                  j                          || j                  vr| j                  |      }nt        | j                  g       }|| _         | j                  j                  | j                  k7  r| j                          | j                  j                  | j                         | j                  j                  t        j                                | j                   j#                  | j                   d       | j                   j#                  | j                   d       |S )a@  Switch to a given mode.

        Args:
            mode: The mode to switch to.

        Returns:
            An optionally awaitable object which waits for the screen associated
                with the mode to be mounted.

        Raises:
            UnknownModeError: If trying to switch to an unknown mode.

        r  z is the current mode
 is active)r|  r   rS  r  r   rW  r3   ScreenSuspendr  r{  r  r  r  r  rN  r  r4   r  )r   r  r  s      r   switch_modezApp.switch_mode	  s5    4%%%dkk2..t{{""^D8#<==  !5!5!78t***//$/K$T[["5K!;;((D,B,BB##DII.  !4!4!674--00DEF4;;-z23r   c                    |dk(  rt        d      || j                  v rt        d|d      t        |t              r"t	        dt        |      j                   d      || j                  |<   y)a  Adds a mode and its corresponding base screen to the app.

        Args:
            mode: The new mode.
            base_screen: The base screen associated with the given mode.

        Raises:
            InvalidModeError: If the name of the mode is not valid/duplicated.
        r   z'Cannot use '_default' as a custom mode.zDuplicated mode name .zOadd_mode() must be called with a Screen type, not an instance (got instance of r  N)r   r  r  r|   r  r  r   )r   r  base_screens      r   add_modezApp.add_mode
  s~     :"#LMMT[[ "%:4(!#DEEk6*%%)+%6%?%?$@C  (Dr   c                Z    | j                   k(  rt        d|      | j                  vrt        d|       j                  |= | j                  vrt        j                         S  j                  |    j                  |= d fd}t         |             j                         S )ad  Removes a mode from the app.

        Screens that are running in the stack of that mode are scheduled for pruning.

        Args:
            mode: The mode to remove. It can't be the active mode.

        Raises:
            ActiveModeError: If trying to remove the active mode.
            UnknownModeError: If trying to remove an unknown mode.
        zCan't remove active mode zUnknown mode c                 d   K   t              D ]  } j                  |        d{     y7 w)zRemove screens.N)r	  _replace_screen)rS  r   r  s    r   remove_screensz'App.remove_mode.<locals>.remove_screens0
  s1     "5/ 3**622232s   #0.0r   )r|  r   r  r   r{  rP   nothingr  )r   r  r  r  s   `  @r   remove_modezApp.remove_mode
  s     4%%%!$=dX"FGG$"]4(#;<<D!t*** ((**##D)%	3
 ^-.88>>r   c                v    t        |t              r|| j                  v S || j                  j                         v S )zCheck if a given screen has been installed.

        Args:
            screen: Either a Screen object or screen name (the `name` argument when installed).

        Returns:
            True if the screen is currently installed,
        )r  r   r  rg  ro  s     r   is_screen_installedzApp.is_screen_installed7
  s9     fc"T4444T44;;===r   c                     y r   r   ro  s     r   
get_screenzApp.get_screenE
  s    <?r   c                     y r   r   ro  s     r   r  zApp.get_screenH
  s    14r   c                     y r   r   r   rS  screen_classs      r   r  zApp.get_screenK
       r   c                     y r   r   r  s      r   r  zApp.get_screenP
  r  r   c                   t        |t              r2	 | j                  |   }t	        |      r |       }|| j                  |<   n|}|&t        ||      st        d| dt        |             |S # t        $ r t        d|d      dw xY w)a  Get an installed screen.

        Example:
            ```python
            my_screen = self.get_screen("settings", MyScreen)
            ```

        Args:
            screen: Either a Screen object or screen name (the `name` argument when installed).
            screen_class: Class of expected screen, or `None` for any screen class.

        Raises:
            KeyError: If the named screen doesn't exist.

        Returns:
            A screen instance.
        zNo screen called z
 installedNzExpected a screen of type z, got )r  r   r  r  r  r  r  )r   rS  r  next_screens       r   r  zApp.get_screenU
  s    ( fc"S"55f= $)m2=''/ K#J{L,Q,\N&kAR@ST    S!26*JGHdRSs   A/ /B	c                    | j                  |      }|j                  s3| j                  | |      }t        ||      }| j	                  |       ||fS t        |g       }| j	                  |       ||fS )a  Get an installed screen and an AwaitMount object.

        If the screen isn't running, it will be registered before it is run.

        Args:
            screen: Either a Screen object or screen name (the `name` argument when installed).

        Raises:
            KeyError: If the named screen doesn't exist.

        Returns:
            A screen instance and an awaitable that awaits the children mounting.
        )r  
is_runningr  r   r  )r   rS  r  r  r  s        r   r  zApp._get_screeny
  sq     //&)!!nnT73G$Wg6KNN;'[))$Wb1KNN;'[))r   c                    | j                   %| j                   j                  |j                         d}|j                  D ]E  }| j                  j	                  t        |      d      r)| j                  j                  |       d}G |j                  r	 t        j                  |j                        }|j                  j                   d}||f}| j                  j	                  ||      sC| j                  j                  |j                  |d|j                  r|j                   nd       d}|r6| j                  j#                          | j                  j%                  |        yy# t        t        f$ r d}Y w xY w)z'Loads the CSS associated with a screen.NFr   T.CSS)	read_fromis_default_cssscope)r  	add_pathsr  r  
has_sourcer   readr   r  getfiler  r  OSErrorr   
add_source
SCOPED_CSS_css_type_namereparserZ  )r   rS  rZ  r  screen_pathscreen_class_varr  s          r   r  zApp._load_screen_css
  sP    '&&v7OO 	D??--c$i<$$T*	 ::!%oof.>.>? #)"2"2";";!<DA$&67I??--k;KL**JJ'#(393D3D&//"	 +  OO##%OO""4(  w' ! !s   E) )E=<E=c                  K   | j                   r| j                  j                          j                  t	        j
                                | j                  j                   d       | j                        sst        fd| j                  j                         D              rG| j                  d       j                          d{    | j                  j                   d       S 7 $w)zHandle the replaced screen.

        Args:
            screen: A screen object.

        Returns:
            The screen that was replaced.
        z
 SUSPENDEDc              3  &   K   | ]  }|v 
 y wr   r   r  r  rS  s     r   r  z&App._replace_screen.<locals>.<genexpr>
  s      8
$)F%8
   Nz REMOVED)r
  rS  r  rW  r3   r  r4   r  r  allr{  rg  capture_mouseremovero  s    `r   r  zApp._replace_screen
  s      KK!F00236(*-.''/C 8
-1-@-@-G-G-I8
 5
 t$--/!!HHOOvhh/0 "s   C	C3C1%C3c                     y r   r   r   rS  r   wait_for_dismisss       r   r$  zApp.push_screen
  s     r   c                     y r   r   r  s       r   r$  zApp.push_screen
  s     03r   c                   t        |t        t        f      st        d|      	 t	        j
                         }|j                         }| j                  j                  d       | j                  rG| j                  j                  t        j                                | j                  j!                          | j#                  |      \  }}	 t%        j&                         }|j+                  |||       | j-                  |       |j/                          | j                  j1                  |       |j                  t        j2                                | j4                  j7                  | j                   d       |r	 t9                |S |S # t        $ r t	        j                         }Y bw xY w# t(        $ r | j                  }Y w xY w# t:        $ r t;        d      dw xY w)a  Push a new [screen](/guide/screens) on the screen stack, making it the current screen.

        Args:
            screen: A Screen instance or the name of an installed screen.
            callback: An optional callback function that will be called if the screen is [dismissed][textual.screen.Screen.dismiss] with a result.
            wait_for_dismiss: If `True`, awaiting this method will return the dismiss value from the screen. When set to `False`, awaiting
                this method will wait for the screen to be mounted. Note that `wait_for_dismiss` should only be set to `True` when running in a worker.

        Raises:
            NoActiveWorker: If using `wait_for_dismiss` outside of a worker.

        Returns:
            An optional awaitable that awaits the mounting of the screen and its children, or an asyncio Future
                to await the result of the screen.
        z3push_screen requires a Screen instance or str; not Nz is current (PUSHED)zEpush_screen must be run from a worker when `wait_for_dismiss` is True)r  r|   r   r  r  ra  create_futurer  r   r   r  r
  rS  rW  r3   r  r  r  rC   r:  LookupError_push_result_callbackr  _update_auto_focusrp  r  r4   r  r   r   )	r   rS  r   r  r  r  r  r  message_pumps	            r   r$  zApp.push_screen
  s   * &63-0EfZP 	*++-D
 '')Ft$KK$$V%9%9%;<KK!#'#3#3F#; [	$.224L 	)),&Ik*&&(!!+.  !4!4!674;;-';<="$
 M?  	H7>~~7GF	H  	$88L	$ " $[s/   F F0 >
G F-,F-0GGG!c                   K   y wr   r   ro  s     r   push_screen_waitzApp.push_screen_wait  s       #   c                   K   y wr   r   ro  s     r   r  zApp.push_screen_wait  s	     >Ar  c                   K   | j                          d{    t        j                  | j                  |d             d{   S 7 27 w)a@  Push a screen and wait for the result (received from [`Screen.dismiss`][textual.screen.Screen.dismiss]).

        Note that this method may only be called when running in a worker.

        Args:
            screen: A screen or the name of an installed screen.

        Returns:
            The screen's result.
        NT)r  )_flush_next_callbacksr  r~  r$  ro  s     r   r  zApp.push_screen_wait  sE      ((***^^D$4$4Vd$4$STTT 	+Ts!   AA	-AAAAc                <    t        |t        t        f      st        d|       j	                  |      \  }| j
                  u s| j
                  u r3 j                  j                  d| d       t        j                         S  j                  j                  d        j                  j                         j                           j                  |        j                  j!                  |        j
                  j#                  t%        j&                                 j
                  j)                   j
                  d        j                  j                   j
                   d       d fd}t         |             j+                         S )zSwitch to another [screen](/guide/screens) by replacing the top of the screen stack with a new screen.

        Args:
            screen: Either a Screen object or screen name (the `name` argument when installed).
        z5switch_screen requires a Screen instance or str; not Screen z is already current.Nz is current (SWITCHED)c                 f   K             d{    j                         d{    y7 7 w)zTask to perform switch.Nr  )r  r   
top_screens   r   	do_switchz$App.switch_screen.<locals>.do_switchI  s1      -&&z222  2s   1-1/11r   )r  r|   r   r  r  rS  r4   r  rP   r  r   r  r
  ro  _pop_result_callbackr  rp  rW  r3   r  r  r  )r   rS  r  r  r  r  s   `   @@r   switch_screenzApp.switch_screen/  sC    &63-0GzR  $(#3#3F#; [T[[ K4;;$>HHOOgfX-ABC ((**t$''++-
'')k*!!+.  !4!4!67))$++t<4;;-'=>?	3 Y[)33D99r   c                    || j                   v rt        d|d      || j                   j                         v rt        d|d      || j                   |<   | j                  j	                  | d|       y)ah  Install a screen.

        Installing a screen prevents Textual from destroying it when it is no longer on the screen stack.
        Note that you don't need to install a screen to use it. See [push_screen][textual.app.App.push_screen]
        or [switch_screen][textual.app.App.switch_screen] to make a new screen current.

        Args:
            screen: Screen to install.
            name: Unique name to identify the screen.

        Raises:
            ScreenError: If the screen can't be installed.

        Returns:
            An awaitable that awaits the mounting of the screen and its children.
        zCan't install screen; z is already installedz has already been installedz INSTALLED name=N)r  r   rg  r4   r  )r   rS  r"  s      r   install_screenzApp.install_screenQ  s    " 4*** 6th>STUUT,,3355(
2MN  )/%6("24(;<r   c                h   t        t              r| j                  vry| j                     t        fd| j                  j                         D              rt        d      | j                  = | j                  j                   d       S t        fd| j                  j                         D              rt        d      | j                  j                         D ]H  \  }}|u s| j                  j                  |       | j                  j                   d|       |c S  y)ax  Uninstall a screen.

        If the screen was not previously installed, then this method is a null-op.
        Uninstalling a screen allows Textual to delete it when it is popped or switched.
        Note that uninstalling a screen is only required if you have previously installed it
        with [install_screen][textual.app.App.install_screen].
        Textual will also uninstall screens automatically on exit.

        Args:
            screen: The screen to uninstall or the name of an installed screen.

        Returns:
            The name of the screen that was uninstalled, or None if no screen was uninstalled.
        Nc              3  &   K   | ]  }|v  
 y wr   r   )r  r  uninstall_screens     r   r  z'App.uninstall_screen.<locals>.<genexpr>~  s     W#u,Wr  z&Can't uninstall screen in screen stackz UNINSTALLED name=c              3  &   K   | ]  }|v  
 y wr   r   r  s     r   r  z'App.uninstall_screen.<locals>.<genexpr>  s     Mu6U?Mr  )r  r   r  anyr{  rg  r   r4   r  r  ro  )r   rS  r"  installed_screenr  s    `  @r   r  zApp.uninstall_screenk  s    fc"T444#66v>W$:M:M:T:T:VWW&'OPP''/HHOO/00B6*MNMM0C0C0J0J0LMM&'OPP*.*A*A*G*G*I  &&#v-++//5HHOOvh.@$IJK	 
 r   c                     j                   }t        |      dk  rt        d      |j                         j	                           j
                  j                  t        j                                 j                  j                   j
                   d       d fd}t         |             j                         S )zPop the current [screen](/guide/screens) from the stack, and switch to the previous screen.

        Returns:
            The screen that was replaced.
        r   z@Can't pop screen; there must be at least one screen on the stackr  c                 D   K   j                          d{    y7 w)zTask to pop the screen.Nr  )previous_screenr   s   r   do_popzApp.pop_screen.<locals>.do_pop  s     &&777s     r   )r
  r  r   ro  r  rS  rW  r3   r  r4   r  rP   r  )r   rH  r  r  s   `  @r   
pop_screenzApp.pop_screen  s     ))|!"R  '**,,,.  !4!4!674;;-z23	8 VX&0066r   c                     g t         j                        D ]  }||urj                  |        n t        d|d      d fd}r j	                  |       yy)zPop screens until the given screen is active.

        Args:
            screen: desired active screen

        Raises:
            ScreenError: If the screen doesn't exist in the stack.
        r	  z not in screen stackc                    K   j                         5  D ]  } | j                          d{     	 ddd       y7 # 1 sw Y   yxY ww)z$Pop any screens in `screens_to_pop`.N)r  dismiss)rS  screens_to_popr   s    r   pop_screensz'App._pop_to_screen.<locals>.pop_screens  sO     ""$ +, +F ..***++ +*+ +s)   AA >A 	AA  A	ANr   )r	  rH  rp  r   
call_later)r   rS  r  r!  r   s   `   @r   _pop_to_screenzApp._pop_to_screen  sq     (*"4#4#45 	HJ'%%j1		H z1EFGG	+ OOK( r   c                <    | j                   j                  ||       y)zFocus (or unfocus) a widget. A focused widget will receive key events first.

        Args:
            widget: Widget to focus.
            scroll_visible: Scroll widget into view.
        N)rS  	set_focus)r   widgetscroll_visibles      r   r%  zApp.set_focus  s     	fn5r   c                ,   |M| j                   	 | j                   j                  t        j                  | j                                d| _         n| j                   |urr	 | j                   8| j                   j                  t        j                  | j                                |$|j                  t        j                  |             || _         | j
                  d| j
                  _        |d|_        || _        y# d| _         w xY w# || _         w xY w)zCalled when the mouse is over another widget.

        Args:
            widget: Widget under mouse, or None for no widgets.
        NFT)r~  rW  r3   LeaveEnterr  mouse_hover)r   r&  hover_widgets      r   _set_mouse_overzApp._set_mouse_over  s     >*+OO00doo1NO&*DOf,-244V\\$//5RS)++FLL,@A&,DO??&*/DOO'#'+L$& '+DO '-DOs   8C> A*D
 >	D
	Dc                j      j                   j                  syd fd} j                  |       y)zUpdates the mouse over after the next refresh.

        This method is called whenever a widget is added or removed, which may change
        the widget under the mouse.

        Nc                    K   	  j                   j                   } | j                  \  }}|j                  us|j                  urj                  ||       yy# t        $ r Y yw xY ww)z+Check if the mouse over widget has changed.N)get_hover_widgets_atr  r  r~  r  r-  rc   )hover_widgetsr~  r  rS  r   s      r   check_mousez+App._update_mouse_over.<locals>.check_mouse  sw     
A ; ; ;T=P=P Q *7)>)>&
Jdoo5!8((Z@ 9  s'   A,A ?A,	A)&A,(A))A,r   )r~  	is_activecall_after_refresh)r   rS  r2  s   `` r   _update_mouse_overzApp._update_mouse_over  s0     ??"&*:*:	A 	,r   c                   || j                   k(  ry| j                   8| j                   j                  t        j                  | j                               || _         |/|j                  t        j
                  | j                               yy)as  Send all mouse events to the given widget or disable mouse capture.

        Normally mouse events are sent to the widget directly under the pointer.
        Capturing the mouse allows a widget to receive mouse events even when the pointer is over another widget.

        Args:
            widget: Widget to capture mouse events, or `None` to end mouse capture.
        N)r  rW  r3   MouseReleaser  MouseCapturer   r&  s     r   r  zApp.capture_mouse  sx     T(((*,,V-@-@ATAT-UV$ 3 3D4G4G HI r   c                     t        d |D              sJ d       d fd}|D cg c]  }t         ||             }} j                  j                  |        j	                          yc c}w )a  Exits the app and display error message(s).

        Used in response to unexpected errors.
        For a more graceful exit, see the [exit][textual.app.App.exit] method.

        Args:
            *renderables: Text or Rich renderable(s) to display on exit.
        c              3  2   K   | ]  }t        |        y wr   r)   )r  
renderables     r   r  zApp.panic.<locals>.<genexpr>  s      
*4M*%
r  z4Can only call panic with strings or Rich renderablesc                z    t        j                  j                  | j                  j                              }|S )zRender a panic renderables.)listrv  r  options)r<  segmentsr   s     r   r  zApp.panic.<locals>.render   s-    DLL//
DLL<P<PQRHOr   N)r<  r'   r   zlist[Segment])r  r,   r  extend_close_messages_no_wait)r   renderablesr  r<  pre_rendereds   `    r   panicz	App.panic  sz      
8C
 
 	BA	B 
	
 HSS
!34SS%%l3$$& Ts   A+c                    d| _         | j                  !|| _        | j                  j                          t	        |d      r| j                  |       y| j                          y)zCalled with an unhandled exception.

        Always results in the app exiting.

        Args:
            error: An exception instance.
        r   N__rich__)r  r  r  r&  r|  rE  _fatal_error)r   r  s     r   r  zApp._handle_exception*  sU      ??"#DO!!%%'5*%JJu r   c                   ddl m} | j                           |dddt        g      }| j                  j                  t        | j                  j                  || j                  j                                     | j                          y)z+Exits the app after an unhandled exception.r   )	TracebackTNr
  )show_localsrT  locals_max_lengthsuppress)rich.tracebackrJ  r  richr  rp  r,   rv  r  r?  rB  )r   rJ  	tracebacks      r   rH  zApp._fatal_error@  sj    ,		DA
	 	%%T\\((DLL4H4HIJ	
 	$$&r   c                   t        | j                        }d| j                  v rS| j                  D ]  }| j                  j	                  |        |dkD  r|| j                  j	                  d| dd       nZ| j                  rN| j                  j	                  | j                  d          |dkD  r!| j                  j	                  d| d	d       | j                  j                          y
)z!Print and clear exit renderables.r  r   z
[b]NOTE:[/b] z errors shown above.TrK  r   z
[b]NOTE:[/b] 1 of zB errors shown. Run with [b]textual run --dev[/] to see all errors.N)r  r  re  rx  r  clear)r   error_countr<  s      r   _print_error_renderableszApp._print_error_renderablesM  s    $001dmm#"44 5
""((45Q""((%k]2FGPT )  ##$$T%;%;A%>?Q""((*;-7yz ) 
 	$$&r   c                    |r	ddl m} |}n|rt        s	ddlm} |}n| j
                  } || t        j                  ||      x}| _        |S )a  Construct a driver instance.

        Args:
            headless: Request headless driver.
            inline: Request inline driver.
            mouse: Request mouse support.
            size: Initial size.

        Returns:
            Driver instance.
        r   )HeadlessDriver)LinuxInlineDriver)r  rn  rN  )	textual.drivers.headless_driverrW  r  #textual.drivers.linux_inline_driverrX  rz  r2   rA  r  )	r   rV  r9  rn  rN  rW  rz  rX  r?  s	            r   _build_driverzApp._build_drivera  sQ      F)LGM,L,,L ,//	!
 	
 r   c                ^  K   | j                   ]ddlm} 	 | j                   j                          d{    | j                  j                  d| j                   j                   d       yy7 9# |$ r6 | j                  j                  d| j                   j                   d       Y yw xY ww)zInitialize developer tools.Nr   )DevtoolsConnectionErrorzConnected to devtools ( z )zCouldn't connect to devtools ( )rV  r  r]  connectr4   r  url)r   r]  s     r   _init_devtoolszApp._init_devtools  s     ==$BYmm++---":4==;L;L:MR PQ % .* Y"A$--BSBSATTV WXYs8   B-A/ A-7A/ +B--A/ /8B*'B-)B**B-c           	     |   K    j                          d fd} fd}	 j                         5   |        d {   s
	 d d d        y d _        	 t        j                         }
 j                  |
       d {     j                  ||||      x} _         j                  |        j                  s|j                          	 t         j                        5  t         j                        5   |	        d {    d d d        d d d        t        j                            j                  j"                  r j$                  \  }} j                  j'                  t)        j*                  | |       j,                  j.                          j                  j1                          |rG j2                  j4                  s1t7               }	 |j9                   j:                  j<                         nN j                  j'                  t)        j*                  d j@                         j,                  j.                         |jC                          d d d        y 7 %7 7 e# 1 sw Y   exY w# 1 sw Y   jxY w# t>        $ r |j9                          Y Ww xY w# t        j                            j                  j"                  r$ j$                  \  }} j                  j'                  t)        j*                  | |       j,                  j.                          j                  j1                          |rf j2                  j4                  sPt7               }	 |j9                   j:                  j<                         nm# t>        $ r |j9                          Y nRw xY w j                  j'                  t)        j*                  d j@                         j,                  j.                         |jC                          w xY w# tD        $ r} jG                  |       Y d }~d }~ww xY w# 1 sw Y   y xY ww)Nc                   K   j                          d{    j                  j                  d       j                  j                  t        j                                j                  j                  j
                         t        j                  Kt        j                  j                  t        j                        } j                  j                  d|        	 j                  r%j                  j                  j                         j                         D ]'  \  }}}}j                  j                  ||d||       ) j                   rc	 t#        j$                  j&                        }|j&                  j,                   d	f}j                  j                  j                   |d
       j4                  rDj7                  dj4                  d       j                  j                  dj4                         y7 # t(        t*        f$ r d}Y w xY w# t.        $ r+}j1                  |       j3                          Y d}~y
d}~ww xY ww)zWork required before running the app.

            Returns:
                `True` if the app should continue, or `False` if there was a problem starting.
            Nz---r  )re  zWriting logs to T)r  r  tie_breakerr  r   r  F)r  r  g      ?zcss monitorr!  STARTED)r`  r4   r  r  ra  re  r2   LOG_FILErc  r  abspathr  r  r  _get_default_cssr  r   r  r  r  r  r  r   r  r  rU  r  set_interval)	_log_pathr  cssrc  r  app_pathr  r   s          r   app_preludez*App._process_messages.<locals>.app_prelude  s     %%'''HHOOE"HHOO!9!9!;O<HHOOT]]O3!!-GGOOI,>,>?	"29- @A==OO,,T]];:>:O:O:Q 6IsKOO.."+'+$/# /  88&#*??4>>#B "*dnn.E.E-Fd+K LIOO..Ie /  !!$(8(8}!M	4+;+;<I (, &w/ &#%&  &&u---/sa   I#HCI#'A7H, H >AH, AI#H)&H, (H))H, ,	I 5!II#I  I#c                   K   dfd} j                         5  	 	 j                  t        j                                d{    j                  t        j                  j                  j                  d             d{    j                  }j                  j                         j                  t        j                                d{    j                          j                  j                          d_        t        j                          j                  |urj                  j                  |       j"                  j%                          d{    	 d_        j-                          d{     |         d{    	 ddd       	 j/                          d{    j4                  j7                          d_        	 j"                  j)                          d{    t9        j:                  j<                         d{    y7 7 7 Y# j                  j                          d_        w xY w7 # t&        $ r% j"                  j)                          d{  7    w xY w7 7 # d_        j-                          d{  7    |         d{  7   w xY w# 1 sw Y   +xY w7 # t0        j2                  $ r Y .w xY w7 7 # t9        j:                  j<                         d{  7   w xY w# j4                  j7                          d_        	 j"                  j)                          d{  7   t9        j:                  j<                         d{  7   w # t9        j:                  j<                         d{  7   w xY wxY ww)z$The main message loop, invoke below.c                 f   K   (        } t        j                  |       r|  d {    y y y 7 wr   )r  isawaitable)ready_resultr^  s    r   invoke_ready_callbackzRApp._process_messages.<locals>.run_process_messages.<locals>.invoke_ready_callback  s;     !-#1#3L**<8*** 9 . +s   $1/1NTFr   )r  _dispatch_messager3   ComposeResizefrom_dimensionsrN  rS  r  applyMountr  r  r&  _is_mountedry   _initialize_objectr  startr  stop_running_ready_process_messages_loopr  r  r  
cancel_allr   	_stop_all_timers)rq  r  r^  r   s     r   run_process_messagesz3App._process_messages.<locals>.run_process_messages  s    + ""$ 220"44V^^5EFFF"44"MM99$))TJ   *.--d3"44V\\^DDD)++//1+/(//5{{.8--n=----/// %)DM++-''/111;2>
811333 '') %8--,,...//$,,777M G
 E ++//1+/( 0  --,,... (1 %)DM++-''/111;2 2@ 4))  /7%//$,,777 '') %8--,,...//$,,777%//$,,777s  N?K&H2H)A H2H,AH2H/H2+A<I'I(I-KJKJKN?%K 8K9K =!N?K3 <K/=K3 "N?#K1$N?)H2,H2/H22#II&J JJJKKK+J.
,K;J>
<KKK
N?K K,(L  +K,,L  /K3 1N?3#LLLN? "N<N M#!N&"N<N	N<#N92N53N99N<<N?T)rV  r9  rn  rN  )r?  r   r   )$r  r*  r|  r3   Loadrr  r[  r  r4   r  start_application_moder   r  r
   r  ry   _clear_watchersr1  r  r   r(   movesegmentr   r   r   r  r$   r  rS  r  r   r!  stop_application_moder  r  )r   r^  rV  r9  rm  rn  r_  rD   rl  r  
load_eventr?  cursor_xcursor_yrv  r  s   ``              r   rb  zApp._process_messages  s\     	*	X2	8h ]]_ ,	.$&&,	. ,	. !DM(.#[[]
,,Z888(,(:(:%!&	 ); )  'zz1137,T-A-AB =!01E1E!F =&:&< < <==
 !006<<11151O1O.Hh LL.. 'hY	 B J J O O !LL..0.txx7Q7Q*1)!4$+MM$++2I2I$J !% 2 2$+LLT5H5H4H$I$Q$Q$V$V!" 446U,	. ,	.&
 9 !== == =  (8 !4$+MMO!4 !006<<11151O1O.Hh LL.. 'hY	 B J J O O !LL..0.txx7Q7Q*1)!4$+MM$++2I2I$J'7 !4$+MMO!4 !% 2 2$+LLT5H5H4H$I$Q$Q$V$V!" 446 .&&u--.W,	. ,	.s  -P<P0I!P0	P<P0(P;I$<APJ#!I77I*I'
I*I7J#B<P%J9AP	P<!P0$P'I**I4/I77J	<J#J PJ  P#B=P!%NPN#	 P"N#	#A"PP	P-P("P0(P--P00P95P<c                   K   yw)zNSpecial case for the app, which doesn't need the functionality in MessagePump.Tr   r   s    r   _pre_processzApp._pre_process)  s	     r  c                    K   t                j                  z
  dz  } j                  j                  d|dd       d
 fd}t        j
                  dk\  r# j                  t        j
                  |d       y	y	w)zCalled immediately prior to processing messages.

        May be used as a hook for any operations that should run first.
        r4  z	ready in z0.0fz millisecondsc                    K    j                  t        j                  t        j                          j	                          yw)zTake a screenshot and exit.)r  r  N)r  r2   SCREENSHOT_LOCATIONSCREENSHOT_FILENAMEr[  r   s   r   take_screenshotz#App._ready.<locals>.take_screenshot6  s7       22"66 !  IIKs   AAr   zscreenshot timerr!  Nr   )r   r`  r4   r  r2   SCREENSHOT_DELAYr#  )r   
ready_timer  s   `  r   r}  z
App._ready-  su      #nt'7'774?
)Jt#4MBC	 %%*NN**OBT   +s   A8A;c                   K   d}| j                   | _        	 g | j                   j                  t        |       }| j                  |       d {    y # t        $ r}t	        | d|       |d }~ww xY w7 'w)NTz. compose() method returned an invalid result; )rS  r  _nodesrZ   r  r  )r   _rich_traceback_omitr  r  s       r   _on_composezApp._on_composeC  s     ##{{	;**;WT];G nnW%%%  	(HP	
 	&s3   A8#A A8A6A8	A3A..A33A8c                h   K   | j                   r d| _         | j                          d{    yy7 w)z!Check if a recompose is required.FN)r  	recomposer   s    r   _check_recomposezApp._check_recomposeO  s/     ##',D$..""" $"s   '202c                  K   | j                   ry	 | j                  j                         4 d{    | j                  j                  d      j	                  d      j                          d{    | j                  j                  t        |              d{    ddd      d{    y7 7 C7 7 # 1 d{  7  sw Y   yxY w# t        $ r Y yw xY ww)zrRecompose the widget.

        Recomposing will remove children and call `self.compose` again to remount.
        Nr  z.-textual-system)	r  rS  batchrh  excluder  r  rZ   r   r   s    r   r  zApp.recomposeU  s     
 ::	{{((* ; ;kk'',445GHOOQQQkk++GDM:::; ; ;Q:; ; ; ;   		s   CC B1C <B9/B30+B9B5B9 C +B7,C 0C1C 3B95B97C 9C?C CC 
CC 	CCCCc                |   ||t        d      || j                  vr||j                  j                  ||       nB|%|dk7  r |j                  j                  |dz   |       n|j                  j	                  |       | j                  j                  |       |j                  |       |j                  |        yy)a  Register a widget as a child of another.

        Args:
            parent: Parent node.
            child: The child widget to register.
            widgets: The widget to register.
            before: A location to mount before.
            after: A location to mount after.
        Nz2Only one of 'before' and 'after' may be specified.r   r   )r   r  r  _insert_appendadd_attach_post_register)r   parentchildr  r  s        r   _register_childzApp._register_childc  s    $ %"3OPP &!%%fe4"u{ %%eai7
 %%e, NNu%MM&!  &- 'r   )r  r  cachec                  |sg S |i }||t        |      }n|}| j                  j                  }g }|j                  }	|D ]  }
d|
_        d|
_        d|
_        t        |
t              st        d|
d      |
| j                  vsF |	|
       | j                  ||
||       |
j                  so | j                  |
g|
j                  d|i  |D ]  }
 ||
|       |
j                           | j                  sg S t!        |      S )a[  Register widget(s) so they may receive events.

        Args:
            parent: Parent node.
            *widgets: The widget(s) to register.
            before: A location to mount before.
            after: A location to mount after.
            cache: Optional rules map cache.

        Returns:
            List of modified widgets.
        FzCan't register z; expected a Widget instancer  )r  )r	  r  rv  rp  _closing_closed_pruningr  r   r   r  r  r  r  _start_messagesr|  r>  )r   r  r  r  r  r  widget_listapply_stylesheetnew_widgetsadd_new_widgetr&  s              r   r  zApp._register  s!   * I=E!2 #7+K!K??00$&$++! 
	HF#FO"FN#FOff-
:VWXXT^^+v&$$VVVUC=="DNN6GFMMGG
	H " 	%FV51""$	% }}IG}r   c                    |j                          t        |j                  t              r5|j                  j                  j                  |       |j                          | j                  j                  |       y)zWUnregister a widget.

        Args:
            widget: A Widget to unregister
        N)	r7  r  _parentr   r  _remove_detachr  discardr9  s     r   _unregisterzApp._unregister  sO     	fnnf-NN!!))&1NNv&r   c                n   K   | j                   #| j                   j                          d {    y y 7 wr   )rV  
disconnectr   s    r   _disconnect_devtoolszApp._disconnect_devtools  s.     ==$--**,,, %,s   *535c                    |j                  |       |j                          | j                  j                  j	                  |       y)zStart a widget (run its task) so that it can receive messages.

        Args:
            parent: The parent of the Widget.
            widget: The Widget to start.
        N)r  r  r   r  r  )r   r  r&  s      r   _start_widgetzApp._start_widget  s4     	v v&r   c                    || j                   v S )zCheck if a widget is mounted.

        Args:
            widget: A widget.

        Returns:
            True of the widget is mounted.
        )r  r9  s     r   
is_mountedzApp.is_mounted  s     ''r   c                  K   | j                   j                         D ]H  }t        |      D ](  }|j                  s| j	                  |       d{    * |j                          J | j                  j                          | j                  j                          t        | j                        }|D ]  }|j                          d{     y7 7 	w)zClose all message pumps.N)r{  rg  r	  r|  _prunerS  r  r  r>  r  _close_messages)r   r  stack_screenremaining_nodesr  s        r   
_close_allzApp._close_all  s      ((//1 	E ( 4((++l3334 KKM		
 	%%' t~~.$ 	*E'')))	* 4 *s)   8CCCA9C	C
CCc                   K   | j                          | j                  }d| _        ||j                          | j	                          d {    | j                          d {    | j                  t        j                                d {    | j                  | j                  j                          | j                  j                          | j                  .| j                  j                  r| j                          d {    | j                          t         j"                  rFddlm} ddlm}  |       }|j-                  d       |j-                   || j.                               y y 7 )7 7 7 sw)NFr   )r$   )Prettyz[b]The app returned:)r  r  r|  disable_inputr  r  rr  r3   Unmountcloser  _clearrV  r  r  rU  r2   SHOW_RETURNrich.consoler$   rich.prettyr  r  r  )r   r?  r$   r  rv  s        r   rh  zApp._shutdown  s!      "oo""$$$$$V^^%5666<<#LL ==$)C)C++---%%'  ,*iGMM01MM&!3!345 ! 	 $6 .sJ   A	E>E4E>#E7$*E>E:A9E>E<	A,E>7E>:E><E>c                b   K   | j                          | j                  j                  d        y wr   )r  r  
put_nowaitr   s    r   _on_exit_appzApp._on_exit_app"  s&     &&t,s   -/)repaintlayoutr  c                   |r$|| _         | j                  | j                         | S | j                  r| j                  j                  ||       | j                          | S )a/  Refresh the entire screen.

        Args:
            repaint: Repaint the widget (will call render() again).
            layout: Also layout widgets in the view.
            recompose: Re-compose the widget (will remove and re-mount children).

        Returns:
            The `App` instance.
        )r  r  )r  r  r  r
  rS  r  r  )r   r  r  r  s       r   r  zApp.refresh&  sU    " '0D$NN4001KKK?r   c                   | j                   j                  }|j                  | j                                |j	                          |j                  | j                   |       	 | j                  j                  r@| j                  j                  | j                         | j                  | j                  _
        | j                  D ]6  }|| j                  k7  s|j                  ||       | j                  |_
        8 y# t        $ r Y Qw xY w)zVRefresh CSS.

        Args:
            animate: Also execute CSS animations.
        r  N)r   r  set_variablesr  r  rZ  rS  r  _refresh_layoutrN  r  r   rH  )r   r8  r  rS  s       r   r  zApp.refresh_cssA  s     XX((
  !7!7!9:$((G4	{{%%++DII6040F0F- '' 	BF$!!&'!:+/+A+A(	B  		s   $AD   	DDc                H  	
 	 |	 | j                          y| j                  r	 | j                          y| j                  r| j                  s| j                  s| j
                  | j                  }| j                          	 	 t        |t              r| j                  j                  j                  | j                        }| j
                  j                  rot        j                   | j"                    j$                  j&                  

|j)                  |      z  

t        j                   | j$                  j&                  z  
n:|j)                  |      

t        j*                  | j$                  j&                  z  
|| _        n"|j-                  |      }|j/                  |      
t0        rFd	| j
                  j2                  }	
fdt5        dt7        
      	      D        D ]
  } ||        n| j
                  j3                  
       	 | j=                          | j
                  j?                          | j                          y# t8        $ r}| j;                  |       Y d}~Zd}~ww xY w# | j=                          w xY w# | j                          w xY w)zDisplay a renderable within a sync.

        Args:
            screen: Screen instance
            renderable: A Rich renderable.
        Ni    c              3  .   K   | ]  }||z      y wr   r   )r  offset
CHUNK_SIZEterminal_sequences     r   r  zApp._display.<locals>.<genexpr>  s%      *$* !2&6J;N O*s   r   ) post_display_hookr  r|  r  rC  r  rv  _begin_updater  rA   rS  
outer_sizeclamp_offsetr  r1  r(   r  r  r  r   render_segmentsmove_tor  _render_bufferr  r   ranger  r  r  _end_updater   )r   rS  r<  rv  r  r@  r   chunkr  r  r  s            @@r   _displayzApp._displayY  sN   =	%!v ""$u   r ""$o ((LL,,,""$+'(B%j2BC.2kk.D.D.Q.Q $ 4 4/O  $||554;LL'+'E'E&E5"")'$$ !2 !2Z5O5OPW5X X 1 1W\\%46"")'$$!/ 1 5?4N4Nw4W 1 1W__%46"")'$$!/ 1 >MD:'.~~j'AH070F0Fx0P- #
 *.J$(LL$6$6E*.3$%s+<'=z/"* - !&e- !LL../@A$$&""$ ""$3 % 6..u556( $$&
 ""$sT   J J AJ D(I 0A(I: *J 	I7I2-I: 2I77I: :JJ J!c                     y)z:Called immediately after a display is done. Used in tests.Nr   r   s    r   r  zApp.post_display_hook  s    r   c                :    | j                   j                  ||      S )zGet the widget under the given coordinates.

        Args:
            x: X coordinate.
            y: Y coordinate.

        Returns:
            The widget and the widget's screen region.
        )rS  get_widget_at)r   xys      r   r  zApp.get_widget_at  s     {{((A..r   c                n    | j                   s)| j                  | j                  j                  d       yyy)zPlay the console 'bell'.

        For terminals that support a bell, this typically makes a notification or error sound.
        Some terminals may make no sound or display a visual bell indicator, depending on configuration.
        Nr  )rC  r  r   r   s    r   r  zApp.bell  s0     DLL$<LLu% %=r   c                    | j                   }|2| j                  | j                  j                  f| | j                  fg}|S |j                  D cg c]  }||j                  f }}|S c c}w )a  Get a chain of nodes and bindings to consider.

        If no widget is focused, returns the bindings from both the screen and the app level bindings.
        Otherwise, combines all the bindings from the currently focused node up the DOM to the root App.
        )rT  rS  r  ancestors_with_self)r   rT  namespace_bindingsr  s       r   _binding_chainzApp._binding_chain  s     ,, ?dkk334t~~&" "! 4;3N3N"+/t~~&" " "!	"s   A(c                N    | j                  t        j                  |d             y)zSimulate a key press.

        This will perform the same action as if the user had pressed the key.

        Args:
            key: Key to simulate. May also be the name of a key, e.g. "space".
        N)rW  r3   r<  r   r  s     r   simulate_keyzApp.simulate_key  s     	&**S$/0r   c                B  K   |rt        | j                  j                        n| j                  j                  D ]_  \  }}|j                  j                  |d      }|D ]9  }|j                  |k(  s| j                  |j                  |       d{   s8  y a y7 w)a-  Handle a key press.

        This method is used internally by the bindings system.

        Args:
            key: A key.
            priority: If `True` check from `App` down, otherwise from focused up.

        Returns:
            True if the key was handled by a binding, otherwise False
        r   NTF)	r	  rS  r  _modal_binding_chainkey_to_bindingsr:  r  
run_actionr  )r   r  r  	namespacebindingskey_bindingsr  s          r   _check_bindingszApp._check_bindings  s       T[[//011		$Ix
 $3377R@L' $##x/!__W^^YGGG#$		$  Hs   A.B1BBBBc                    | j                   j                         D ]6  \  }}|j                  j                  dv s| j	                  d| dd        y y)z:Bound to ctrl+C to alert the user that it no longer quits.)r  zapp.quitz	Press [b]z[/b] to quit the appzDo you want to quit?r  N)r_  r  r  r  notify)r   r  active_bindings      r   action_help_quitzApp.action_help_quit  sb     $(#7#7#=#=#? 	C%%,,0DDu$89AW   	r   c                h    |j                         D ci c]  \  }}|t        |       c}}S c c}}w )z]Normalizes the keys in a keymap, so they use long form, i.e. "question_mark" rather than "?".)r  rq   )r  keymap
binding_idr*  s       r   _normalize_keymapzApp._normalize_keymap  s8     KQ,,.
6Fj$J+D11
 	
 
s   .c                P    | j                  |      | _        | j                          y)a  Set the keymap, a mapping of binding IDs to key strings.

        Bindings in the keymap are used to override default key bindings,
        i.e. those defined in `BINDINGS` class variables.

        Bindings with IDs that are present in the keymap will have
        their key string replaced with the value from the keymap.

        Args:
            keymap: A mapping of binding IDs to key strings.
        N)r  r  refresh_bindingsr   r  s     r   
set_keymapzApp.set_keymap  s"     --f5r   c                l    i | j                   | j                  |      | _         | j                          y)a  Update the App's keymap, merging with `keymap`.

        If a Binding ID exists in both the App's keymap and the `keymap`
        argument, the `keymap` argument takes precedence.

        Args:
            keymap: A mapping of binding IDs to key strings.
        N)r  r  r  r  s     r   update_keymapzApp.update_keymap  s1     J$,,I$*@*@*HIr   c                     y)a  Handle a clash between bindings.

        Bindings clashes are likely due to users setting conflicting
        keys via their keymap.

        This method is intended to be overridden by subclasses.

        Textual will call this each time a clash is encountered -
        which may be on each keypress if a clashing widget is focused
        or is in the bindings chain.

        Args:
            clashed_bindings: The bindings that are clashing.
            node: The node that has the clashing bindings.
        Nr   )r   clashed_bindingsr  s      r   handle_bindings_clashzApp.handle_bindings_clash"  s    $ 	r   c                  K   t        |t        j                        r;| j                  | j                         d {    t
        
|   |       d {    y t        |t        j                        r|j                  s| j                  s1t        |t        j                  t        j                  f      rd| _	        t        |t        j                        rt        |j                  |j                        | _        t        |t        j                        r/	 | j#                  |j                  |j                        \  | _        }| j(                  j+                  |       t        |t        j,                        r| j$                  	 |j.                  }| j$                  } | j"                  | \  }}||u r| j0                  d uxr | j0                  |k(  }| j2                  d uxr& |j4                  | j2                  z
  | j6                  k  }|r|r| xj8                  dz  c_        nd| _        t        j:                  j=                  ||| j8                        }|j4                  | _        || _        | j(                  j+                  |       y y t        |t        j                        r| j(                  j>                  6|j@                  dk(  r'| jB                  r| j(                  jE                          y | jF                  r	 | j(                  jI                          | jM                  |j@                  d       d {   sH| jF                  xs | j(                  }	|	j+                  |       y | j(                  j+                  |       y y y y t        |t        jN                        rP|j                  sD| jF                  | jF                  j+                  |       y | j(                  j+                  |       y t
        
|   |       d {    y 7 7 # t&        $ r d | _        Y w xY w# t&        $ r Y y w xY w# tJ        $ r Y *w xY w7 7 Dw)NTr   )chainescape)r  )(r  r3   rs  r  r|  ra  on_event
InputEventis_forwardedr'  r<  	MouseDown
MouseEventrk   r  r  r  r  r  rc   rS  _forward_eventMouseUpscreen_offsetr  r  r  r  r  Click
from_eventrk  r  escape_to_minimizeminimizerT  _clear_tooltipra   r  Paste)r   eventr  r  mouse_down_widgetmouse_up_widgetsame_offsetwithin_time_thresholdclick_eventforward_targetr  s             r   r  zApp.on_event6  s     eV^^,//$"4"4555'"5)))v001%:L:L>>jVEUEU8V&W!%%!2!23&,UWWegg&>#eV%5%567595G5G!GGUWW62/ **51
 ufnn5//;(-(;(;,0,C,C)-?T-?-?-O**.?? $ = =T I !S$($A$A]$R (
 !% ; ;4 G !C$)JJ1L1L$L#'#B#B%C 2  +/D $ 4 4 9 478 4*0,,*A*A 15@T@T +B +K ;@**D7<ID9 KK66{C/ @6 E6::. KK))5		X-//KK((*<<224 "11%))d1KKK%)\\%@T[[N"11%8**51	 La < 6n v||,U5G5G||'++E2**51'"5)))g 6) $ 726/7P $   $ K *s   9QPQPCQ.P AQDP, A4QP;  Q=Q>CQ	Q
QQP)%Q(P))Q,	P85Q7P88Q;	QQQQQc                    t        | j                  j                  | j                        S | j                  j                        S )a  Use the escape key to minimize?

        When a widget is [maximized][textual.screen.Screen.maximize], 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.

        )r   rS  r  r   s    r   r  zApp.escape_to_minimize  sE     {{--5 ##
 	
 //
 	
r   c                "   t        |t              r|\  }}}nt        j                  |      \  }}}|dn|j	                  |      }|r=|;|| j
                  vrt        d| d      t        | |d      }|t        d|d      ||||fS |||fS )a  Parse an action.

        Args:
            action: An action string.
            default_namespace: Namespace to user when none is supplied in the action.
            namespaces: Mapping of namespaces.

        Raises:
            ActionError: If there are any errors parsing the action string.

        Returns:
            A tuple of (node or None, action name, tuple of parameters).
        NzAction namespace z is not knownzAction target z not available)r  tupler1   r  r:  r  r   r  )r   r  default_namespace
namespacesdestinationaction_nameparamsaction_targets           r   _parse_actionzApp._parse_action  s    & fe$/5,Kf/6}}V/D,Kf &DJNN;,G 	 =0$"6"66!$5k]-"PQQ#D+t<M$!N;/"PQQ"/"7
 	
=J
 	
r   c                R    | j                  ||      \  }}}|j                  ||      S )zCheck if an action is enabled.

        Args:
            action: An action string.
            default_namespace: The default namespace if one is not specified in the action.

        Returns:
            State of an action.
        )r.  check_action)r   r  r(  r-  r+  
parameterss         r   _check_action_statezApp._check_action_state  s6     261C1C%2
.{J ))+zBBr   c                   K   | j                  ||| n||      \  }}}|j                  ||      r| j                  |||       d{   S y7 w)a  Perform an [action](/guide/actions).

        Actions are typically associated with key bindings, where you wouldn't need to call this method manually.

        Args:
            action: Action encoded in a string.
            default_namespace: Namespace to use if not provided in the action,
                or None to use app.
            namespaces: Mapping of namespaces.

        Returns:
            True if the event has been handled.
        NF)r.  r0  _dispatch_action)r   r  r(  r)  r-  r+  r,  s          r   r  zApp.run_action  sb     & .2-?-?-5D;Lj.
*{F %%k6:..}k6RRR Ss   AAAAc           	       K   d}t        j                  d|||       	 t        |d| d      }t        |      rt	        |g|  d{    yt        |d| d      }t        |      rt	        |g|  d{    yt        j                  d|d| d	| d
       y7 U7 '# t
        $ r t        j                  d|d       Y yw xY ww)a  Dispatch an action to an action method.

        Args:
            namespace: Namespace (object) of action.
            action_name: Name of the action.
            params: Action parameters.

        Returns:
            True if handled, otherwise False.
        Tz<action>)r  r+  r,  _action_Naction_z	<action> z0 has no target. Could not find methods '_action_z' or 'action_'z	 skipped.F)r4   r  r  r  r?   rO   )r   r  r+  r,  _rich_traceback_guardprivate_methodpublic_methods          r   r4  zApp._dispatch_action  s      !%

#		
	=$Y(;-0H$ON'^5f555#I/FMM&]4V444JJK? +44?=k]Z[]  6 5  	=JJ;/;<		=sd   C*B# 	B
B# C*B# 9B!:B# >C?B# CB# !B# #"CCCCc                2  K   	 t        |d      }	 t        ||j                        \  }}|j	                          t        |t              r| j                  ||       d{    yt        |t              rJt        |      dk(  r<|\  }}t        j                  |      \  }	}
}| j                  |	|
|f|       d{    yt        |t              r%| j                  rt        j                  d| d       y# t        $ r Y yw xY w# t
        $ r Y yw xY w7 7 [w)a2  Allow the app an opportunity to dispatch events to action system.

        Args:
            event_name: _description_
            event: An event object.
            default_namespace: The default namespace, where one isn't supplied.

        Returns:
            True if an action was processed.
        r  FN   zCan't parse @z9 action from style meta; check your console markup syntaxT)r  AttributeErrorrG   metar{  rF   r  r   r  r'  r  r1   r  r  r4   r  )r   
event_namer  r(  r  
_modifiersr  r+  action_paramsr  parsed_actionr  s               r   _broker_eventzApp._broker_event  s"    	E7+E	!8UZZ!PJ JJLfc"//&*;<<<" ! &3v;!+;)/&K*1--*D'I}a//M=9!    &%(TZZ #J</hi 5  		  		 =sc   DC5 D 5DD AD9D:;D5	D>D DD	DDDDDc                ,   K   |j                          y wr   r{  r   rZ  s     r   
_on_updatezApp._on_updateH          c                ,   K   |j                          y wr   rF  rG  s     r   
_on_layoutzApp._on_layoutK  rI  rJ  c                   K   | j                  |j                         d {   st        | |       d {    y y 7 7 wr   )r  r  rE   r   r  s     r   _on_keyzApp._on_keyN  s7     **599555tU+++ 6+s   A <A >A A c                \   K   |j                          |j                  | _        || _        y wr   )r{  rN  r  r  rN  s     r   
_on_resizezApp._on_resizeR  s"     

ZZ
"s   *,c                N   K   d| _         | j                  j                          yw)zApp has focus.TNr'  rS  r  rN  s     r   _on_app_focuszApp._on_app_focusW  s      $$&   #%c                N   K   d| _         | j                  j                          yw)zApp has lost focus.FNrS  rN  s     r   _on_app_blurzApp._on_app_blur]  s      $$&rU  )r  c                    |st        g       S h |}|D ]<  }|j                  t                      |j                  |j	                  d             > 	 |d   j
                  }|j                  r4|j                  |v r&|j                  |j                  t        |             	 |D ]	  }d|_         d fd}t        |D cg c]  }|j                  x}| c}|      } j                  |       |S # t        t        f$ r Y bw xY wc c}w )zPrune nodes from DOM.

        Args:
            parent: Parent node.

        Returns:
            Optional awaitable.
        Tr  r   c                     >	 j                   } | j                  rj                  |        	 j                  d       yy# t        t        f$ r Y %w xY w# j                  d       w xY w)zCalled after removing children.NTr  )rS  r|  r5  r   ra   r  )rS  r  r   s    r   
post_mountzApp._prune.<locals>.post_mount~  sm     !0#]]F //7NN$N/ " )(3  NN$N/s(   A A AA AA A,r   )rQ   rW  rt   rZ  r  rS  rT  _reset_focusr>  r   ra   r  re  r  )	r   r  nodespruning_nodesr  rS  r[  taskawait_completes	   ``       r   r  z
App._prunec  s    r?"%-uX 	EDeg&  !3!3d!3!CD	E	I1X__F ~~&..M"A##FNND4GH! 	!D DM	!	0 %#Hd

(:'GTH
 	~&9 !(+ 		0 Is   C6 DD6DDc                   | j                   j                          |ru	 | j                  `| j                  j                   | j                   u r>| j                   j                  (| j                   j	                  | j                  dd       d| _        y| j                   j                  | _        | j                   j	                  d       y# t
        $ r
 Y d| _        yw xY w)z Respond to changes in app focus.NFT)r'  from_app_focus)rS  _update_stylesr  rT  r%  ra   )r   r6  s     r   _watch_app_focuszApp._watch_app_focus  s    ""$22>66==L++3 KK))66','+ *  .2D* .2[[-@-@D*KK!!$'   .2D*	s   A,C	 		CCc                .   K   | j                  |       yw)zAn [action](/guide/actions) to simulate a key press.

        This will invoke the same actions as if the user had pressed the key.

        Args:
            key: The key to process.
        N)r  r  s     r   action_simulate_keyzApp.action_simulate_key  s      	#   c                ,   K   | j                          yw)z@An [action](/guide/actions) to quit the app as soon as possible.N)r[  r   s    r   rg  zApp.action_quit       		rJ  c                ,   K   | j                          yw)z8An [action](/guide/actions) to play the terminal 'bell'.N)r  r   s    r   action_bellzApp.action_bell  ri  rJ  c                   K   	 | j                  d|       j                         }t        |t              r| j	                  |       yy# t
        $ r Y yw xY ww)z|An [action](/guide/actions) to focus the given widget.

        Args:
            widget_id: ID of widget to focus.
        #N)rh  firstr  r   r%  r]   )r   	widget_idr  s      r   action_focuszApp.action_focus  sX     	%::)o.446D $'t$ (  		s'   A"A	 #A		AAAAc                .   K   | j                  |       yw)znAn [action](/guide/actions) to switch screens.

        Args:
            screen: Name of the screen.
        N)r  ro  s     r   action_switch_screenzApp.action_switch_screen  s      	6"rg  c                .   K   | j                  |       yw)zAn [action](/guide/actions) to push a new screen on to the stack and make it active.

        Args:
            screen: Name of the screen.
        N)r$  ro  s     r   action_push_screenzApp.action_push_screen  s      	 rg  c                ,   K   | j                          yw)zaAn [action](/guide/actions) to remove the topmost screen and makes the new topmost screen active.N)r  r   s    r   action_pop_screenzApp.action_pop_screen  s     rJ  c                .   K   | j                  |       yw)z<An [action](/guide/actions) that switches to the given mode.N)r  )r   r  s     r   action_switch_modezApp.action_switch_mode  s     rg  c                L   K   	 | j                          y# t        $ r Y yw xY ww)a$  An [action](/guide/actions) to go back to the previous screen (pop the current screen).

        Note:
            If there is no screen to go back to, this is a non-operation (in
            other words it's safe to call even if there are no other screens
            on the stack.)
        N)r  r   r   s    r   action_backzApp.action_back  s&     	OO 		s   $ $	!$!$c                `   K   | j                   j                  |      j                  |       yw)zAn [action](/guide/actions) to add a CSS class to the selected widget.

        Args:
            selector: Selects the widget to add the class to.
            class_name: The class to add to the selected widget.
        N)rS  rh  	add_classr   selector
class_names      r   action_add_classzApp.action_add_class  s%      	(#--j9   ,.c                `   K   | j                   j                  |      j                  |       yw)zAn [action](/guide/actions) to remove a CSS class from the selected widget.

        Args:
            selector: Selects the widget to remove the class from.
            class_name: The class to remove from  the selected widget.N)rS  rh  remove_classr}  s      r   action_remove_classzApp.action_remove_class  s%      	(#00<r  c                `   K   | j                   j                  |      j                  |       yw)zAn [action](/guide/actions) to toggle a CSS class on the selected widget.

        Args:
            selector: Selects the widget to toggle the class on.
            class_name: The class to toggle on the selected widget.
        N)rS  rh  toggle_classr}  s      r   action_toggle_classzApp.action_toggle_class	  s%      	(#00<r  c                @    | j                   dk(  rd| _         yd| _         y)zAn [action](/guide/actions) to toggle the theme between textual-light
        and textual-dark. This is offered as a convenience to simplify backwards
        compatibility with previous versions of Textual which only had light mode
        and dark mode.ztextual-lightr  N)r?  r   s    r   action_toggle_darkzApp.action_toggle_dark  s#     #jjO;N 	
AP 	
r   c                8    | j                   j                          y)z5An [action](/guide/actions) to focus the next widget.N)rS  
focus_nextr   s    r   action_focus_nextzApp.action_focus_next  s     r   c                8    | j                   j                          y)z9An [action](/guide/actions) to focus the previous widget.N)rS  focus_previousr   s    r   action_focus_previouszApp.action_focus_previous  s    ""$r   c                V    | j                   j                  d      j                          y)z!Hide the keys panel (if present).ra  N)rS  rh  r  r   s    r   ri  zApp.action_hide_help_panel#  s    +&--/r   c                    ddl m} 	 | j                  j                  |       y# t        $ r# | j                  j                   |              Y yw xY w)zShow the keys panel.r   )ra  N)r  ra  rS  	query_oner]   r  )r   ra  s     r   rj  zApp.action_show_help_panel'  s?    -	+KK!!), 	+KKik*	+s   $ )AAinformationc                ,    | j                  |||       y)zShow a notification.r   severityN)r  )r   rZ  r   r  s       r   action_notifyzApp.action_notify0  s     	G58<r   c                    t        j                  d       | j                  | j                  j                  sd| _        y y y )Nz$SynchronizedOutput mode is supportedT)r4   r  r  r1  r}  rG  s     r   )_on_terminal_supports_synchronized_outputz-App._on_terminal_supports_synchronized_output6  s8     	

9:<<#DLL,B,B#'D  -C#r   c                v    | j                   r-| j                   | j                  j                  t               y y y r   )r}  r  r   r<   r   s    r   r  zApp._begin_update=  s.    DLL$<LLz* %=r   c                v    | j                   r-| j                   | j                  j                  t               y y y r   )r}  r  r   r;   r   s    r   r  zApp._end_updateA  s.    DLL$<LLx( %=r   c                    	 | j                   }	 |j                  t              }| j	                  |j
                  | j                         y# t        $ r Y yw xY w# t        $ r Y yw xY w)zERefresh the notifications on the current screen, if one is available.N)rS  r  r   r]   r"  r  r  r   )r   rS  
toast_racks      r   _refresh_notificationszApp._refresh_notificationsE  si    	B[[F#55i@
 OOJOOT-@-@A      		s"   A A 	AA	A&%A&c                X    	 | j                   j                          y# t        $ r Y yw xY w)z*Clear text selection on the active screen.N)rS  clear_selectionra   r   s    r   r  zApp.clear_selectionW  s)    	KK'') 		s    	)))r   r  timeoutrK  c               t    || j                   }t        |||||      }| j                  t        |             y)a  Create a notification.

        !!! tip

            This method is thread-safe.


        Args:
            message: The message for the notification.
            title: The title for the notification.
            severity: The severity of the notification.
            timeout: The timeout (in seconds) for the notification, or `None` for default.
            markup: Render the message as content markup?

        The `notify` method is used to create an application-wide
        notification, shown in a [`Toast`][textual.widgets._toast.Toast],
        normally originating in the bottom right corner of the display.

        Notifications can have the following severity levels:

        - `information`
        - `warning`
        - `error`

        The default is `information`.

        Example:
            ```python
            # Show an information notification.
            self.notify("It's an older code, sir, but it checks out.")

            # Show a warning. Note that Textual's notification system allows
            # for the use of Rich console markup.
            self.notify(
                "Now witness the firepower of this fully "
                "[b]ARMED[/b] and [i][b]OPERATIONAL[/b][/i] battle station!",
                title="Possible trap detected",
                severity="warning",
            )

            # Show an error. Set a longer timeout so it's noticed.
            self.notify("It's a trap!", severity="error", timeout=10)

            # Show an information notification, but without any sort of title.
            self.notify("It's against my programming to impersonate a deity.", title="")
            ```
        NrR  )r  ru   rW  rw   )r   rZ  r   r  r  rK  notifications          r   r  z
App.notify^  s:    p ?//G#GUHgfU&./r   c                n    | j                   j                  |j                         | j                          y)zHandle notification message.N)r  r  r  r  rN  s     r   
_on_notifyzApp._on_notify  s(     2 23##%r   c                D    | j                   |= |r| j                          yy)zRemove a notification from the notification collection.

        Args:
            notification: The notification to remove.
            refresh: Flag to say if the display of notifications should be refreshed.
        N)r  r  )r   r  r  s      r   	_unnotifyzApp._unnotify  s&     -'') r   c                X    | j                   j                          | j                          y)z$Clear all the current notifications.N)r  rS  r  r   s    r   clear_notificationszApp.clear_notifications  s     !!###%r   c                    | j                   r2t        j                  |       s| j                  t        d             yyy)z!Show the Textual command palette.z--command-paletterr  N)r  rW   is_openr$  r   s    r   action_command_palettezApp.action_command_palette  s5    ##N,B,B4,H^/BCD -I#r   c                :    | j                   j                  |        y)z/Signal that the application is being suspended.N)r  r  r   s    r   _suspend_signalzApp._suspend_signal  s    ''-r   c                :    | j                   j                  |        y)z?Signal that the application is being resumed from a suspension.N)r  r  r   s    r   _resume_signalzApp._resume_signal  s     	&&t,r   c              #  R  K   | j                   y| j                   j                  r| j                          | j                   j                          | j                   j	                         5  t        t        j                        5  t        t        j                        5  d ddd       ddd       ddd       | j                   j                          | j                          | j                  d       yt        d      # 1 sw Y   axY w# 1 sw Y   exY w# 1 sw Y   ixY ww)a:  A context manager that temporarily suspends the app.

        While inside the `with` block, the app will stop reading input and
        emitting output. Other applications will have full control of the
        terminal, configured as it was before the app started running. When
        the `with` block ends, the application will start reading input and
        emitting output again.

        Example:
            ```python
            with self.suspend():
                os.system("emacs -nw")
            ```

        Raises:
            SuspendNotSupported: If the environment doesn't support suspending.

        !!! note
            Suspending the application is currently only supported on
            Unix-like operating systems and Microsoft Windows. Suspending is
            not supported in Textual Web.
        NTrZ  z1App.suspend is not supported in this environment.)r  can_suspendr  suspend_application_modeno_automatic_restartr   r  r  r
   r  resume_application_moder  r  r   r   s    r   suspendzApp.suspend  s     0 <<<<##  "LL113 224 o7 s~~.   
 LL002!LLL%%C      sO   A(D'*DDD#D+D3AD'DDD	DD$ D'c                    t         sk| j                  ^| j                  j                  rG| j                          t	        j
                  t	        j                         t        j                         yyyy)a  Suspend the process into the background.

        Note:
            On Unix and Unix-like systems a `SIGTSTP` is sent to the
            application's process. Currently on Windows and when running
            under Textual Web this is a non-operation.
        N)	r  r  r  r  rc  killgetpidsignalSIGTSTPr   s    r   action_suspend_processzApp.action_suspend_process  sM     4<<38P8P   "GGBIIK0 9Q3wr   )new_tabc               V    | j                   | j                   j                  ||       yy)zOpen a URL in the default web browser.

        Args:
            url: The URL to open.
            new_tab: Whether to open the URL in a new tab.
        N)r  open_url)r   r_  r  s      r   r  zApp.open_url  s'     <<#LL!!#w/ $r   downloadr  r  r  rQ  r  r"  c          	     H   t        |t        t        f      r-t        |      }|j                  d      }	|xs |j                  }
n(|xs t        |dd      xs d}|}	|xs t        |dd      }
|
r|st        j                  |
      \  }}|d}| j                  |	||
||||      S )az  Deliver a text file to the end-user of the application.

        If a TextIO object is supplied, it will be closed by this method
        and *must not be used* after this method is called.

        If running in a terminal, this will save the file to the user's
        downloads directory.

        If running via a web browser, this will initiate a download via
        a single-use URL.

        After the file has been delivered, a `DeliveryComplete` message will be posted
        to this `App`, which contains the `delivery_key` returned by this method. By
        handling this message, you can add custom logic to your application that fires
        only after the file has been delivered.

        Args:
            path_or_file: The path or file-like object to save.
            save_directory: The directory to save the file to.
            save_filename: The filename to save the file to.  If `path_or_file`
                is a file-like object, the filename will be generated from
                the `name` attribute if available. If `path_or_file` is a path
                the filename will be generated from the path.
            encoding: The encoding to use when saving the file. If `None`,
                the encoding will be determined by supplied file-like object
                (if possible). If this is not possible, 'utf-8' will be used.
            mime_type: The MIME type of the file or None to guess based on file extension.
                If no MIME type is supplied and we cannot guess the MIME type, from the
                file extension, the MIME type will be set to "text/plain".
            name: A user-defined named which will be returned in [`DeliveryComplete`][textual.events.DeliveryComplete]
                and [`DeliveryComplete`][textual.events.DeliveryComplete].

        Returns:
            The delivery key that uniquely identifies the file delivery.
        rbrQ  Nr  r"  z
text/plainr  	r  r   r   r  r"  r  	mimetypes
guess_type_deliver_binary)r   path_or_filer  r  r  rQ  r  r"  binary_pathbinary	file_namer  s               r   r  zApp.deliver_text  s    ^ lS$K0|,K %%d+F%9)9)9IU7<T#JUgH!F%Lvt)LI Y$//	:LIq $I##)## $ 
 	
r   r  c          	        t        |t        t        f      r-t        |      }|j                  d      }|xs |j                  }	n|}|xs t        |dd      }	|	r|st        j                  |	      \  }}
|d}| j                  |||	||d|      S )a	  Deliver a binary file to the end-user of the application.

        If an IO object is supplied, it will be closed by this method
        and *must not be used* after it is supplied to this method.

        If running in a terminal, this will save the file to the user's
        downloads directory.

        If running via a web browser, this will initiate a download via
        a single-use URL.

        This operation runs in a thread when running on web, so this method
        returning does not indicate that the file has been delivered.

        After the file has been delivered, a `DeliveryComplete` message will be posted
        to this `App`, which contains the `delivery_key` returned by this method. By
        handling this message, you can add custom logic to your application that fires
        only after the file has been delivered.

        Args:
            path_or_file: The path or file-like object to save.
            save_directory: The directory to save the file to. If None,
                the default "downloads" directory will be used. This
                argument is ignored when running via the web.
            save_filename: The filename to save the file to. If None, the following logic
                applies to generate the filename:
                - If `path_or_file` is a file-like object, the filename will be taken from
                  the `name` attribute if available.
                - If `path_or_file` is a path, the filename will be taken from the path.
                - If a filename is not available, a filename will be generated using the
                  App's title and the current date and time.
            open_method: The method to use to open the file. "browser" will open the file in the
                web browser, "download" will initiate a download. Note that this can sometimes
                be impacted by the browser's settings.
            mime_type: The MIME type of the file or None to guess based on file extension.
                If no MIME type is supplied and we cannot guess the MIME type, from the
                file extension, the MIME type will be set to "application/octet-stream".
            name: A user-defined named which will be returned in [`DeliveryComplete`][textual.events.DeliveryComplete]
                and [`DeliveryComplete`][textual.events.DeliveryComplete].

        Returns:
            The delivery key that uniquely identifies the file delivery.
        r  r"  Nzapplication/octet-stream)r  r  r  r  rQ  r"  r  )r   r  r  r  r  r  r"  r  r  r  r  s              r   deliver_binaryzApp.deliver_binaryY  s    l lS$K0|,K %%d+F%9)9)9I!F%Lvt)LI Y$//	:LIq 2I##)## $ 
 	
r   )rQ  r  r"  c          	        | j                   y|t        | j                  d      }|
t               n
t	        |      }t        t        j                         j                        }| j                   j                  ||||z  ||||       |S )z9Deliver a binary file to the end-user of the application.Nr   )delivery_key	save_pathrQ  r  r  r"  )
r  rH   r   r#   r   r   uuiduuid4hexr  )	r   r  r  r  r  rQ  r  r"  r  s	            r   r  zApp._deliver_binary  s     <<  6tzz2FM &4%;!nAU 	
 4::<++,
 	##%$}4# 	$ 	
 r   c                    |j                   dk(  rJ|j                  | j                  dd       y| j                  dt        |j                        d       yy)z+Handle a successfully delivered screenshot.r  NzSaved screenshot
Screenshotr  zSaved screenshot to [green])r"  r  r  r   rN  s     r   _on_delivery_completezApp._on_delivery_complete  sW     ::%zz!.lC1#ejj/1DE&  	 &r   c                L    |j                   dk(  r| j                  ddd       yy)z+Handle a failure to deliver the screenshot.r  zFailed to save screenshotr  r  r  N)r"  r  rN  s     r   _on_delivery_failedzApp._on_delivery_failed  s-     ::%KK+<'   &r   c                \    |j                   | _        | j                  j                  |       y)z/In band window resize enables smooth scrolling.N)rE  r  r4   r  rG  s     r   _on_in_band_window_resizezApp._on_in_band_window_resize  s      *1&wr   c                    | j                   }|Ed| _         | j                  j                  |       | j                  D ]  }|j                  |        yy)zLSend app resize events on idle, so we don't do more resizing that necessary.N)r  rS  rW  r  )r   r  rS  s      r   _on_idlezApp._on_idle  sU    ""!%DKK$$U+22 +##E*+ r   )NNFF)rz  zType[Driver] | Noner  zCSSPathType | Noner  r   r3  r   )r   zSequence[LineFilter]r   )r   zasyncio.Eventr   )r   r`   )r   r   r   r   )r>  r   r   r   )r   r|   )r   r   r  )r   
int | None)r   zSequence['Widget'])r   r   )r   r   r>  r   r   r[   )r   zGenerator[None, None, None])g?)r$  r  r   r   )r3  r   r   r   )r6  r   r7  zfloat | Animatabler/  objectr0  r  r1  r  r$  r  r2  zEasingFunction | strr3  CallbackType | Noner4  rL   r   r   )T)r6  r   r;  r   r   r   )r   zlist[Screen[Any]])r   r&   )Nr   N)rY  r  r  r   rZ  RenderableType | Noner   r   )r   Widget | None)r   zdict[str, ActiveBinding])rS  r|   r   zIterable[SystemCommand])r   ComposeResult)r   zdict[str, str])r~  r   r   zTheme | None)r?  r   r   r   )r~  r   r   r   )r   zdict[str, Theme])r   r   )r~  r   r   r   )r?  r-   r   r   )r   r-   )r   zType[Driver])r   zrich.repr.Result)r   r9   )r   zScreen[object])r   zlist[Screen])r   rm   r   )r   r.   )
r  r/   r  r0   r  zinspect.Tracebackr  r   r   r   )r   r   r   )r   zECallable[..., CallThreadReturnType | Awaitable[CallThreadReturnType]]r  r   r  r   r   r   )NN)r  r  r  r  r   r   )r   r  r  r   r   r   )NNN)r  r  r  r  r  r  r   r   )r  r  r  r  r  r  r   r  )u   Search for commands…)r%  zSequence[CommandListItem]r#  r   r   r   )r*  r   r  r   r(  r   r  r   r_  r  r   r   )r  rR   r   r   )r*  zIterable[str]r   r   r   )r   r   r   r   )r   r   r   r   r   r   )TT)rL  r   rQ  r   r   r   r   r   )rL  r   r   r   )rV  r   rN  tuple[int, int] | NonerW  r   rX  r   rD    Callable[[Message], None] | Noner   z'AsyncGenerator[Pilot[ReturnType], None])rV  r   r9  r   rm  r   rn  r   rN  r  ro  AutopilotCallbackType | Noner   r  )rV  r   r9  r   rm  r   rn  r   rN  r  ro  r  r  zAbstractEventLoop | Noner   r  )r   r   )rs  r   r   r   )rs  r   r  type[ExpectType]r   r  r   )rs  r   r  ztype[ExpectType] | Noner   zExpectType | Widget)r  r  r   r  )r  r`   r   r   )r  r   r  int | str | Widget | Noner  r  r   r   )r  zIterable[Widget]r  r  r  r  r   r   )r  r   r   r   )r  r   r  zstr | Callable[[], Screen]r   r   )r  r   r   rP   )rS  Screen | strr   r   )rS  r   r   r   )rS  r   r   r|   )rS  r   r  Type[ScreenType] | Noner   r   )rS  r   r  r  r   r   )rS  r  r  zType[Screen] | Noner   r|   )rS  r  r   ztuple[Screen, AwaitMount])rS  r|   )rS  r|   r   r|   )NF)rS  Screen[ScreenResultType] | strr   1ScreenResultCallbackType[ScreenResultType] | Noner  zLiteral[False]r   r   r   )rS  r  r   r  r  zLiteral[True]r   z asyncio.Future[ScreenResultType])rS  r  r   r  r  r   r   z-AwaitMount | asyncio.Future[ScreenResultType])rS  zScreen[ScreenResultType]r   r~   )rS  r   r   r   )rS  r  r   zScreenResultType | Any)rS  r  r   rP   )rS  r|   r"  r   r   r   )rS  r  r   r  )r   rP   )rS  r|   r   r   )r&  r  r'  r   r   r   )r&  r  r,  r  r   r   )r&  r  r   r   )rC  r'   r   r   )r  r  r   r   )
rV  r   r9  r   rn  r   rN  r  r   rb   )NFFFTNN)r^  r  rV  r   r9  r   rm  r   rn  r   r_  r  rD   r  r   r   )
r  r`   r  r   r  r  r  r  r   r   )r  r`   r  r   r  r  r  r  r  zdict[tuple, RulesMap] | Noner   zlist[Widget])r&  r   r   r   )r  r   r&  r   r   r   )r&  r   r   r   )r  r   r  r   r  r   r   r   )r8  r   r   r   )rS  r|   r<  r  r   r   )r  r   r  r   r   ztuple[Widget, Region])r   z!list[tuple[DOMNode, BindingsMap]])r  r   r   r   )r  r   r  r   r   r   )r  rU   r   rU   )r  rU   r   r   )r  zset[Binding]r  r`   r   r   )r  events.Eventr   r   )r  str | ActionParseResultr(  r`   r)  Mapping[str, DOMNode] | Noner   z'tuple[DOMNode, str, tuple[object, ...]])r  r   r(  r`   r   zbool | None)r  r  r(  DOMNode | Noner)  r  r   r   )r  r`   r+  r   r,  r   r   r   )r@  r   r  r  r(  r`   r   r   )rZ  zmessages.Updater   r   )rZ  zmessages.Layoutr   r   )r  z
events.Keyr   r   )r  zevents.Resizer   r   )r  zevents.AppFocusr   r   )r  zevents.AppBlurr   r   )r]  r   r  r  r   rQ   )r6  r   r   r   )ro  r   r   r   )rS  r   r   r   )r  r   r   r   )r~  r   r  r   r   r   )r   r  )rZ  r   r   r   r  r   r   r   )rZ  z+messages.TerminalSupportsSynchronizedOutputr   r   )rZ  r   r   r   r  rx   r  r  rK  r   r   r   )r  rw   r   r   )r  ru   r  r   r   r   )r   zIterator[None])r_  r   r  r   r   r   )r  zstr | Path | TextIOr  str | Path | Noner  r  r  Literal['browser', 'download']rQ  r  r  r  r"  r  r   r  )r  zstr | Path | BinaryIOr  r  r  r  r  r  r  r  r"  r  r   r  )r  zBinaryIO | TextIOr  r  r  r  r  r  rQ  r  r  r  r"  r  r   r  )r  zevents.DeliveryCompleter   r   )rZ  zmessages.InBandWindowResizer   r   (  r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r	  r  r   r  r  r  r  r  rR   r  r  r  r  r  r!  r"  r#  r$  r<  ry   r   r>  r'  r2   DEFAULT_THEMEr?  r>   ri  r=   rj  r3  r   r  propertyr  r@   r  r  r  r  r  r  r  r  r  r  r  r  r  r	   r  r  r  r   r*  r,  r7   r8  r:  r=  r?  r  rC  r1  rF  rH  r
  rK  rU  r[  rT  r_  rp  rt  rZ   rw  r  r  rh  r  r}  r-  r  r  r  r  r  r  r  ry  r  r  rS  r  rN  r  r  r4   r  r  r  r  rf  r  r  r  re  r&  r  r  r2  rD  r   r   rR  rP  r   rk  r  r  r  r  r   r   r  r   r    r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r$  r  r  r  r  r  r#  r%  r-  r5  r  rE  r  rH  rU  r[  r`  rb  r  r}  r  r  r  r  r  r  r  r  r  r  rh  r  r  r  r  r  r  r  r  r  r  r  classmethodr  r  r	  r  r  r  r.  r2  r  r4  rD  rH  rL  rO  rQ  rT  rW  r  rd  rf  rg  rk  rp  rr  rt  rv  rx  rz  r  r  r  r  r  r  ri  rj  r  r  r  r  r  r  r  r  r  r  r  r  r6   rb   SignalResumer  r  r  r  r  r  r  r3   DeliveryCompleter  DeliveryFailedr  r5   InBandWindowResizer  r  __classcell__)r  s   @r   r   r   '  sf   2CI 6Kp >@E:?8 #-L-,#>@G;@F'*J$* $(L.'
 "J
!-1H*1&E: !Iz  .2N1f,-/-O 	%NHJ 
 .6]5 L4818`-5]5o255. 	D	
 	+E$?
-H) 
 $"%M<%JM5C&**/)--
 %&NM%4,.M.LEGBG$ DF@E +-27+*+HOD  $B6E=68'E:I}:\u-I $I$;$;<E=<1wU3Od	6e%J" -1'+ o)o %o 	o
 ob	F H H  :$	0# U U   " " ! !   *  !*  >& . .0 "!%"'5+/ &&
&
 "&

 &
 &
 &
 &
 %&
 )&
 &
 
&
P
G     ; ; K K I I F F > > 	7 	7 " " 
 
( %))-	3!3 3 '	3
 
3(   + +=
~%&"( 44 + +  A$-- 
 

#J	8   D D  " " # #  U  5*5*  5* !2	5*
 5* 
5*n
"9$2W2 2 	2
 
2h
 ?C	0"	01;	0		0 !	 =  = 	 =
 
 =H  $"&	   	
 
>  $"&	"
"
 "
  	"

 
"
N 4
+
 
 
	
*

" "&

 

 
 
  
 

4$<'8.G6 JN;#;-1;BF;	;"(  '/#9=U* U* %	U*
 U* U* 7U* 
1U* U*t  %'+37V  V  	V 
 V  V  %V  1V  
V v  %'+37)-62 62 	62
 62 62 %62 162 '62 
62p,3\- V4J	9 
9			(8		 
	
 ?C

$;
	
. 	: 
:			(8		 
	
 ?C

$;
	
6:	@ -1+/	GG *G )	G
 
GB -1+/@!@ *	@
 )@ 
@<,\&P(,?@> ? ?4 4CG)@	  JN 0G	 
 IM"""2E"	"H*2)<* 	 KO/4		2	 H	 -		
 	 
	 
 KO.2		32	3 H	3 ,		3
 .	3 
	3 GK!&	;.; D; 	;
 
7;z 		#2	#	# 
	# 
A 
AU4U	U" :D=4 D70)66'#'3@'	'<-6J"'. ,''(!!&*!37!?U!	!F	Y /3 %049=X.+X. X. 	X.
 X. X. .X. 7X. 
X.t,
&#,','&,,'6@,'IS,'	,'d " .299 9 	9
 9 ,9 
9v
'-
'	(*$6:-   	
  
6B0E%NI
/& " "*10 
 
    ,4;	(W*r 
 
( 48	%
'%
 #%
 1	%

 
1%
NCC.5C	C( -137	' * 1	
 
6' '/2'<?'	'R**&2*GN*	*X,#
'' ?C . .`(@%#!:==
!%0+ >K==#&=7:=	=(B(	(+)B$ "/ $;0;0 	;0
  ;0 ;0 ;0 
;0z&
	*&
E
. - - 0 0d1( 59 0 0 -1$(6@# $H
)H
 *	H

 "H
 4H
 H
 H
 H
 
H
\ -1$(6@ $N
+N
 *	N

 "N
 4N
 N
 N
 
N
n  $ $(!( *	(
 "( 4( ( ( ( 
(T  	 !	   ##$  % 
+ +r   r   )r   ztype[SystemCommandsProvider](  r   
__future__r   r  r  r  r  r  rc  r  r  r  r  warningsr   r   r   concurrent.futuresr   
contextlibr   r	   r
   r   	functoolsr   pathlibr   r  r   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    weakrefr!   r"   rO  	rich.reprplatformdirsr#   r  r$   r%   r&   r'   rich.controlr(   rich.protocolr*   rich.segmentr+   r,   rich.terminal_themer-   textualr.   r/   r0   r1   r2   r3   r4   r5   r6   textual._animatorr7   r8   r9   r:   textual._ansi_sequencesr;   r<   textual._ansi_themer=   r>   textual._callbackr?   textual._compatr@   textual._compositorrA   textual._contextrB   rC   rD   r`  textual._dispatch_keyrE   textual._event_brokerrF   rG   textual._filesrH   textual._pathrI   rJ   rK   textual._typesrL   textual._waitrM   textual.actionsrN   rO   textual.await_completerP   textual.await_removerQ   textual.bindingrR   rS   rT   rU   textual.commandrV   rW   rX   rY   textual.composerZ   textual.contentr[   textual.css.errorsr\   textual.css.queryr]   textual.css.stylesheetr^   r_   textual.domr`   ra   textual.driverrb   textual.errorsrc   textual.featuresrd   re   textual.file_monitorrf   textual.filterrg   rh   ri   rj   textual.geometryrk   rl   rm   textual.keysrn   ro   rp   rq   rr   textual.messagesrs   rt   textual.notificationsru   rv   rw   rx   textual.reactivery   textual.renderables.blankrz   textual.screenr{   r|   r}   r~   r   textual.signalr   textual.themer   r   r   textual.timerr   textual.visualr   r   textual.widgetr   r   textual.widgets._toastr   textual.workerr   r   textual.worker_managerr   r  r   typing_extensionsr   r   r   r   r   r   r   textual.messager   rd  r   r   r   r   platformr  rA  simplefilterResourceWarningversion_infor  r  r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   rw  autor   r   r   r   <module>r<     s   #    	  	  
    8 8 %        ( /   , S S   ' * -
 
 
 S R 8 2 $ + 0 < E . D 5 
 * ' 9 0 , E E U U # # . ' 7 ) ! # 8 , J J 1 1  1 T T % +  " > >  1 - , = 01EE, ,)'#>)
,,'
! ??H(O4 ),(8(8J(F % Di D  ; y  FO O b\0
 P
<J 
<"9y 99) 9<) <I{ I6	 68y 8By BFi F) /	 / \"
56 
 
   F LG+'*
w LG+ LG+r   