
    Cj{7                      % S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJr  SSKrSSKJr  SSKJr  SS	KJrJrJrJ r   SS
K!J"r"  SSK#J$r$  SSK%J&r&  SSK'J(r(J)r)  SSK*J+r+J,r,  SSK-J.r.J/r/J0r0  SSK1J2r2  SSK3J4r4  SSK5J6r6  SSK7J8r8J9r9J:r:  SSK;J<r<  SSK=J>r>  SSK?J@r@JArA  SSKBJCrC  SSKDJErE  SSKFJGrG  SSKHJIrIJJrJJKrKJLrL  SSKMJNrN  SSKOJPrP  SSKQJRrRJSrS  SSKTJUrU  SSKVJWrW  SS KXJYrYJZrZJ[r[J\r\J]r]  SS!K^J_r_  SS"K`Jara  SS#KbJcrc  SS$KdJere  SS%KfJgrg  SS&KhJiri  \	(       a  SS'KjJkrk  SS(KlJmrm  SS)KnJoro  S*\R                  -  rqS+\rS,'   \" S-5      rs \\\\s   /S4   \\\s   /\S   4   4   rt  " S. S/\5      ru\R                  R                   " S0 S1\\s   5      5       rx\R                  R                   " S2 S3\\s   \e5      5       ry\R                  R                   " S4 S5\y\s   5      5       rz " S6 S7\z\s   S8S99r{g):z

This module contains the `Screen` class and related objects.

The `Screen` class is a special widget which represents the content in the terminal. See [Screens](/guide/screens/) for details.

    )annotationsN)partial)
attrgetter)TYPE_CHECKINGAny	AwaitableCallableClassVarGenericIterableIteratorLiteral
NamedTupleOptionalTypeVarUnion)RenderableType)Style)	constantserrorseventsmessages)arrange)get_auto_scroll_regions)invoke)
CompositorMapGeometry)active_message_pumpvisible_screen_stack)CSSPathType_css_path_type_as_list_make_path_object_relative)CallbackType)
SkipAction)AwaitComplete)ActiveBindingBindingBindingsMapmatch)parse_selectors)	NoMatches	QueryType)PointerShape)DOMNode)NoWidget)OffsetRegionShapeSize)key_to_character)DockArrangeResult)Reactivevar)BackgroundScreen)Blank)
SELECT_ALL	SelectEnd	SelectionSelectStartSelectState)Signal)Timer)walk_selectable_widgets)Widget)Tooltip)	ToastRack)Final)Provider)MessagePump   zFinal[float]UPDATE_PERIODScreenResultTypec                  F    \ rS rSr% SrS\S'    S\S'    \S
S j5       rSrg	)HoverWidgetsZ   zJResult of [get_hover_widget_at][textual.screen.Screen.get_hover_widget_at]tuple[Widget, Region]
mouse_overztuple[Widget, Region] | None
hover_overc                ^    U R                   S   U R                  c  S4$ U R                  S   4$ )zJust the widgets.r   N)rP   rQ   selfs    `/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/screen.pywidgetsHoverWidgets.widgetsb   s<     OOAOO+D
 	
151C
 	
     N)returnztuple[Widget, Widget | None])	__name__
__module____qualname____firstlineno____doc____annotations__propertyrV   __static_attributes__rY   rX   rU   rM   rM   Z   s)    T%%5,,Y
 
rX   rM   c                  @    \ rS rSrSr S       SS jjrS	S jrSrg)
ResultCallbackk   z Holds the details of a callback.Nc                ,    Xl          X l         X0l        g)zInitialise the result callback object.

Args:
    requester: The object making a request for the callback.
    callback: The callback function.
    future: A Future to hold the result.
N)	requestercallbackfuturerT   rg   rh   ri   s       rU   __init__ResultCallback.__init__o   s     #@9A$%rX   c                    U R                   b  U R                   R                  U5        U R                  b3  U R                  b&  U R                  R	                  U R                  U5        SU l        g)zCall the callback, passing the given result.

Args:
    result: The result to pass to the callback.

Note:
    If the requested or the callback are `None` this will be a no-op.
N)ri   
set_resultrg   rh   	call_nextrT   results     rU   __call__ResultCallback.__call__   sR     ;;"KK""6*>>%$--*CNN$$T]]F;rX   )rh   ri   rg   N)rg   rH   rh   1ScreenResultCallbackType[ScreenResultType] | Noneri   z'asyncio.Future[ScreenResultType] | NonerZ   None)rq   rK   rZ   rv   )r[   r\   r]   r^   r_   rk   rr   rb   rY   rX   rU   rd   rd   k   s;    * ;?	&& D& 8	&
 
&(rX   rd   c            	      4  ^  \ rS rSr% SrSrS\S'    SrS\S'    SrS	\S
'    S1r	Sr
SrS\S'    SrS\S'    SrS\S'    SrS\S'    \" S5      rS\S'    \" SSS9rS\S'    \" SSS9rS\S'    \" SSS9rS\S'    \" 5       rS\S'    SrS\S'    SrS \S!'    \" SS"S#9rS\S$'    \" \5      rS%\S&'    \" S5      r \" S5      rS'\S('    \" S5      rS)\S*'    \" S+5      rS,\S-'    \ " S.S/S0SS19\ " S2S3S4SS19\ " S5S6S7SS19/r!   S       SU 4S8 jjjr"\#SS9 j5       r$\#SS: j5       r%\#SS; j5       r&\#SU 4S< jj5       r'\#SS= j5       r(S> r)S? r*    SS@ jr+SSA jr,      SSB jr-\#SSC j5       r.\#SSD j5       r/\#SSE j5       r0SSSF jjr1\#SSG j5       r2\#SSH j5       r3SSI jr4SSJ jr5SSK jr6SSL jr7SSM jr8SSN jr9SSO jr:SSP jr;SSQ jr<SSR jr=      SSS jr>SST jr?SSU jr@SSV jrA\#SSW j5       rB S     SSX jjrCSSSY jjrDSSSZ jjrESSS[ jjrFSS\ jrGSS] jrHSS^ jrISS_ jrJSS` jrKSSa jrLSSb jrM S     SSc jjrN S     SSd jjrO  S       SSe jjrPSSf jrQSSg jrRSSh jrSSSi jrTSSj jrUSSk jrVSSl jrW S       SSm jjrXSU 4Sn jjrYSSo jrZSSSp jjr[SSq jr\SSr jr]SSs jr^SSt jr_SSu jr`SSv jraSU 4Sw jjrbSSx jrcSSy jrdSSz jre      SS{ jrfSS| jrgSS} jrhSS~ jriSS jrjSS jrk\l        SS j5       rm S       SS jjrnSS jro        SS jrpSS jrqSS jrrSS jrsSS jrt\u          SS j5       rvSS jrwSSS jjrxSS jrySSS jjrzSU 4S jjr{SU 4S jjr|SS jr}SS jr~SrU =r$ )Screen   zThe base class for screens.NzClassVar[str | None]
AUTO_FOCUS zClassVar[str]CSSzClassVar[CSSPathType | None]CSS_PATHzscreen--selectionaa  
    Screen {
        layout: vertical;
        overflow-y: auto;
        background: $background;        
        
        &:inline {
            height: auto;
            min-height: 1;
            border-top: tall $background;
            border-bottom: tall $background;
        }
        & > .screen--selection {
            background: $screen-selection-background;
            color: $screen-selection-foreground;           
        }
        &:ansi {
            background: ansi_default;
            color: ansi_default;
            &.-screen-suspended {
                text-style: dim;
                ScrollBar {
                    text-style: not dim;
                }
            }
            &:inline {
                border-top: tall $ansi-background;
                border-bottom: tall $ansi-background;
            }
        }
    }
    
    TITLE	SUB_TITLEz&ClassVar[list[tuple[int, str]]] | NoneHORIZONTAL_BREAKPOINTSVERTICAL_BREAKPOINTSzReactive[Widget | None]focusedr   F)repaintzReactive[int]stack_updates)computezReactive[str | None]	sub_titletitlez<ClassVar[set[type[Provider] | Callable[[], type[Provider]]]]COMMANDSALLOW_IN_MAXIMIZED_VIEWzClassVar[bool | None]ESCAPE_TO_MINIMIZETlayout	maximizedzvar[dict[Widget, Selection]]
selectionszReactive[SelectState | None]_select_statezvar[Offset | None]_mouse_down_offsetdefaultzvar[PointerShape]_pointer_shapetabzapp.focus_nextz
Focus Next)showz	shift+tabzapp.focus_previouszFocus Previouszctrl+c,super+czscreen.copy_textzCopy selected textc                   > SU l         [        TU ]	  XUS9  [        5       U l        [        5       U l        SU l        / U l        / U l	        SU l
        SU l        U R                  b  [        U R                  5      O/  Vs/ s H  n[        X@5      PM     nnXPl        U R                   U l        U R$                  U l        [)        U S5      U l         [)        U S5      U l         [)        U S5      U l         SU l         0 U l         SU l        gs  snf )z
Initialize the screen.

Args:
    name: The name of the screen.
    id: The ID of the screen in the DOM.
    classes: The CSS classes for the screen.
FnameidclassesNzlayout-refreshbindings_updatedselection_started)_modalsuperrk   r   _compositorset_dirty_widgets_Screen__update_timer
_callbacks_result_callbacks_tooltip_widget_tooltip_timerr}   r!   r"   css_pathr~   r   r   r   r@   screen_layout_refresh_signalbindings_updated_signaltext_selection_started_signal_css_update_count_layout_widgets_auto_select_scroll_timer)rT   r   r   r   r   	css_paths	__class__s         rU   rk   Screen.__init__  s-    d7;%<+.5,0BDPR.2,0 ==, 't}}5
  'x6 	 
 "ZZ
<B"=
) 	R7=dDV7W$D=C%>
* 	B!##;=47;&1C
s   >Dc                    U R                   $ )zIs the screen modal?r   rS   s    rU   is_modalScreen.is_modalO  s     {{rX   c                    SSK Jn   U R                  R                  U L =(       d    X R                  R                  ;   $ ! U a     gf = f)z-Is the screen current (i.e. visible to user)?r   )ScreenStackErrorF)textual.appr   appscreen_background_screens)rT   r   s     rU   
is_currentScreen.is_currentT  sC     	1	88??d*Rdhh6R6R.RR 		s   6? AAc                ~    U R                   c%  U R                  [        U R                  SSS9U l         U R                   $ )zTimer used to perform updates.screen_updateT)r   pause)r   set_intervalrJ   _on_timer_updaterS   s    rU   _update_timerScreen._update_timer^  sF     &"&"3"3t44?RV #4 #D """rX   c                   > S/nU R                   R                  (       d  UR                  S5        U R                   R                  (       d  UR                  S5        / [        TU ]  QUQ7$ )z8Layers from parent.

Returns:
    Tuple of layer names.
_loading
_toastrack	_tooltips)r   _disable_notificationsappend_disable_tooltipsr   layers)rT   extrasr   s     rU   r   Screen.layersg  sR     xx..MM,'xx))MM+&))&))rX   c                p    U R                   R                  U R                  R                  R                  -
  $ )zThe size of the screen.)r   sizestylesguttertotalsrS   s    rU   r   Screen.sizeu  s'     xx}}t{{118888rX   c                $    U R                  5         g rt   refresh_bindingsrS   s    rU   _watch_focusedScreen._watch_focusedz      rX   c                $    U R                  5         g rt   r   rS   s    rU   _watch_stack_updatesScreen._watch_stack_updates}  r   rX   c                   #    UR                  5       UR                  5       -   H$  nUR                  UR                  US 5      5        M&     g 7frt   )keysselection_updatedget)rT   old_selectionsr   widgets       rU   _watch_selectionsScreen._watch_selections  s@     
 %))+joo.??F$$Z^^FD%AB @s   AAc                :    U R                   R                  U 5        g)z&Call to request a refresh of bindings.N)r   publishrS   s    rU   r   Screen.refresh_bindings  s    $$,,T2rX   c                ~    U R                  US LS5        Ub  UR                  S5        Ub  UR                  S5        g g )Nz-maximized-viewz
-maximized)	set_classremove_class	add_class)rT   previously_maximizedr   s      rU   _watch_maximizedScreen._watch_maximized  sE    
 	y,.?@+ --l; - !rX   c           	     .   U R                   nUb  UR                  (       a  SnUcL  X R                  R                  5       4U R                  U R                  R                  R                  5       4/nO5UR
                   Vs/ s H  o3UR                  R                  5       4PM      nn/ nU Hm  u  pVU HQ  nUR                  n[        UR                  5       H)  n	U" U	[        U	5      5      (       d  M  UR                  U		 M+     MS     UR                  U5        Mo     U R                  R                  n
U HX  u  pVU
(       d  M  UR                  U
5      nUR                  (       d  M2  U R                  R                  UR                  U5        MZ     U$ s  snf )zBinding chain from this screen.N)r   loading	_bindingscopyr   ancestors_with_selfcheck_consume_keylistkey_to_bindingsr5   r   _keymapapply_keymapclashed_bindingshandle_bindings_clash)rT   r   namespace_bindingsnodefilter_namespaces	namespacebindings_mapfilter_namespacer   keykeymaprq   s               rU   _binding_chainScreen._binding_chain  so    ,,7??G ?~~**,-488--2245" ;B:U:U":U$t~~**,-:U  "
 ,.'9#I$5 $4$F$F! < <=C(.>s.CDD )88=	 > %6 $$Y/ (: !!'9#Iv%226:***HH2263J3JIV	 (: "!1"s    %Fc                ~    U R                   n[        US5       H   u  nu  p4UR                  (       d  M  USU s  $    U$ )z=The binding chain, ignoring everything before the last modal.rI   N)r  	enumerater   )rT   binding_chainindexr   r   s        rU   _modal_binding_chainScreen._modal_binding_chain  sG     ++(1-(C$E$D}}}$Ve,, )D rX   c                   0 nU R                   nU R                   H  u  p4U H  u  pVUR                  UR                  U5      nUSL a  M(  [	        U5      nUR                  U5      =n	(       aJ  UR                  (       a7  U	R                  R                  (       d  [        X6XR                  5      X'   M  M  M  [        X6XR                  5      X'   M     M     U$ )aY  Get currently active bindings for this screen.

If no widget is focused, then app-level bindings are returned.
If a widget is focused, then any bindings present in the screen and app are merged and returned.

This property may be used to inspect current bindings.

Returns:
    A map of keys to a tuple containing (NAMESPACE, BINDING, ENABLED).
F)
r   r	  _check_action_stateactionboolr   prioritybindingr&   tooltip)
rT   r   r   r   bindingsr  r  action_stateenabledexisting_key_and_bindings
             rU   active_bindingsScreen.active_bindings  s     24hh#'#<#<I ("66w~~yQ5( |,/;/?/?/DD+D  (( 8 @ @ I I,9%-) !J ) )6!G__)L%- !) $=6 rX   c                  ^ ^ UT R                   R                  T R                  4nT R                  R	                  U5      nUb  U$ T R
                  c  T R                  R
                  OT R
                  mSUU 4S jjn[        T T R                  b  U" T R                  5      OT R                   UT R                  S5      =nT R                  U'   U$ )zvArrange children.

Args:
    size: Size of container.
    optimal: Ignored on screen.

Returns:
    Widget locations.
c                   > U 1TR                  T5      kTR                  S5      knTR                   Vs/ s H  o"U;   d  M
  UPM     nnX;  a  UR                  SU 5        U$ s  snf )zLGet widgets to display in maximized view.

Returns:
    A list of widgets.

z.-textual-systemr   )query_childrenchildreninsert)r   rV   r   maximize_widgetsallow_in_maximized_viewrT   s       rU   get_maximize_widgets,Screen.arrange.<locals>.get_maximize_widgets
  s|     $$%<= $$%78G 6:]]X]6PWFW]X0 ''95##	  Ys   	A#A#F)r   rC   rZ   list[Widget])	_nodes_updatesr   _arrangement_cacher   r   r   r   r   )rT   r   _optimal	cache_keycached_resultr  arrangementr  s   `      @rU   r   Screen.arrange  s     4;;//@	//33I>$   ++3 HH,,-- 	 	$ 	$( <C >>- %T^^4[[II
<
 
	
d--i8 rX   c                T     U R                   R                  U L $ ! [         a     gf = f)z9Is the screen active (i.e. visible and top of the stack)?F)r   r   	ExceptionrS   s    rU   	is_activeScreen.is_active,  s,    	88??d** 		s    
''c                    U R                   $ )z,Check if this widget permits text selection.)ALLOW_SELECTrS   s    rU   allow_selectScreen.allow_select4  s        rX   c                :    U R                   R                  5       nU$ )zGet a widget to display a loading indicator.

The default implementation will defer to App.get_loading_widget.

Returns:
    A widget in place of this widget to indicate a loading.
)r   get_loading_widget)rT   loading_widgets     rU   r3  Screen.get_loading_widget9  s     446rX   c                :    U R                   R                  U5        g rt   )r   _set_pointer_shape)rT   pointer_shapes     rU   _watch__pointer_shapeScreen._watch__pointer_shapeD  s    ##M2rX   c                ^   U R                   (       a  SU l        gU R                  R                  c  U OU R                  R                  nSnUR                   HM  n[        U[        5      (       d  M  UR                  (       a  Sn  O"UR                  R                  =nS:w  d  MM    O   X l        g)z'Get the screen's current pointer shape.textNr   wait)

_selectingr   r   rP   r   
isinstancerC   r   r   pointer)rT   r   r8  r   s       rU   update_pointer_shapeScreen.update_pointer_shapeG  s    ??"(D,,4$((:M:M!..D$''<<$*M%)[[%8%88MYF / ,rX   c                J   U R                   R                  n [        R                  " 5       R	                  5       nUb  X La  UR                  S:  a  [        X!5      $ UR                  (       a  U R                  R                  5       $ [        U5      $ ! [
         a    Sn Nff = f)zrRender method inherited from widget, used to render the screen's background.

Returns:
    Background renderable.
NrI   )r   
backgroundr   r   popLookupErrorar9   is_transparentr   renderr:   )rT   rD  base_screens      rU   rI  Screen.renderX  s     [[++
	.22488:K "{'>:<<RSCS#K<<$$88??$$Z    	K	s   #B B"!B"c                8    U R                   R                  U5      $ )zGet the absolute offset of a given Widget.

Args:
    widget: A widget

Returns:
    The widget's offset relative to the top left of the terminal.
)r   
get_offsetrT   r   s     rU   rM  Screen.get_offsetn  s     **622rX   c                8    U R                   R                  X5      $ )zGet the widget at a given coordinate.

Args:
    x: X Coordinate.
    y: Y Coordinate.

Returns:
    Widget and screen region.

Raises:
    NoWidget: If there is no widget under the screen coordinate.
)r   get_widget_atrT   xys      rU   rQ  Screen.get_widget_aty  s     --a33rX   c                l   [        U R                  R                  X5      5      n [        U5      u  pEUR                  (       d9  U H&  u  pgUR                  (       d  M  [        XE4Xg45      s  $    [        XE4S5      $ [        XE4XE45      $ ! [         a    [
        R                  " SU SU S35      ef = f)aP  Get the widget, and its region directly under the mouse, and the first
widget, region pair with a hover style.

Args:
    x: X Coordinate.
    y: Y Coordinate.

Returns:
    A pair of (WIDGET, REGION) tuples for the top most and first hover style respectively.

Raises:
    NoWidget: If there is no widget under the screen coordinate.

z)No hover widget under screen coordinate (z, )N)	iterr   get_widgets_atnextStopIterationr   r0   _has_hover_stylerM   )rT   rS  rT  widgets_under_coordinate
top_widget
top_regionr   regions           rU   get_hover_widgets_atScreen.get_hover_widgets_at  s     $((8(8(G(G(M#N 	Y%)*B%C"J **":***'(@6BRSS #;   8$??Z4z6NOO  	Y//$MaSPRSTRUUV"WXX	Ys   B (B3c                8    U R                   R                  X5      $ )zGet all widgets under a given coordinate.

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

Returns:
    Sequence of (WIDGET, REGION) tuples.
)r   rY  rR  s      rU   rY  Screen.get_widgets_at  s     ..q44rX   c                    U R                  X5      u  p4UR                  S5      (       d  UR                  (       a  gUR                   H/  n[        U[        5      (       d  M  UR                  (       d  M-  Us  $    g! [         a     gf = f)a  Get the focusable widget under a given coordinate.

If the widget directly under the given coordinate is not focusable, then this method will check
if any of the ancestors are focusable. If no ancestors are focusable, then `None` will be returned.

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

Returns:
    A `Widget`, or `None` if there is no focusable widget underneath the coordinate.
N-textual-system)rQ  r0   	has_classr   r   r?  rC   	focusable)rT   rS  rT  r   _regionr   s         rU   get_focusable_widget_atScreen.get_focusable_widget_at  sy    	"006OF -..&....D$''DNNN /   		s   A= =
B
	B
c                8    U R                   R                  X5      $ )zzGet the style under a given coordinate.

Args:
    x: X Coordinate.
    y: Y Coordinate.

Returns:
    Rich Style object.
)r   get_style_atrR  s      rU   rm  Screen.get_style_at  s     ,,Q22rX   c                8    U R                   R                  X5      $ )zGet the widget under a given coordinate, and an offset within the original content.

Args:
    x: X Coordinate.
    y: Y Coordinate.

Returns:
    Tuple of Widget and Offset, both of which may be None.
)r   get_widget_and_offset_atrR  s      rU   rp  Screen.get_widget_and_offset_at  s     88>>rX   c                8    U R                   R                  U5      $ )zGet the screen region of a Widget.

Args:
    widget: A Widget within the composition.

Returns:
    Region relative to screen.

Raises:
    NoWidget: If the widget could not be found in this screen.
)r   find_widgetrN  s     rU   rs  Screen.find_widget  s     ++F33rX   c                     0 U l         SU l        g)zClear any selected text.N)r   r   rS   s    rU   clear_selectionScreen.clear_selection  s    !rX   c                n    [         nX0UR                  S5       Vs0 s H  o3U_M     snEU l        gs  snf )zKSelect a widget and all its children.

Args:
    widget: Widget to select.
*N)r;   queryr   )rT   r   
select_allchilds       rU   _select_all_in_widgetScreen._select_all_in_widget  s=      

.4ll3.?@.?Uj .?@
@s   2c                    / nUR                   n[        S5      nU R                  nU R                  =nb(  UR                   H  nUR
                  (       d  M  Un  O   [        [        UR                  US95      U R                  4/nUR                  nUR                   n	U(       a  US   u  p[        U
S5      nUc  U" 5         OUR                  5       (       a  M<  UR                  R                  S5      nU(       a  US:g  OUnUR                  (       a<  UR!                  5       (       a'  [        UR                  US9nU	" [        U5      U45        U(       a  UR#                  5       (       a  U" U5        U(       a  M  U$ )z9A list of widgets that may receive focus, in focus order._focus_sort_keyN)r  r   
visibilityhidden)r   r   r   r   r   _trap_focusrX  sorteddisplayed_childrenvisiblerE  rZ  _check_disabledr   get_ruleis_containerallow_focus_childrenallow_focus)rT   rV   
add_widgetfocus_sorter	root_noder   r   
node_stackrE  pushchildren_iteratorparent_visibilitynode_styles_visibilitynode_is_visiblesorted_displayed_childrens                  rU   focus_chainScreen.focus_chain  sm    !#^^
!"34 KK	||#G033### $I 4 VI88lKL;

 nn  3=b>0)40D|'')))-)=)=l)K& . +h6*  
 $$)B)B)D)D06//\1- $89?KL #t'7'7'9'9t$- j0 rX   c                  ^ [        U[        5      (       d  UR                  n[        U5      mU R                  nU R
                  b;  [        U R
                  R                  SS95      nU Vs/ s H  oUU;   d  M
  UPM     nnU4S jU 5       nU(       d  U R                  $ U R                  c)  [        US5      nU R                  U5        U R                  $ U(       d  [        TU R                  5      (       d  Sn UR                  U R                  5      nU(       a_  Sn[        U5      n	[        S[        U5      S-   5       H%  n
UXU
-  -   U	-     n[        TU5      (       d  M#  Un  O   U R                  U5        U R                  $ s  snf ! [         a)    U R                  [        US5      5         U R                  $ f = f)a;  Move the focus in the given direction.

If no widget is currently focused, this will focus the first focusable widget.
If no focusable widget matches the given CSS selector, focus is set to `None`.

Args:
    direction: 1 to move forward, -1 to move backward, or
        0 to keep the current focus.
    selector: CSS selector to filter
        what nodes can be focused.

Returns:
    Newly focused widget, or None for no focus. If the return
        is not `None`, then it is guaranteed that the widget returned matches
        the CSS selectors given in the argument.
NT	with_selfc              3  N   >#    U  H  n[        TU5      (       d  M  Uv   M     g 7frt   r)   ).0r   selector_sets     rU   	<genexpr>%Screen._move_focus.<locals>.<genexpr>Z  s       
(TE,,EDD[s   %	%rI   )r?  strr[   r+   r  r   r   walk_childrenr   rZ  	set_focusr*   r  lenrange
ValueError)rT   	directionselectorr  rh  r   filtered_focus_chainto_focuscurrent_indexchain_lengthstepr   r  s               @rU   _move_focusScreen._move_focus<  s   ( (C((((H&x0&& >>%DNN8848HII0;Sf?R6KS 
( 
 <<<<0$7HNN8$<< |T\\!B!BI	)'--dll;M ";/!!S%5%9:D&&T)99\ID \400#' ; x(||O T,  	=NN4 4d;< ||#	=s   -	F	:F	<F %G Gc                &    U R                  SU5      $ )a  Focus the next widget, optionally filtered by a CSS selector.

If no widget is currently focused, this will focus the first focusable widget.
If no focusable widget matches the given CSS selector, focus is set to `None`.

Args:
    selector: CSS selector to filter
        what nodes can be focused.

Returns:
    Newly focused widget, or None for no focus. If the return
        is not `None`, then it is guaranteed that the widget returned matches
        the CSS selectors given in the argument.
rI   r  rT   r  s     rU   
focus_nextScreen.focus_next  s     8,,rX   c                &    U R                  SU5      $ )a  Focus the previous widget, optionally filtered by a CSS selector.

If no widget is currently focused, this will focus the first focusable widget.
If no focusable widget matches the given CSS selector, focus is set to `None`.

Args:
    selector: CSS selector to filter
        what nodes can be focused.

Returns:
    Newly focused widget, or None for no focus. If the return
        is not `None`, then it is guaranteed that the widget returned matches
        the CSS selectors given in the argument.
r   r  r  s     rU   focus_previousScreen.focus_previous  s     H--rX   c                    UR                   (       aQ  U(       aC  UR                   H3  n[        U[        5      (       d    OUR                   (       d  M-  X0l          g   Xl        gg)zMaximize a widget, so it fills the screen.

Args:
    widget: Widget to maximize.
    container: If one of the widgets ancestors is a maximizeable widget, maximize that instead.

Returns:
    `True` if the widget was maximized, otherwise `False`.
TF)allow_maximize	ancestorsr?  rC   r   )rT   r   	containermaximize_widgets       rU   maximizeScreen.maximize  sQ       '-'7'7O%ov>>&555)8# (8 $NrX   c                z    SU l         U R                  b'  U R                  U R                  U R                  SSS9  gg)z-Restore any maximized widget to normal state.NFT)animatecenter)r   r   call_after_refreshscroll_to_widgetrS   s    rU   minimizeScreen.minimize  s>    <<###%%t||U4 $  $rX   c                *   U R                   (       d  g/ nU R                   R                  5        H@  u  p#UR                  (       d  M  UR                  U5      =n c  M/  UR	                  U5        MB     SR                  U5      R                  S5      nU$ )zZGet text under selection.

Returns:
    Selected text, or `None` if no text was selected.
Nr{   
)r   itemsis_attachedget_selectionextendjoinrstrip)rT   widget_textr   	selectionselected_text_in_widgetselected_texts         rU   get_selected_textScreen.get_selected_text  s     !#!%!6!6!8F """060D0DY0OO, ""#:; "9 ,33D9rX   c                t    U R                  5       nUc
  [        5       eU R                  R                  U5        g)z Copy selected text to clipboard.N)r  r$   r   copy_to_clipboard)rT   r  s     rU   action_copy_textScreen.action_copy_text  s0    **,	,""9-rX   c                V    U R                   b  U R                  U R                   5        gg)z0Action to maximize the currently focused widget.N)r   r  rS   s    rU   action_maximizeScreen.action_maximize  s!    <<#MM$,,' $rX   c                $    U R                  5         g)z2Action to minimize the currently maximized widget.N)r  rS   s    rU   action_minimizeScreen.action_minimize  s    rX   c                &    U R                  S5        g)z Action to remove focus (if set).N)r  rS   s    rU   action_blurScreen.action_blur  s    trX   c                   #     U R                  U5      R                  5       n[        U[        5      (       a  U R	                  U5        gg! [
         a     gf = f7f)zwAn [action](/guide/actions) to focus the given widget.

Args:
    selector: Selector of widget to focus (first match).
N)rz  firstr?  rC   r  r,   )rT   r  r   s      rU   action_focusScreen.action_focus  sT     	%::h'--/D $''t$ (  		s'   AA (A
AAAAc                   U=(       d    / nU R                   ULa  gU R                  nU(       d  U R                  S5        g UR                  U5      nSn[        X4S-   S USU -   5       H  nXr;  d  M
  Un  O   U R                  U5        g! [         aR    UR
                   H.  nXR;  d  M
  UR                  (       d  M  U R                  U5          O   U R                  S5         gf = f)zReset the focus when a widget is removed

Args:
    widget: A widget that is removed.
    avoiding: Optional list of nodes to avoid.
NrI   )r   r  r  r  r  visible_siblingsrh  reversed)rT   r   avoidingfocusable_widgetswidget_indexsiblingchosen	candidates           rU   _reset_focusScreen._reset_focus  s     >r <<v% !,, NN4 	 -226:L !%!Q.014Em|4TT
I ("
 	v/  
	 "22*w/@/@/@NN7+ 3
 t$
	s   B C)-C) &C)(C)c                   [        5       nUbM  [        UR                  5       H4  nUR                  (       d  M  UR	                  UR                  SS95          O   UbM  [        UR                  5       H4  nUR                  (       d  M  UR	                  UR                  SS95          O   U(       a%  U R                  R                  R                  USS9  gg)zyUpdate CSS for focus changes.

Args:
    focused: The widget that was focused.
    blurred: The widget that was blurred.
NTr  r  )	r   r  r   _has_focus_withinupdater  r   
stylesheetupdate_nodes)rT   r   blurredrV   r   s        rU   _update_focus_stylesScreen._update_focus_styles1  s     !$"7#>#>?+++NN6#7#7$#7#GH @ "7#>#>?+++NN6#7#7$#7#GH @ HH,,Wd,C rX   c                   ^  UT R                   L a  gSnSnUcj  T R                   bA  T R                   R                  [        R                  " 5       5        T R                   nST l         T R                  R                  S5        OUR                  (       a  T R                   U:w  a  T R                   b:  T R                   R                  [        R                  " 5       5        T R                   nUT l         UR                  [        R                  " US95        UnU(       a  SU 4S jjnT R                  Xa5        T R                  R                  US5        T R                  XE5        T R                  T R                  5        g)ak  Focus (or un-focus) a widget. A focused widget will receive key events first.

Args:
    widget: Widget to focus, or None to un-focus.
    scroll_visible: Scroll widget into view.
    from_app_focus: True if this focus is due to the app itself having regained
        focus. False if the focus is being set because a widget within the app
        regained focus.
Nzfocus was removed)from_app_focusc                t   > TR                   U L a(  TR                  U 5      (       d  TR                  U SS9  ggg)z#Scroll to center (after a refresh).T)origin_visibleN)r   can_view_entirescroll_to_center)r   rT   s    rU   r  *Screen.set_focus.<locals>.scroll_to_centert  s;    <<61$:N:Nv:V:V 11&1N ;W1rX   zwas focusedr   rC   rZ   rv   )r   post_messager   Blurlogdebugrh  Focus
call_laterr  r  r   )rT   r   scroll_visibler  r   r  r  s   `      rU   r  Screen.set_focusI  s    T\\!!%!%>||'))&++-8,,#HHNN./||v%<<+LL--fkkm<"llG%##FLL$OP !O
 OO$4=v}5!!'3 5 56rX   c                    U R                   R                  (       d  UR                  S[        SS95        U R                   R                  (       d  UR                  S[        SS95        gg)zInsert Textual's own internal widgets.

Args:
    widgets: The list of widgets to be composed.

This method adds the tooltip, if required, and also adds the
container for `Toast`s.
r   ztextual-tooltip)r   ztextual-toastrackN)r   r   r  rD   r   rE   )rT   rV   s     rU   _extend_composeScreen._extend_compose  sK     xx))NN1g):;<xx..NN1i+>?@ /rX   c                L    U R                   R                  X R                  SS9  g)z1Set up the tooltip-clearing signal when we mount.T)	immediateN)r   	subscribe_maybe_clear_tooltiprT   events     rU   	_on_mountScreen._on_mount  s&    ))33++t 	4 	
rX   c                  #    UR                  5         U R                  R                  (       d  U R                  (       ap  U R                  (       dD  U R
                  (       d3  U R                  (       d"  U R                  (       d  U R                  (       a  U R                  R                  5         g U R                  5       I S h  vN   g  N7frt   )prevent_defaultr   _batch_countr   _layout_required_scroll_required_repaint_required_recompose_requiredr   r   resume_invoke_and_clear_callbacksr  s     rU   _on_idleScreen._on_idle  sx     xx$$%%(())++&&""))+..000s   C C
CC
c           	        U R                   nUR                  (       Gav  XR                  L a  UR                  5       nUR                  SL=(       a    X!R                  :  nUR                  U U R                  R                  UR                  R                  U5      UR                  US95        X!l        U R                  R                  5         U R                  R                  R                  5         GOX R                   R                  ;   a  U R                  R                  (       ak  UR                  R                  " U R                  R                  6   U R                  R                  R                  5         U R                  R                  5         GO&XR                  L aO  U R                  R                  UR                  S9nUR                  X5        U R                  R                  5         OX R                   R                  ;   a  U R                  R                  (       a  U R                   " U R                  R                  6   UR                  R                  " U R                  R                  6   SU l        U R                  R                  R                  5         U R                  R                  5         UR%                  U 5        g)zPerform a compositor refresh.N)screen_stackclear)r  T)r   	is_inliner   _get_inline_height_previous_inline_height_displayr   render_inliner   with_heightr   r   r   _dirty_regionsrefreshrender_update
_set_dirtyr  _update_mouse_over)rT   r   inline_heightr   r  s        rU   _compositor_refreshScreen._compositor_refresh  s    hh===zz! # 6 6 8//t; D%(C(CC  $$22,,];%(%<%<# 3  /<+##))+  //5574449I9I9X9X

""D$4$4$C$CD  //557##))+ zz!))77!$!8!8 8  T*##))+4449I9I9X9X!1!1!@!@A

""D$4$4$C$CD)-&  //557##))+t$rX   c                `   U R                   R                  5         U R                  (       GaU  U R                  R                  (       Gd9  U R
                  (       a;  U R                  U R                  S9  SU l        U R                  R                  5         O U R                  (       a  U R                  SS9  SU l        U R                  (       a<  U R                  R                  5         U R                  R                  U 5        SU l
        U R                  (       a5  U R                  R                  U R                  5        U R                  5         U R                  (       a"  SU l        U R!                  U R"                  5        U R$                  (       a  U R!                  U R&                  5        gg)zCalled by the _update_timer.)scrollFTN)r   r   r   r   r  r  _refresh_layoutr  r   r   r  addr   update_widgetsr-  r  ro   	recomposer   r  rS   s    rU   r   Screen._on_timer_update  s-     "???488#8#8#8$$$$D,A,A$B(-%##))+&&$$D$1$)D!%%##))+##''-).&""  //0C0CD((*''+0(t~~.??NN4;;< rX   c                  #    U R                   (       aa  U R                   SS nU R                   R                  5         U H1  u  p#UR                  5          [        U5      I Sh  vN   SSS5        M3     gg N! , (       d  f       MH  = f7f)zPIf there are scheduled callbacks to run, call them and clear
the callback queue.N)r   r   _contextr   )rT   	callbacksrh   message_pumps       rU   r  "Screen._invoke_and_clear_callbacks  sm      ??*IOO!!#*3&!**, *** -, +4 
 + -,s0   AB
A8#A6$A8(B
6A88
B	B
c                \    U R                   R                  X45        U R                  5         g)zEnqueue a callback to be invoked after the screen is repainted.

Args:
    callback: A callback.
    sender: The sender (active message pump) of the callback.
N)r   r   
check_idle)rT   rh   senders      rU   _invoke_laterScreen._invoke_later  s#     	12rX   c                l    U R                   R                  [        [        [              " XU5      5        g)zAdd a result callback to the screen.

Args:
    requester: The object requesting the callback.
    callback: The callback.
    future: A Future to hold the result.
N)r   r   rd   r   rK   rj   s       rU   _push_result_callbackScreen._push_result_callback  s-     	%%8$456yFS	
rX   c                  >#    [         TU ]  5       I S h  vN   U R                  R                  5         U R                  R                  5         U R
                  R                  5         U R                  R                  5         U R                  R                  U 5        U R                  R                  5         S U l        g  N7frt   )r   _message_loop_exitr   r   r   r'  r$  r   unsubscriber"  _clear_taskrT   r   s    rU   rD  Screen._message_loop_exit  s     g(*** !!#!!#%%'))55d;
 	+s   CB?B*Cc                8    U R                   R                  5         g)z1Remove the latest result callback from the stack.N)r   rE  rS   s    rU   _pop_result_callbackScreen._pop_result_callback   s    ""$rX   c                   Uc  U R                   OUnU R                  R                  (       a)  UR                  U R                  R	                  5       5      nU(       d  gU R
                  R                  U R                  5        U R                  R                  5         [        R                  n U(       a  U R                  (       d  U R
                  R                  X5      nU(       au  U R
                  R                  nU HY  u  nu  nnn	n
nnnXd;   d  M  UR                  UR                   XSS9(       d  M7  UR#                  U" UR                   X5      5        M[     GOU R
                  R%                  X5      u  pnU R                  R'                  5         [        R(                  n[        R*                  nU H  nUR#                  U" 5       5        M     X-  nU R
                  R                  nU HT  u  nu  nnn	n
nnnUR                  UR                   X5        UU;   d  M2  UR#                  U" UR                   X5      5        MV     U H  nUR#                  U" 5       5        M      U R0                  (       aG  U R                  R2                  (       a  U R5                  U R6                  5        OU R7                  5         U R                  R8                  (       a&  U R:                  R=                  U R>                  5        gU R                  R#                  [        R@                  " 5       5        SU R                  l        g! [,         a%  nU R                  R/                  U5         SnAgSnAff = f)z>Refresh the layout (can change size and positions of widgets).NFr   T)!
outer_sizer   r!  r&  r"  r   r3  r   r   r   r   Resizer   reflow_visibler   _size_updatedr   r   reflowr   HideShowr+  _handle_exceptionr   r  r  r-  
_dom_readyr   r   r   Ready)rT   r   r0  ResizeEventexposed_widgetsr   r   r`  _order_clipvirtual_sizecontainer_size_r  shownresizedrS  rT  send_resizeerrors                       rU   r1  Screen._refresh_layout$  s   "&,tD88##DHH$?$?$ABD''(;(;<  "mm9	d22"&"2"2"A"A$"M"!--44F   !$&!4%33 &\RW  4     !' 3 3$/(.\%&!"   *.)9)9)@)@)L&w$$**,{{{{$F''/ % $o))00 F  "((lS,++'\R  $F''/ $ ??xx$$ 8 89((*88--55dkkBHH!!&,,.1"&DHH  	HH&&u-	s3   .A#M M 7&M CM $AM 
M2M--M2c                  #    UR                  5         UR                  5         UR                  n[        U[        5      (       d   eX R
                  ;   a,  U R                  R                  U5        U R                  5         g g 7frt   )	stopr  r   r?  rC   r   r   r2  r<  )rT   messager   s      rU   
_on_updateScreen._on_updatev  se     !&&))))#####F+OO $s   B Bc                  #    UR                  5         UR                  5         SnUR                  nUR                  R                   H  n[	        U[
        5      (       d    OxX@R                  ;  a  [        5       U R                  U'   X0R                  ;  a   U R                  U   R                  U5        SnUR                  R                  (       d    OUnM     U(       a*  U R                  (       d  SU l        U R                  5         g g g 7f)NFT)re  r  r   r  r?  rC   r   r   r2  r   auto_dimensionsr  r<  )rT   rf  layout_requiredr   ancestors        rU   
_on_layoutScreen._on_layout  s     !!..00Hh//33314$$X.111$$X.226:"&??22F 1 4#8#8$(D!OO $9?s   D	Dc                z   #    UR                  5         UR                  5         SU l        U R                  5         g 7f)NT)re  r  r  r<  )rT   rf  s     rU   _on_update_scrollScreen._on_update_scroll  s,     ! $s   9;c           	     T   U R                   R                  nUb  UR                  (       a  U R                  XUR                  5      nO[        UR                  X5      5      nX0R                   R                  R                  -  nU R                   R                  nU R                   R                  nUb$  [        U[        UR                  X5      5      5      nUb$  [        U[        UR                  X5      5      5      n[        U R                  R                  R                  U5      nU$ )zGet the inline height (number of lines to display when running inline mode).

Args:
    size: Size of the terminal

Returns:
    Height for inline mode.
)r   heightis_autoget_content_heightwidthintresolver   
min_height
max_heightmaxminr   r   )rT   r   height_scalarr,  ry  rz  s         rU   r"  Screen._get_inline_height  s     ** M$9$9 33D

KM 5 5d ABM++222[[++
[[++
!s:3E3Ed3Q/RSM!s:3E3Ed3Q/RSMDHHMM00-@rX   c                n    U R                   (       a$  U R                  (       a  U R                  U5        ggg)z)Called by App when the screen is resized.N)r   r  r1  )rT   r   s     rU   _screen_resizedScreen._screen_resized  s)    $"2"2  & #3rX   c                   U R                   R                  (       a%  U R                  U R                   R                  5        U =R                  S-  sl        U R                   R	                  5         U R                   R
                  nU R                  5         U R                  (       aR  UR                  (       a  U R                  SS9  U R                  U:w  a  U R                  U5        U R                  5         gg)zScreen has resumed.rI   Fr  N)r   SUSPENDED_SCREEN_CLASSr   r   _refresh_notificationsr   _update_auto_focusr  refresh_stylesupdate_node_styles_sizer1  r(  )rT   r  r   s      rU   _on_screen_resumeScreen._on_screen_resume  s    88**dhh==>a'')xx}}!##'''6zzT!$$T*LLN rX   c                ^   >#    [         TU ]  5       I S h  vN   U R                  5         g  N7frt   )r   _composer  rH  s    rU   r  Screen._compose  s(     g   ! 	!s   -+-c                L   U R                   R                  (       a  U R                  c  U R                   R                  OU R                  nU(       aR  U R                  cD  U R	                  U5       H.  nUR
                  (       d  M  SUl        U R                  U5          g   gggg)zUpdate auto focus.NT)r   	app_focusrz   r   rz  rh  	has_focusr  )rT   
auto_focusr   s      rU   r  Screen._update_auto_focus  s    88'+'>##DOO  dll2"jj4F'''+/(v.	 5 3z	 rX   c                   U R                   R                  (       a%  U R                  U R                   R                  5        U R                   R                  SS5        U R	                  5         U =R
                  S-  sl        g)zScreen has suspended.NrI   )r   r  r   _set_mouse_over_clear_tooltipr   rS   s    rU   _on_screen_suspendScreen._on_screen_suspend  sV    88**NN488::;  t,arX   c                  #    UR                  5         U R                  UR                  5        U R                  R                   H  nUR                  UR                  5        M      U R
                  c  U R                  R
                  OU R
                  =(       d    / nU R                  c  U R                  R                  OU R                  =(       d    / nU(       d  U(       ap  UR                  u  pVX4-    VVs0 s H  u  pxUS_M
     n	nnU R                  XS5       H  nSX'   M	     U R                  Xd5       H  nSX'   M	     U R                  U	SS9  g g s  snnf 7f)NFTr  )	re  r  r   r   r   r   r   _get_breakpoint_classesupdate_classes)
rT   r  r   horizontal_breakpointsvertical_breakpointsrv  rs  r^  
breakpointbreakpointss
             rU   
_on_resizeScreen._on_resize  sV    

UZZ(hh22F""5::. 3
 **2 HH++,," 	 	 ((0 HH))**  	 	 "%9!JJME '=&S&SMA E!&S  
 #::
 +/'
 #::
 +/'
 U;# &:s   C7E9EAEc                P    [        USS9 H  u  p4X:  d  M  U1s  $    [        5       $ )zGet breakpoint classes for given dimension.

Args:
    dimension: Size in cells.
    breakpoints: Associated breakpoints.

Returns:
    A set containing a breakpoint, or an empty set if none apply.
T)reverse)r  r   )rT   	dimensionr  r  
class_names        rU   r  Screen._get_breakpoint_classes  s0     '-[$&G"J&"|# 'H urX   c                     U R                  [        5      nUR                  (       a"  U R                  UL a  U R	                  U5        ggg! [
         a     gf = f)z"Update the content of the tooltip.N)get_child_by_typerD   displayr   _handle_tooltip_timerr,   )rT   r   r  s      rU   _update_tooltipScreen._update_tooltip  sW    	3,,W5G 4#7#76#A**62 $B  		s   A 
AAc                     U R                  [        5      nUR                  (       a/  U R                  b  U R                  R                  5         SUl        gg! [         a     gf = f)z+Unconditionally clear any existing tooltip.NF)r  rD   r,   r  r   re  )rT   r  s     rU   r  Screen._clear_tooltip&  s^    	,,W5G ??"".##((*#GO   		s   A 
A%$A%c                    U R                   bF   U R                  " U R                  R                  6 u  p!X R                   La  U R	                  5         ggg! [
         a     gf = f)zxCheck if the widget under the mouse cursor still pertains to the tooltip.

If they differ, the tooltip will be removed.
N)r   rQ  r   mouse_positionr  r0   )rT   r^  under_mouses      rU   r  Screen._maybe_clear_tooltip1  si     +*!%!3!3TXX5L5L!M
 &:&::'') ; ,  s   %A 
A"!A"c                Z    U R                  [        5      nSnUR                   H5  n[        U[        5      (       d    OUR
                  c  M)  UR
                  n  O   Uc  SUl        gSUl        U R                  R                  Ul	        UR                  U5        g! [         a     gf = f)zpCalled by a timer from _handle_mouse_move to update the tooltip.

Args:
    widget: The widget under the mouse.
NFT)r  rD   r   r?  rC   r  r  r   r  absolute_offsetr  r,   )rT   r   r  tooltip_contentr   s        rU   r  Screen._handle_tooltip_timerC  s    	0,,W5G 6:O22!$//<<+&*llO 3 &"'"&*.((*A*A'/!  		s   B 
B*)B*c                B   S n U R                   R                  (       a2  U R                   R                  nU R                  U5      R                  nO3U R	                  UR
                  UR                  5      u  u  p4nUb  US   nU R                   R                  X25        U R                  5         UR                  Ul
        X0L a  U R                  U5        O3U R                  XU5      nUR                  5         UR                  U5        U R                   R                  (       d   U R!                  ["        5      nU R$                  U:w  d  UR&                  (       dl  X0l        U R(                  b  U R(                  R+                  5         U R-                  U R                   R.                  [1        U R2                  U5      SS9U l        O	SUl        O U R:                  R                  5         g ! [4         a     N'f = f! [6        R8                   a    U R                   R                  S S 5        U R(                  b  U R(                  R+                  5         U R                   R                  (       d.   SU R!                  ["        5      l         N! [4         a      Nf = f Nf = f)Nr   ztooltip-timer)r   F)r   mouse_capturedrs  r`  ra  rS  rT  r  rA  stylehover_styler   _translate_mouse_move_event_set_forwarded_forward_eventr   r  rD   r   r  r   re  	set_timerTOOLTIP_DELAYr   r  r,   r   r0   r   )rT   r  hover_widgetr   r`  hovermouse_eventr  s           rU   _handle_mouse_moveScreen._handle_mouse_move^  s"   &*-	0xx&&00))&188*.*C*CEGGUWW*U' %$#(8L HH$$V:%%'!&F~!!%(">>ufU**,%%k288--0"44W=G ++v5W__/5,..: //446.2nn HH22#D$>$>G!0 /= /+ +0# .$ 	((* ! /  	HH$$T40"".##((*88-->CD**73;   .		sC   B G; %G+ +
G87G8;A2J.J


JJJJJc                P   [         R                  " UU R                  UR                  -
  U R                  UR
                  -
  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9$ )zm
Returns a mouse move event whose relative coordinates are translated to
the origin of the specified region.
)screen_xscreen_yr  )r   	MouseMove_xrS  _yrT  _delta_x_delta_ybuttonshiftmetactrl	_screen_x	_screen_yr  )r  r   r`  s      rU   r  "Screen._translate_mouse_move_event  sy     HHvxxHHvxxNNNNLLKKJJJJ____++
 	
rX   c                   ^  US:  d   S5       eSU 4S jjnT R                  5         UT R                  R                  [        R                  -  -  U-  n[        XAU5      nU" 5         T R                  S[        R                  -  U5      T l        g)zStart (or update) auto scrolling.

Args:
    widget: Container widget to scroll.
    direction: Direction: `+1` for up, `-1` for down.
    speed: The scroll speed as a factor of the maximum.
r   z%Speed should be positive and non-zeroc                   > TR                   b7  U =R                  U-  sl        U R                  U l        TR                  5         gg)zScroll a container a single line in the given direction.

Args:
    widget: Container widgets to scroll.
    direction: Lines to scroll.
N)r   scroll_yscroll_target_y_update_select)r   r  rT   s     rU   _auto_scroll_y1Screen._start_auto_scroll.<locals>._auto_scroll_y  s<     !!-9,)/&##% .rX   rI   N)r   rC   r  floatrZ   rv   )_stop_auto_scrollr   SELECT_AUTO_SCROLL_SPEEDr   MAX_FPSr   r   r   )rT   r   r  speedr  lines_to_scrollscroll_callbacks   `      rU   _start_auto_scrollScreen._start_auto_scroll  s     qyAAAy	& 	  ::Y=N=NNORWW 	 "./J *.):):	!!!?*
&rX   c                b    U R                   b"  U R                   R                  5         SU l         gg)zStop any auto scrolling.N)r   re  rS   s    rU   r  Screen._stop_auto_scroll  s-    ))5**//1-1D* 6rX   c                   U R                   R                  (       d  gU R                  c  [        U5      S:  a  gUu  pE[	        [        U5      [        U5      5      nUR                   H  n[        U[        5      (       d    OUR                  (       d  M-  UR                  nU R                   R                  n	[        UU	S9u  pXj;   aD  UR                  S:  a2  XU
R                  -
  -
  U	-  nU(       a  U R                  USU5          gM  M  Xk;   d  M  UR                  UR                   :  d  M  X[R                  -
  U	-  nU(       d  M  U R                  USU5          g   U R#                  5         g)a   Check auto-scrolling when selecting.

This will start, update, or stop a timer used to move the scroll position.

Args:
    select_widget: The widget under the mouise pointer.
    mouse_coordinate: The screen-space mouse pointer.
    delta_y: Change in mouse y since previous mouse move.
NrI   )auto_scroll_linesr   r   )r   ENABLE_SELECT_AUTO_SCROLLr   absr1   rw  r   r?  rC   allow_vertical_scrollcontent_regionSELECT_AUTO_SCROLL_LINESr   r  rT  r  max_scroll_yr  )rT   select_widgetmouse_coordinatedelta_ymouse_xmouse_ymouse_offsetrl  ancestor_regionscroll_lines	up_regiondown_regionr  s                rU   _check_auto_scrollScreen._check_auto_scroll  sJ     xx11))1c'lQ6F+c'lCL9 &99Hh//11&55O88<<L%<".&"I ($$q( *y{{-BC|SE//"eD 	 ) ,$$x'<'<<$}}4DEu//"eD9 :< 	 rX   c                :    U R                  U R                  5        g)zGUpdate select for a screen-space offset (typically the mouse position).N)_watch__select_stater   rS   s    rU   r  Screen._update_select  s    !!$"4"45rX   c                   UR                   (       a  g UR                  5         [        U[        R                  [        R
                  45      (       a  U R                  U5        GO?[        U[        R                  5      (       Ga?  U R                  UR                  UR                  5      Ul        U R                  U5        U R                  (       a  U R                  b  U R                  UR                   UR"                  5      u  p#Ubp  Ub2  UnUn[        UR$                  [&        5      (       d   eUR$                  nOS nUnS nU R                  R)                  UR*                  [-        XdU5      5      U l        Ub5  U R/                  UUR0                  UR2                  4UR4                  5        GOU R7                  5         GO[        U[        R8                  5      (       Ga  [        U[        R:                  5      (       a  U R<                  bk  U R<                  UR*                  :X  aQ  U R                  UR                   UR"                  5      u  p#Ub  UR?                  S5      (       d  U RA                  5         S U l        SU l        U R                  [        RB                  " 5       5        GOf[        U[        RD                  5      (       GaF  U RF                  RH                  (       Gd*  UR*                  U l        U R                  UR                   UR"                  5      u  p#Ub  URJ                  (       a  U RL                  RJ                  (       a  U RF                  RN                  (       a  Ub2  UnUn[        UR$                  [&        5      (       d   eUR$                  nOS nUnS n[Q        UR*                  [S        UUR*                  URT                  RV                  -
  URT                  RV                  URX                  UUS9S9U l        OS U l         U RF                  RH                  (       a2  U RF                  RH                  nU R[                  U5      RT                  nO(U R]                  UR                   UR"                  5      u  px[        U[        RD                  5      (       aN  U R_                  UR                   UR"                  5      n	U	b%  U	Ra                  5       (       a  U Rc                  U	SS9  U R                  UR                  UR                  5      Ul        URd                  (       a  g XpL a"  UR                  5         U R                  U5        OIURg                  URi                  UR                   * UR"                  * 5      5        OU R                  U5        U Ro                  5         g ! [j        Rl                   a    U Rc                  S 5         N8f = f)Nrf  F)content_widgetcontent_offset)start)r  )8is_forwardedr  r?  r   EnterLeaver   r  rm  r  r  r  r  r>  r   rp  rS  rT  parentrC   
update_endscreen_offsetr<   r  pointer_screen_xpointer_screen_yr  r  
MouseEventMouseUpr   rg  rv  TextSelected	MouseDownr   r  r0  r   r/  r?   r>   r`  offsetscroll_offsetrs  rQ  rj  focus_on_clickr  r   r  _apply_offsetr   r0   rA  )
rT   r  r  select_offsetr  r  r  r   r`  focusable_widgets
             rU   r  Screen._forward_event  s   efllFLL9::e$v//00++ENNENNKEK##E*4#5#5#A/3/L/LGGUWW0, !,$0)6)6).*?*?HHHH$2$9$9	)-$1	)-)-););)F)F++!)^L*D&
 !,++%//1G1GH **,v0011%00++7//53F3FF 483P3P40M %,M4K4K)5 5 ,,.*.'"'!!&"5"5"78E6#3#344TXX=T=T=T*/*=*='/3/L/LGGUWW0, "-%2200--$0)6)6).*?*?HHHH$2$9$9	)-$1	)-)4++)%!//)2B2B2I2II%,,33%33+9+9
*D& *.D&U88**!XX44F!--f5<<F%)%7%7%INF eV%5%566'+'C'CEGGUWW'U$(4,;;=='7N"//O>>>((*%%e,))%*=*=vxxi&((*ST e$!!#+ ?? %t$%s   A5V5 5%WWc                $    U R                  5         g rt   )rv  rS   s    rU   _key_escapeScreen._key_escape  s    rX   c                4    U(       d  U R                  5         g g rt   )r  )rT   	selectings     rU   _watch__selectingScreen._watch__selecting  s    ""$ rX   c                    [        [        UUX415      5      nSn UR                  U5      nSn UR                  U5      S-   nXVU nU$ ! [         a     N)f = f! [         a     N"f = f)a  Get widgets between two widgets in select order.

Args:
    selection_bounds: A shape defining the selection bounds.
    container: A parent widgets.
    start_widget: First widget.
    end_widget: Second widget.

Returns:
    Widgets between start and end, in select sort order.
NrI   )r   rB   r  r  )	clsselection_boundsr  start_widget
end_widgetrV   index1index2resultss	            rU   _collect_select_widgetsScreen._collect_select_widgets  s    ( # *
 "	]]<0F "	]]:.2F (  		  		s"   A	 A 	
AA
A&%A&c                   Uc  SU l         U R                  5         gSU l         UR                  c  gUR                  (       d  SU l        gUR
                  (       a]  UR                  u  p#UR                  R                  c   eUR                  R                  [        R                  " UUS-   5      0U l        g[        nUR                  5        Vs0 s H  oUU_M     nnUR                  U5        X`l        gs  snf )z^Respond to user-initiated selection change.

Args:
    select_state: Current selection state.
NFT)rI   r   )r>  r(  endis_attached_to_domr   is_single_content_widgetcontent_offsetsr  r  r=   from_offsetsr   r;   _walk_selected_widgets_apply_content_selections)rT   select_statestart_index
end_offsetr{  r   r   s          rU   r  Screen._watch__select_state  s     #DOLLN"DO#..!%D 00&2&B&B#K%%44@@@""1193I3I'4DO   
-9-P-P-R
-R6J-R 	 
 	..z: %
s   C6c                   ^  SnT R                   (       a  T R                   S   nU" U5        T R                  R                  5       nSU 4S jjnUR                  U5        U$ )a  Dismiss the screen, optionally with a result.

Any callback provided in [push_screen][textual.app.App.push_screen] will be invoked with the supplied result.

!!! warning

    Textual will raise a [`ScreenError`][textual.app.ScreenError] if you await the return value from a
    message handler on the Screen being dismissed. If you want to dismiss the current screen, you can
    call `self.dismiss()` _without_ awaiting.

Args:
    result: The optional result to be passed to the result callback.

Tr   c                 V   > Sn [         R                  " 5       TL a  SSKJn  U" S5      eg)z#Called by the AwaitComplete object.Tr   ScreenErrorz_Can't await screen.dismiss() from the screen's message handler; try removing the await keyword.N)r   r   r   r3  )_rich_traceback_omitr3  rT   s     rU   	pre_await!Screen.dismiss.<locals>.pre_await  s2    #' "&&(D03!u  1rX   rZ   rv   )r   r   
pop_screenset_pre_await_callback)rT   rq   r4  rh   	await_popr5  s   `     rU   dismissScreen.dismiss  sY      $!!--b1HVHH'')		 	((3rX   c                v    SSK Jn   U R                  R                  U 5        g! U a    U" SU  S35      Sef = f)zPop any screens on top of this one, until this screen is active.

Raises:
    ScreenError: If this screen is not in the current mode.

r   r2  zCan't make z* active as it is not in the current stack.N)r   r3  r   _pop_to_screen)rT   r3  s     rU   pop_until_activeScreen.pop_until_active  sJ     	,	HH##D) 	dV#MN	s   $ 8c                b   #    U R                  5       I Sh  vN   U R                  U5        g N7f)zA wrapper around [`dismiss`][textual.screen.Screen.dismiss] that can be called as an action.

Args:
    result: The optional result to be passed to the result callback.
N)_flush_next_callbacksr;  rp   s     rU   action_dismissScreen.action_dismiss-  s*      ((***V 	+s   /-/c                   > XR                   R                  ;  a  gUR                  R                  S:X  a  UR                  U R                  ;   $ [
        TU ]  U5      $ )a=  Check if a given widget is fully within the current screen.

Note: This doesn't necessarily equate to a widget being visible.
There are other reasons why a widget may not be visible.

Args:
    widget: A widget.

Returns:
    `True` if the entire widget is in view, `False` if it is partially visible or not in view.
Fr   )r   visible_widgetsr   overlayr`  r   r  rT   r   r   s     rU   r  Screen.can_view_entire6  sO     ))999==  H,==DKK//w&v..rX   c                   > XR                   R                  ;  a  gUR                  R                  S:X  a  UR                  U R                  ;   $ [
        TU ]  U5      $ )zCheck if a given widget is at least partially within the current view.

Args:
    widget: A widget.

Returns:
    `True` if the any part of the widget is in view, `False` if it is completely outside of the screen.
Fr   )r   rF  r   rG  r`  r   can_view_partialrH  s     rU   rK  Screen.can_view_partialK  sO     ))999==  H,==DKK//w'//rX   c                "    Uc  S$ [        U5      $ )z'Ensure the title is a string or `None`.Nr  )rT   r   s     rU   validate_titleScreen.validate_title]  s    }t4#e*4rX   c                "    Uc  S$ [        U5      $ )z+Ensure the sub-title is a string or `None`.NrN  )rT   r   s     rU   validate_sub_titleScreen.validate_sub_titlea  s     (t<c)n<rX   )__update_timerr   r   r   r   r   r  r   r   r   r   r  r  r   r  r   r>  rG  r   r   r   r   r   r   r   r   r   r   r   NNNr   
str | Noner   rW  r   rW  rZ   rv   )rZ   r  )rZ   rA   )rZ   ztuple[str, ...])rZ   r4   )r   dict[Widget, Selection]r   rX  r7  )r   Widget | Noner   rY  rZ   rv   )rZ   z!list[tuple[DOMNode, BindingsMap]])rZ   zdict[str, ActiveBinding])F)r   r4   r%  r  rZ   r6   )rZ   rC   )r8  r.   rZ   rv   )rZ   r   )r   rC   rZ   r1   )rS  rw  rT  rw  rZ   rO   )rS  rw  rT  rw  rZ   rM   )rS  rw  rT  rw  rZ   zIterable[tuple[Widget, Region]])rS  rw  rT  rw  rZ   rY  )rS  rw  rT  rw  rZ   r   )rS  rw  rT  rw  rZ   z#tuple[Widget | None, Offset | None])r   rC   rZ   r   r  )rZ   r!  )r   ry  )r  rw  r  str | type[QueryType]rZ   rY  )ry  )r  rZ  rZ   rY  )T)r   rC   r  r  rZ   r  )rZ   rW  )r  r  rZ   rv   rt   )r   rC   r  zlist[Widget] | NonerZ   rv   )NN)r   rY  r  rY  rZ   rv   )TF)r   rY  r  r  r  r  rZ   rv   )rV   r!  rZ   rv   )r  zevents.MountrZ   rv   )r  zevents.IdlerZ   rv   )rh   r#   r=  rH   rZ   rv   )rg   rH   rh   ru   ri   z.asyncio.Future[ScreenResultType | None] | NonerZ   rv   )NF)r   zSize | Noner0  r  rZ   rv   )rf  zmessages.UpdaterZ   rv   )rf  zmessages.LayoutrZ   rv   )rf  zmessages.UpdateScrollrZ   rv   )r   r4   rZ   rw  )r   r4   rZ   rv   )r  zevents.ScreenResumerZ   rv   )r  zevents.ResizerZ   rv   )r  rw  r  zlist[tuple[int, str]]rZ   zset[str])r  events.MouseMoverZ   rv   )r  r[  r   rC   r`  r2   rZ   r[  )g      ?)r   rC   r  zLiteral[+1, -1]r  r  rZ   rv   )r  rC   r  ztuple[float, float]r  r  rZ   rv   )r  zevents.EventrZ   rv   )r  r  rZ   rv   )
r  r3   r  rC   r  rC   r  rC   rZ   r!  )r,  zSelectState | NonerZ   rv   )rq   ScreenResultType | NonerZ   r%   )rq   r\  rZ   rv   )r   rC   rZ   r  )r   r   rZ   rW  )r   r   rZ   rW  )r[   r\   r]   r^   r_   rz   r`   r|   r}   COMPONENT_CLASSESDEFAULT_CSSr~   r   r   r   r7   r   r   r   r   r   r   r   r   r   r8   dictr   r>  r   r   r   r'   BINDINGSrk   ra   r   r   r   r   r   r   r   r   r   r   r  r	  r  r   r,  r0  r3  r9  rA  rI  rM  rQ  ra  rY  rj  rm  rp  rs  rv  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r-  r   r  r>  rA  rD  rK  r1  rg  rm  rp  r"  r  r  r  r  r  r  r  r  r  r  r  r  staticmethodr  r  r  r  r  r  r  r  classmethodr"  r  r;  r?  rC  r  rK  rO  rR  rb   __classcell__r   s   @rU   rx   rx      sZ   %'+J$+ C
 .2H*1 -- KD #'E& '+I#* FJBI DCG@G}'/~G$5r#+Au#=M===&.tU&CI#CV"*4"?E?JMPUHJR 5918c 15-4 ])1$t)DI&DL/24yJ,8-UJ32:4.M/@--0Y*6F(+IN%6* 	'EB13C%P "46JQVWH  "	:2:2 :2 	:2
 
:2 :2x     # # * * 9 9  C/C ,C3	.$1	.>K	.		. &" &"P   ( (T6p   ! !	3,"!,	34P6
56
3???	,?4"


 6 6r EHCC,AC	CJ-"."0,.(
% ?C33(;3	3l GKD$D6CD	D6  $$	5757 57 	57
 
57nA
1 .%`=8+	 BF	

 D
 ?	

 

"%P'd,0'
(" #<J+@	"3	$*$060+d 

)/
9?
	
 
4 	,
,
 #,
 	,

 
,
\2;!;! .;! 	;!
 
;!z6|$|% (( ( 	(
 ( 
( (T+%Z!F"/*0$5= =rX   rx   c                  L   ^  \ rS rSrSrSr   S       SU 4S jjjrSrU =r$ )ModalScreenif  zA screen with bindings that take precedence over the App's key bindings.

The default styling of a modal screen will dim the screen underneath.
z
    ModalScreen {
        layout: vertical;
        overflow-y: auto;
        background: $background 60%;
        &:ansi {
            background: transparent;                   
        }
    }
    c                0   > [         TU ]  XUS9  SU l        g )Nr   T)r   rk   r   )rT   r   r   r   r   s       rU   rk   ModalScreen.__init__x  s     	d7;rX   r   rU  rV  )	r[   r\   r]   r^   r_   r^  rk   rb   rc  rd  s   @rU   rf  rf  f  sJ    
	K  "	  	
 
 rX   rf  c                      \ rS rSrSrSrg)SystemModalScreeni  a  A variant of `ModalScreen` for internal use.

This version of `ModalScreen` allows us to build system-level screens;
the type being used to indicate that the screen should be isolated from
the main application.

Note:
    This screen is set to *not* inherit CSS.
rY   N)r[   r\   r]   r^   r_   rb   rY   rX   rU   rj  rj    s    rX   rj  F)inherit_css)|r_   
__future__r   asyncio	functoolsr   operatorr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   	rich.reprrichrich.consoler   
rich.styler   textualr   r   r   r   textual._arranger   textual._auto_scrollr   textual._callbackr   textual._compositorr   r   textual._contextr   r   textual._pathr    r!   r"   textual._typesr#   textual.actionsr$   textual.await_completer%   textual.bindingr&   r'   r(   textual.css.matchr*   textual.css.parser+   textual.css.queryr,   r-   textual.css.stylesr.   textual.domr/   textual.errorsr0   textual.geometryr1   r2   r3   r4   textual.keysr5   textual.layoutr6   textual.reactiver7   r8   %textual.renderables.background_screenr9   textual.renderables.blankr:   textual.selectionr;   r<   r=   r>   r?   textual.signalr@   textual.timerrA   textual.walkrB   textual.widgetrC   textual.widgetsrD   textual.widgets._toastrE   typing_extensionsrF   textual.commandrG   textual.message_pumprH   r  rJ   r`   rK   ScreenResultCallbackTyperM   reprautord   rx   rf  rj  rY   rX   rU   <module>r     s   #         '  7 7 $ 8 $ 7 F 
 ( & 0 ? ? # - 2 +  # 8 8 ) , * B + X X !  0 ! # ,'( 1  )"3"33| 3-.  " h'()4/0h'()9T?:;=  1
: 
" $W-. $ $N O=W%& O= O=d> &)*  6	$455 	rX   