
    AHjx                      U d Z ddlmZ ddl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 ddlZddl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%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZFmGZGmHZHmIZI ddlJmKZK ddlLmMZM ddlNmOZOmPZP ddlQmRZR ddlSmTZT ddlUmVZVmWZW dd lXmYZY dd!lZm[Z[ dd"l\m]Z] dd#l^m_Z_ dd$l`maZa e	rdd%lbmcZc dd&ldmeZe dd'lfmgZg d(ej                  z  Zid)ejd*<    ed+      Zk	 eeeek   gdf   eeek   ged   f   f   Zl	  G d, d-e      Zmej                  j                   G d. d/eek                Zpej                  j                   G d0 d1eek   e]             Zqej                  j                   G d2 d3eqek                Zr G d4 d5erek   d67      Zsy)8z

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
NamedTupleOptionalTypeVarUnion)RenderableType)Style)	constantserrorseventsmessages)arrange)invoke)
CompositorMapGeometry)active_message_pumpvisible_screen_stack)CSSPathType_css_path_type_as_list_make_path_object_relative)
SpatialMap)CallbackType)
SkipAction)AwaitComplete)ActiveBindingBindingBindingsMapmatch)parse_selectors)	NoMatches	QueryType)DOMNode)NoWidget)NULL_OFFSETOffsetRegionSize)key_to_character)DockArrangeResult)Reactivevar)BackgroundScreen)Blank)
SELECT_ALL	Selection)Signal)Timer)Widget)Tooltip)	ToastRack)Final)Provider)MessagePump   zFinal[float]UPDATE_PERIODScreenResultTypec                  <    e Zd ZU dZded<   	 ded<   	 edd       Zy)	HoverWidgetszJResult of [get_hover_widget_at][textual.screen.Screen.get_hover_widget_at]tuple[Widget, Region]
mouse_overztuple[Widget, Region] | None
hover_overc                \    | j                   d   | j                  dfS | j                  d   fS )zJust the widgets.r   N)rI   rJ   selfs    F/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/screen.pywidgetszHoverWidgets.widgets_   s<     OOAOO+D
 	
151C
 	
    N)returnztuple[Widget, Widget | None])__name__
__module____qualname____doc____annotations__propertyrO    rP   rN   rG   rG   W   s)    T%%5,,Y
 
rP   rG   c                  2    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZddZy)ResultCallbackz Holds the details of a callback.Nc                2    || _         	 || _        	 || _        y)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rM   r\   r]   r^   s       rN   __init__zResultCallback.__init__l   s"     #@9A$%rP   c                    | j                   | j                   j                  |       | j                  2| j                  &| j                  j	                  | j                  |       d| _        y)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)r^   
set_resultr\   r]   	call_nextrM   results     rN   __call__zResultCallback.__call__   sR     ;;"KK""6*>>%$--*CNN$$T]]F;rP   N)r\   rB   r]   1ScreenResultCallbackType[ScreenResultType] | Noner^   z'asyncio.Future[ScreenResultType] | NonerQ   None)re   rE   rQ   ri   )rR   rS   rT   rU   r`   rf   rX   rP   rN   rZ   rZ   h   s;    * ;?	&& D& 8	&
 
&(rP   rZ   c                      e Zd ZU dZdZded<   	 dZded<   	 dZded	<   	 d
hZdZ	dZ
ded<   	 dZded<   	 dZded<   	 dZded<   	  ed      Zded<   	  edd      Zded<   	  edd      Zded<   	  edd      Zded<   	  e       Zded<   	 dZded<   	 dZded <   	  edd!"      Zded#<   	  ee      Zd$ed%<   	  ed      Z	  ed      Z	  ed      Zd&ed'<   	  ed      Zd&ed(<   	  ed      Zd)ed*<   	  e d+d,d-d.       e d/d0d1d.       e d2d3d4d.      gZ!	 	 	 d	 	 	 	 	 	 	 d fd5Z"e#dd6       Z$e#dd7       Z%e#dd8       Z&e#d fd9       Z'e#dd:       Z(d; Z)d< Z*	 	 	 	 dd=Z+dd>Z,	 	 	 	 	 	 dd?Z-e#dd@       Z.e#ddA       Z/e#ddB       Z0ddCZ1e#ddD       Z2e#ddE       Z3ddFZ4ddGZ5ddHZ6ddIZ7ddJZ8ddKZ9ddLZ:	 	 	 	 	 	 ddMZ;ddNZ<ddOZ=ddPZ>e#ddQ       Z?	 d	 	 	 	 	 ddRZ@dddSZAdddTZBdddUZCddVZDddWZEddXZFddYZGddZZHdd[ZIdd\ZJ	 d	 	 	 	 	 dd]ZK	 d	 	 	 	 	 dd^ZL	 	 d	 	 	 	 	 	 	 dd_ZMdd`ZNddaZOddbZPddcZQdddZRddeZSddfZT	 d	 	 	 	 	 	 	 ddgZUd fdhZVddiZWdddjZXddkZYddlZZddmZ[ddnZ\ddoZ]ddpZ^d fdqZ_ddrZ`ddsZaddtZb	 	 	 	 	 	 dduZcddvZdddwZeddxZfddyZgddzZhei	 	 	 	 	 	 	 	 dd{       Zjdd|Zkdd}Zl	 	 	 	 dd~ZmdddZnddZodddZpd fdZqd fdZrddZsddZt xZuS )ScreenzThe base class for screens.NzClassVar[str | None]
AUTO_FOCUS zClassVar[str]CSSzClassVar[CSSPathType | None]CSS_PATHzscreen--selectiona  
    Screen {
        layout: vertical;
        overflow-y: auto;
        background: $background;        
        
        &:inline {
            height: auto;
            min-height: 1;
            border-top: tall $background;
            border-bottom: tall $background;
        }

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

            &.-screen-suspended {                                            
                text-style: dim;
                ScrollBar {
                    text-style: not dim;
                }
            }
        }
        .screen--selection {
            background: $primary 50%;            
        }
    }
    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[tuple[Widget, Offset, Offset] | None]_select_start_select_endzvar[Offset | None]_mouse_down_offsettabzapp.focus_nextz
Focus Next)showz	shift+tabzapp.focus_previouszFocus Previouszctrl+czscreen.copy_textzCopy selected textc                   d| _         t        | 	  |||       t               | _        t               | _        d| _        g | _        g | _	        d| _
        d| _        | j                  t        | j                        ng D cg c]  }t        ||        }}|| _        | j                   | _        | j$                  | _        t)        | d      | _        	 t)        | d      | _        	 t)        | d      | _        	 d| _        yc c}w )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superr`   r   _compositorset_dirty_widgets_Screen__update_timer
_callbacks_result_callbacks_tooltip_widget_tooltip_timerro   r   r    css_pathrp   ry   rq   rx   r;   screen_layout_refresh_signalbindings_updated_signaltext_selection_started_signal_css_update_count)rM   r   r   r   r   	css_paths	__class__s         rN   r`   zScreen.__init__  s    dr7;%<+.5,0BDPR.2,0 ==, 't}}5
 'x6
	 
 "ZZ
<B"=
) 	R7=dDV7W$D=C%>
* 	B!##7
s   C=c                    | j                   S )zIs the screen modal?)r   rL   s    rN   is_modalzScreen.is_modalD  s     {{rP   c                    ddl m} 	 | j                  j                  | u xs | | j                  j                  v S # |$ r Y yw xY w)z-Is the screen current (i.e. visible to user)?r   )ScreenStackErrorF)textual.appr   appscreen_background_screens)rM   r   s     rN   
is_currentzScreen.is_currentI  sE     	1	88??d*Rddhh6R6R.RR 		s   1: AAc                    | j                   (| j                  t        | j                  dd      | _         | j                   S )zTimer used to perform updates.screen_updateT)r   pause)r   set_intervalrD   _on_timer_updaterL   s    rN   _update_timerzScreen._update_timerS  sF     &"&"3"3t44?RV #4 #D """rP   c                    dg}| j                   j                  s|j                  d       | j                   j                  s|j                  d       g t        |   |S )zPLayers from parent.

        Returns:
            Tuple of layer names.
        _loading
_toastrack	_tooltips)r   _disable_notificationsappend_disable_tooltipsr   layers)rM   extrasr   s     rN   r   zScreen.layers\  sR     xx..MM,'xx))MM+&))&))rP   c                p    | j                   j                  | j                  j                  j                  z
  S )zThe size of the screen.)r   sizestylesguttertotalsrL   s    rN   r   zScreen.sizej  s'     xx}}t{{118888rP   c                $    | j                          y rg   refresh_bindingsrL   s    rN   _watch_focusedzScreen._watch_focusedo      rP   c                $    | j                          y rg   r   rL   s    rN   _watch_stack_updateszScreen._watch_stack_updatesr  r   rP   c                   K   |j                         |j                         z  D ]#  }|j                  |j                  |d              % y wrg   )keysselection_updatedget)rM   old_selectionsr   widgets       rN   _watch_selectionszScreen._watch_selectionsu  sG     
 %))+joo.?? 	CF$$Z^^FD%AB	Cs   A	Ac                :    | j                   j                  |        y)z&Call to request a refresh of bindings.N)r   publishrL   s    rN   r   zScreen.refresh_bindings}  s    $$,,T2rP   c                z    | j                  |d ud       ||j                  d       ||j                  d       y y )Nz-maximized-viewz
-maximized)	set_classremove_class	add_class)rM   previously_maximizedr   s      rN   _watch_maximizedzScreen._watch_maximized  sE    
 	y,.?@+ --l; - !rP   c           	        | j                   }||j                  rd}|M| | j                  j                         f| j                  | j                  j                  j                         fg}n3|j
                  D cg c]  }||j                  j                         f  }}g }|D ]c  \  }}|D ]H  }|j                  }t        |j                        D ]"  }	 ||	t        |	            s|j                  |	= $ J |j                  |       e | j                  j                  }
|D ]L  \  }}|
s	|j                  |
      }|j                  s'| j                  j                  |j                  |       N |S c c}w )zBinding chain from this screen.N)rt   loading	_bindingscopyr   ancestors_with_selfcheck_consume_keylistkey_to_bindingsr3   r   _keymapapply_keymapclashed_bindingshandle_bindings_clash)rM   rt   namespace_bindingsnodefilter_namespaces	namespacebindings_mapfilter_namespacer   keykeymapre   s               rN   _binding_chainzScreen._binding_chain  s    ,,7??G ?t~~**,-488--2245" ;B:U:U"26t~~**,-" "
 ,.'9 		0#I|$5 > $4$F$F! < <= >C(.>s.CD )88=	>> $$Y/		0 !!'9 	W#I|%226:**HH2263J3JIV		W "!1"s   :#E2c                r    | j                   }t        |d      D ]  \  }\  }}|j                  s|d| c S  |S )z=The binding chain, ignoring everything before the last modal.rC   N)r   	enumerater   )rM   binding_chainindexr   r   s        rN   _modal_binding_chainzScreen._modal_binding_chain  sK     ++(1-(C 	-$E$D)}}$Ve,,	- rP   c                   i }| j                   }| j                  D ]  \  }}|D ]  \  }}|j                  |j                  |      }|du r't	        |      }|j                  |      x}	r@|j                  sR|	j                  j                  rit        ||||j                        ||<   t        ||||j                        ||<     |S )a  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)
rM   r   r   r   bindingsr   r   action_stateenabledexisting_key_and_bindings
             rN   active_bindingszScreen.active_bindings  s     24hh#'#<#< 	Ix ( W"66w~~yQ5( |,/;/?/?/DD+D  (( 8 @ @ I I,9%w-S)
 )6!7GW__)L%-	6 rP   c                    | j                   j                   j                  f} j                  j	                  |      }||S  j
                   j                  j
                  n j
                  d fd}t          j                   | j                        n j                   | j                  d      x} j                  |<   |S )z~Arrange children.

        Args:
            size: Size of container.

        Returns:
            Widget locations.
        c                    | hj                        j                  d      }j                  D cg c]	  }||v s| }}| |vr|j                  d|        |S c c}w )zpGet widgets to display in maximized view.

            Returns:
                A list of widgets.

            z.-textual-systemr   )query_childrenchildreninsert)r   rO   r   maximize_widgetsallow_in_maximized_viewrM   s       rN   get_maximize_widgetsz,Screen.arrange.<locals>.get_maximize_widgets  s     $$%<= $$%78G 6:]]X6fPWFWXX 00 ''95##	  Ys
   	AAF)r   r=   rQ   list[Widget])	_nodes_updatesr   _arrangement_cacher   r{   r   r   r   )rM   r   	cache_keycached_resultr   arrangementr   s   `     @rN   r   zScreen.arrange  s     4;;//@	//33I>$   ++3 HH,,-- 	 	$( <C >>- %T^^4[[II
<
 
	
d--i8 rP   c                R    	 | j                   j                  | u S # t        $ r Y yw xY w)z9Is the screen active (i.e. visible and top of the stack)?F)r   r   	ExceptionrL   s    rN   	is_activezScreen.is_active   s,    	88??d** 		s    	&&c                    | j                   S )z,Check if this widget permits text selection.)ALLOW_SELECTrL   s    rN   allow_selectzScreen.allow_select(  s        rP   c                2   | j                   j                  }	 t        j                         j	                         }||j                  dk  rt        ||      S |j                  r| j                  j                         S t        |      S # t
        $ r d}Y [w xY w)zRender method inherited from widget, used to render the screen's background.

        Returns:
            Background renderable.
        NrC   )r   
backgroundr   r   popLookupErrorar7   is_transparentr   renderr8   )rM   r  base_screens      rN   r  zScreen.render-  s     [[++
	.22488:K "z||a'7#K<<$$88??$$Z    	K	s   "B BBc                8    | j                   j                  |      S )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rM   r   s     rN   r  zScreen.get_offsetC  s     **622rP   c                :    | j                   j                  ||      S )a	  Get 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rM   xys      rN   r  zScreen.get_widget_atN  s     --a33rP   c                `   t        | j                  j                  ||            }	 t        |      \  }}|j                  s6|D ]#  \  }}|j                  st        ||f||f      c S  t        ||fd      S t        ||f||f      S # t        $ r t        j                  d| d| d      w xY w)a  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   r.   _has_hover_stylerG   )rM   r  r  widgets_under_coordinate
top_widget
top_regionr   regions           rN   get_hover_widgets_atzScreen.get_hover_widgets_at]  s     $((8(8(G(G1(M#N 	Y%)*B%C"J
 **": T**'Z(@66BRSST  Z 8$??Z4z:6NOO  	Y//$MaSPRSTRUUV"WXX	Ys   B &B-c                :    | j                   j                  ||      S )zGet all widgets under a given coordinate.

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

        Returns:
            Sequence of (WIDGET, REGION) tuples.
        )r   r   r  s      rN   r   zScreen.get_widgets_atx  s     ..q!44rP   c                    	 | j                  ||      \  }}|j                  d      s|j                  ry|j                  D ]#  }t        |t              s|j                  s!|c S  y# t        $ r Y yw xY w)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.
        Nz-textual-system)r  r.   	has_classr   r   
isinstancer=   	focusable)rM   r  r  r   _regionr   s         rN   get_focusable_widget_atzScreen.get_focusable_widget_at  sz    	"00A6OFG -.&.... 	D$'DNN	   		s   A( (	A43A4c                :    | j                   j                  ||      S )zGet the style under a given coordinate.

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

        Returns:
            Rich Style object.
        )r   get_style_atr  s      rN   r1  zScreen.get_style_at  s     ,,Q22rP   c                :    | j                   j                  ||      S )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_atr  s      rN   r3  zScreen.get_widget_and_offset_at  s     88A>>rP   c                8    | j                   j                  |      S )a   Get 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_widgetr  s     rN   r5  zScreen.find_widget  s     ++F33rP   c                .    i | _         d| _        d| _        y)zClear any selected text.N)r   r   r   rL   s    rN   clear_selectionzScreen.clear_selection  s    !rP   c                l    t         }||i|j                  d      D ci c]  }|| c}| _        yc c}w )zdSelect a widget and all it's children.

        Args:
            widget: Widget to select.
        *N)r9   queryr   )rM   r   
select_allchilds       rN   _select_all_in_widgetzScreen._select_all_in_widget  s;      
J
.4ll3.?@Uuj @
@s   
1c                2   g }|j                   }t        d      }t        t        | j                  |            | j
                  fg}|j                  }|j                   }|r|d   \  }}t        |d      }	|	 |        n|	j                         r1|	j                  j                  d      }
|
r|
dk7  n|}|	j                  r:|	j                         r*t        |	j                  |      } |t        |      |f       |r|	j                         r ||	       |r|S )z9A list of widgets that may receive focus, in focus order._focus_sort_keyr   r   N
visibilityhidden)r   r   r  sorteddisplayed_childrenvisibler  r!  _check_disabledr   get_ruleis_containerallow_focus_childrenallow_focus)rM   rO   
add_widgetfocus_sorter
node_stackr  pushchildren_iteratorparent_visibilityr   node_styles_visibilitynode_is_visiblesorted_displayed_childrens                rN   focus_chainzScreen.focus_chain  s'    !#^^
!"34 VD33FG;

 nn  3=b>00)40D|''))-)=)=l)K& . +h6*  
 $$)B)B)D06//\1- $89?KL #t'7'7'9t$- 0 rP   c                >   t        |t              s|j                  }t        |      | j                  }| j
                  9t        | j
                  j                  d            }|D cg c]	  }||v s| }}fd|D        }|s| j                  S | j                  )t        |d      }| j                  |       | j                  S |st        | j                        sd}	 |j                  | j                        }|rYd}t        |      }	t        dt        |      dz         D ]   }
||||
z  z   |	z     }t        |      s|} n | j                  |       | j                  S c c}w # t        $ r) | j                  t        |d             Y | j                  S w xY w)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  <   K   | ]  }t        |      s|  y wrg   r(   ).0r   selector_sets     rN   	<genexpr>z%Screen._move_focus.<locals>.<genexpr>'  s       
E,,ED 
s   rC   )r,  strrR   r*   rT  r   r   walk_childrenrt   r!  	set_focusr)   r   lenrange
ValueError)rM   	directionselectorrT  r-  r   filtered_focus_chainto_focuscurrent_indexchain_lengthstepr   rZ  s               @rN   _move_focuszScreen._move_focus	  s   ( (C(((H&x0&& >>%DNN8848HII0;Sfv?R6SKS 
( 
 <<<<0$7HNN8$<< |T\\!BI	)'--dll;M ";/!!S%5%9: D&&T)99\ID \40#' x(||O T,  	=NN4 4d;< ||#	=s   *	E%4E%#E* *$FFc                &    | j                  d|      S )aC  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.
        rC   ri  rM   rc  s     rN   
focus_nextzScreen.focus_nextN  s     8,,rP   c                &    | j                  d|      S )aG  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   rk  rl  s     rN   focus_previouszScreen.focus_previous_  s     H--rP   c                    |j                   rI|r?|j                  D ]0  }t        |t              s	 || _        y|j                   s)|| _         y || _        yy)a'  Maximize 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,  r=   r   )rM   r   	containermaximize_widgets       rN   maximizezScreen.maximizep  sb       '-'7'7 $O%ov>
 $DN '55)8#$ $DNrP   c                ~    d| _         | j                  *| j                  | j                  | j                  dd       yy)z-Restore any maximized widget to normal state.NFT)animatecenter)r   rt   call_after_refreshscroll_to_widgetrL   s    rN   minimizezScreen.minimize  s>    <<###%%t||U4 $  $rP   c                    | j                   syg }| j                   j                         D ]*  \  }}|j                  |      }||j                  |       , dj	                  |      j                  d      }|S )zrGet text under selection.

        Returns:
            Selected text, or `None` if no text was selected.
        Nrm   
)r   itemsget_selectionextendjoinrstrip)rM   widget_textr   	selectionselected_text_in_widgetselected_texts         rN   get_selected_textzScreen.get_selected_text  s{     !#!%!6!6!8 	<FI&,&:&:9&E#&2""#:;	<
 ,33D9rP   c                r    | j                         }|
t               | j                  j                  |       y)z Copy selected text to clipboard.N)r  r#   r   copy_to_clipboard)rM   r  s     rN   action_copy_textzScreen.action_copy_text  s0    **,	,""9-rP   c                T    | j                   | j                  | j                          yy)z0Action to maximize the currently focused widget.N)rt   ru  rL   s    rN   action_maximizezScreen.action_maximize  s!    <<#MM$,,' $rP   c                $    | j                          y)z2Action to minimize the currently maximized widget.N)r{  rL   s    rN   action_minimizezScreen.action_minimize  s    rP   c                &    | j                  d       y)z Action to remove focus (if set).N)r^  rL   s    rN   action_blurzScreen.action_blur  s    trP   c                   K   	 | j                  |      j                         }t        |t              r| j	                  |       yy# t
        $ r Y yw xY ww)zAn [action](/guide/actions) to focus the given widget.

        Args:
            selector: Selector of widget to focus (first match).
        N)r:  firstr,  r=   r^  r+   )rM   rc  r   s      rN   action_focuszScreen.action_focus  sR     	%::h'--/D $'t$ (  		s'   AA #A	AAAAc                   |xs g }| j                   |ury| j                  }|s| j                  d       y	 |j                  |      }d}t        ||dz   d |d| z         D ]
  }||vs|} n | j                  |       y# t        $ rJ |j
                  D ]'  }||vs|j                  s| j                  |        Y y | j                  d       Y yw xY w)zReset the focus when a widget is removed

        Args:
            widget: A widget that is removed.
            avoiding: Optional list of nodes to avoid.
        NrC   )rt   rT  r^  r   ra  visible_siblingsr-  reversed)rM   r   avoidingfocusable_widgetswidget_indexsiblingchosen	candidates           rN   _reset_focuszScreen._reset_focus  s
    >r <<v% !,, NN4 	 -226:L !%!lQ.014Em|4TT
 	I ("	 	v/  
	 "22 %(*w/@/@NN7+ %
 t$
	s#   B   CC*C>CCc                   t               }|It        |j                        D ]1  }|j                  s|j	                  |j                  d              n |It        |j                        D ]1  }|j                  s|j	                  |j                  d              n |r(| j                  j                  j                  |d       yy)zUpdate CSS for focus changes.

        Args:
            focused: The widget that was focused.
            blurred: The widget that was blurred.
        NTrV  )rw  )	r   r  r   _has_focus_withinupdater]  r   
stylesheetupdate_nodes)rM   rt   blurredrO   r   s        rN   _update_focus_styleszScreen._update_focus_styles  s     !$"7#>#>? ++NN6#7#7$#7#GH "7#>#>? ++NN6#7#7$#7#GH HH,,Wd,C rP   c                    | j                   u ryd}d}|h j                   @ j                   j                  t        j                                 j                   }d _          j                  j                  d       n|j                  r j                   |k7  r j                   9 j                   j                  t        j                                 j                   }| _         |j                  t        j                  |             |}|rd fd} j                  ||        j                  j                  |d        j                  ||        j                   j                         y)a  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                n    j                   | u r&j                  |       sj                  | d       yyy)z#Scroll to center (after a refresh).T)origin_visibleN)rt   can_view_entirescroll_to_center)r   rM   s    rN   r  z*Screen.set_focus.<locals>.scroll_to_center=  s8    <<61$:N:Nv:V 11&1N ;W1rP   zwas focusedr   r=   rQ   ri   )rt   post_messager   Blurlogdebugr-  Focus
call_laterr  ry  r   )rM   r   scroll_visibler  rt   r  r  s   `      rN   r^  zScreen.set_focus  s    T\\!!%!%>||'))&++-8,,#HHNN./||v%<<+LL--fkkm<"llG%##FLL$OP !O
 OO$4f=v}5!!'73 5 56rP   c                    | j                   j                  s|j                  dt        d             | j                   j                  s|j                  dt        d             yy)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   r>   r   r?   )rM   rO   s     rN   _extend_composezScreen._extend_composeI  sK     xx))NN1g):;<xx..NN1i+>?@ /rP   c                T    | j                   j                  | | j                  d       y)z1Set up the tooltip-clearing signal when we mount.T)	immediateN)r   	subscribe_maybe_clear_tooltiprM   events     rN   	_on_mountzScreen._on_mountW  s(    ))33$++t 	4 	
rP   c                R  K   |j                          | j                  j                  sc| j                  rW| j                  s0| j
                  s$| j                  s| j                  s| j                  r| j                  j                          y | j                          d {    y 7 wrg   )prevent_defaultr   _batch_countr   _layout_required_scroll_required_repaint_required_recompose_requiredr   r   resume_invoke_and_clear_callbacksr  s     rN   _on_idlezScreen._on_idle]  sy     xx$$%%(())++&&""))+..000s   BB'B% B'c                   | j                   }|j                  rr| |j                  u r|j                         }|j                  duxr ||j                  k  }|j                  | | j                  j                  |j                  j                  |      |j                  |             ||_        | j                  j                          | j                  j                  j                          n| | j                   j                  v r| j                  j                  r |j                  j                  | j                  j                    | j                  j                  j                          | j                  j                          n$| |j                  u rS| j                  j                  |j                        }|j                  | |       | j                  j                          n| | j                   j                  v r| j                  j                  r | j                   | j                  j                     |j                  j                  | j                  j                    d| _        | j                  j                  j                          | j                  j                          |j%                  |        y)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)rM   r   inline_heightr  r  s        rN   _compositor_refreshzScreen._compositor_refreshm  s)    hh==szz! # 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##))+ szz!))77!$!8!8 8  T6*##))+4449I9I9X9X!1!1!@!@A"

""D$4$4$C$CD)-&  //557##))+t$rP   c                   | j                   j                          | j                  r=| j                  j                  s&| j
                  r>| j                  | j                         d| _        | j                  j                          n| j                  r| j                  d       d| _        | j                  r<| j                  j                          | j                  j                  |        d| _
        | j                  r5| j                  j                  | j                         | j                          | j                  r"d| _        | j!                  | j"                         | j$                  r| j!                  | j&                         yy)zCalled by the _update_timer.)scrollFTN)r   r   r   r   r  r  _refresh_layoutr  r   r  r  addr   update_widgetsr  r  rc   	recomposer   r  rL   s    rN   r   zScreen._on_timer_update  s(     "??488#8#8$$$$D,A,A$B(-%##))+&&$$D$1$)D!%%##))+##''-).&""  //0C0CD((*''+0(t~~.??NN4;;< rP   c                   K   | j                   r`| j                   dd }| j                   j                          |D ]1  \  }}|j                         5  t        |       d{    ddd       3 yy7 # 1 sw Y   AxY ww)zXIf there are scheduled callbacks to run, call them and clear
        the callback queue.N)r   r  _contextr   )rM   	callbacksr]   message_pumps       rN   r  z"Screen._invoke_and_clear_callbacks  s      ??*IOO!!#*3 +&,!**, + ***+ ++ 
 ++ +s0   AA>A2A0 A2$A>0A22A;	7A>c                ^    | j                   j                  ||f       | j                          y)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)rM   r]   senders      rN   _invoke_laterzScreen._invoke_later  s%     	&12rP   c                l    | j                   j                  t        t        t              |||             y)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   rZ   r   rE   r_   s       rN   _push_result_callbackzScreen._push_result_callback  s/     	%%8$456y(FS	
rP   c                  K   t         |           d {    | j                  j                          | j                  j                          | j
                  j                          | j                  j                          | j                  j                  |        | j                  j                          d | _        y 7 wrg   )r   _message_loop_exitr   r  r   r  r  r   unsubscriber  _clear_taskrM   r   s    rN   r  zScreen._message_loop_exit  s     g(*** !!#!!#%%'))55d;
 	+s   CB?B*Cc                8    | j                   j                          y)z1Remove the latest result callback from the stack.N)r   r  rL   s    rN   _pop_result_callbackzScreen._pop_result_callback  s    ""$rP   c                   || j                   n|}| j                  j                  r)|j                  | j                  j	                               }|sy| j
                  j                  | j                         | j                  j                          t        j                  }	 |r| j
                  j                  | |      }|r]| j
                  j                  }|D ]U  \  }\  }}}	}
}}}||v s|j                  |j                  |
|d      s3|j!                   ||j                  |
|             W n| j
                  j#                  | |      \  }}}t        j$                  }t        j&                  }|D ]  }|j!                   |               ||z  }| j
                  j                  }|D ]R  \  }\  }}}	}
}}}|j                  |j                  |
|       ||v s0|j!                   ||j                  |
|             T |D ]  }|j!                   |               | j,                  r| j/                          | j                  j0                  r&| j2                  j5                  | j6                         y| j                  j!                  t        j8                                d| j                  _        y# t(        $ r%}| j                  j+                  |       Y d}~yd}~ww xY w)z>Refresh the layout (can change size and positions of widgets).NFr}   T)
outer_sizer   r  r  r  r   r  r   r   r   r   Resizereflow_visibler   _size_updatedr   r  reflowHideShowr  _handle_exceptionr   r  
_dom_readyr   r   r   Ready)rM   r   r  ResizeEventexposed_widgetsr   r   r'  _order_clipvirtual_sizecontainer_size_rB  shownresizedr  r  send_resizeerrors                       rN   r  zScreen._refresh_layout  s   "&,tD88##DHH$?$?$ABD''(;(;<  "mm8	"&"2"2"A"A$"M"!--44F  "  !$&!_4%33 &\>RW  4   !' 3 3$/(.\>%&!""( *.)9)9)@)@t)L&w{{{{$ 0F''/0 $go))00  F  "((lNS,++'\>R $ 0F''/0 ??$$&88--55dkkBHH!!&,,.1"&DHH  	HH&&u-	s-   #AJ8 /J8 CJ8 AJ8 8	K&K!!K&c                   K   |j                          |j                          |j                  }t        |t              sJ | | j
                  v r,| j                  j                  |       | j                          y y wrg   )	stopr  r   r,  r=   r   r   r  r  )rM   messager   s      rN   
_on_updatezScreen._on_update:  se     !&&)))4#####F+OO $s   A:A<c                z   K   |j                          |j                          d| _        | j                          y wNT)r  r  r  r  rM   r  s     rN   
_on_layoutzScreen._on_layoutD  -     ! $   9;c                z   K   |j                          |j                          d| _        | j                          y wr	  )r  r  r  r  r
  s     rN   _on_update_scrollzScreen._on_update_scrollJ  r  r  c           	     N   | j                   j                  }||j                  r| j                  |||j                        }nt        |j                  ||            }|| j                   j                  j                  z  }| j                   j                  }| j                   j                  }|%t        |t        |j                  ||                  }|%t        |t        |j                  ||                  }t        | j                  j                  j                  |      }|S )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   )rM   r   height_scalarr  r  r  s         rN   r  zScreen._get_inline_heightP  s     ** M$9$9 33D$

KM 5 5dD ABM++222[[++
[[++
!s:3E3EdD3Q/RSM!s:3E3EdD3Q/RSMDHHMM00-@rP   c                Z    | j                   r| j                  r| j                  |       yyy)z)Called by App when the screen is resized.N)rv   is_attachedr  rM   r   s     rN   _screen_resizedzScreen._screen_resizedh  s)    $"2"2  & #3rP   c                   | j                   j                  r%| j                  | j                   j                         | xj                  dz  c_        | j                   j	                          | j                   j
                  }| j                          | j                  rW| j                          | j                   j                  j                  |        | j                  |       | j                          yy)zScreen has resumed.rC   N)r   SUSPENDED_SCREEN_CLASSr   rv   _refresh_notificationsr   _update_auto_focusr  r  r  r  r  r  r  s     rN   _on_screen_resumezScreen._on_screen_resumem  s    88**dhh==>a'')xx}}!$$&HH&&t,  &LLN	 rP   c                ^   K   t         |           d {    | j                          y 7 wrg   )r   _composer#  r  s    rN   r&  zScreen._compose  s)     g   ! 	!s   -+-c                &   | j                   j                  r{| j                  | j                   j                  n| j                  }|rJ| j                  =| j	                  |      D ](  }|j
                  sd|_        | j                  |        y yyyy)zUpdate auto focus.NT)r   	app_focusrl   rt   r:  r-  	has_focusr^  )rM   
auto_focusr   s      rN   r#  zScreen._update_auto_focus  s    88'+'>##DOO  dll2"jj4 F''+/(v.	 3z	 rP   c                    | j                   j                  r%| j                  | j                   j                         | j                   j                  dd       | j	                          | xj
                  dz  c_        y)zScreen has suspended.NrC   )r   r!  r   _set_mouse_over_clear_tooltiprv   rL   s    rN   _on_screen_suspendzScreen._on_screen_suspend  sV    88**NN488::;  t,arP   c                  K   |j                          | j                  |j                         | j                  j                  D ]  }|j                  |j                          | j
                  | j                  j
                  n| j
                  xs g }| j                  | j                  j                  n| j                  xs g }|j                  \  }}|r| j                  ||       |r| j                  ||       y y wrg   )r  r  r   r   r   rr   rs   _set_breakpoints)rM   r  r   horizontal_breakpointsvertical_breakpointsr  r  s          rN   
_on_resizezScreen._on_resize  s     

UZZ(hh22 	/F""5::.	/
 **2 HH++,," 	 	 ((0 HH))**  	 	 

v!!!%)?@!!&*>?  s   C?Dc                    |D cg c]  \  }}|	 }}} | j                   |  t        |d      D ]  \  }}||k\  s| j                  |        y yc c}}w )zSet horizontal or vertical breakpoints.

        Args:
            dimension: Either the width or the height.
            breakpoints: A list of breakpoints.

        T)reverseN)r   rC  r   )rM   	dimensionbreakpoints_breakpoint
class_nameclass_names
breakpoints          rN   r0  zScreen._set_breakpoints  sf     BMM&=k:zMM;'&,[$&G 	"J
J&z*	 Ns   Ac                    	 | j                  t              }|j                  r!| j                  |u r| j	                  |       yyy# t
        $ r Y yw xY w)z"Update the content of the tooltip.N)get_child_by_typer>   displayr   _handle_tooltip_timerr+   )rM   r   r   s      rN   _update_tooltipzScreen._update_tooltip  sW    	3,,W5G 4#7#76#A**62 $B  		s   A 	AAc                    	 | j                  t              }|j                  r.| j                  | j                  j                          d|_        yy# t        $ r Y yw xY w)z+Unconditionally clear any existing tooltip.NF)r=  r>   r+   r>  r   r  )rM   r   s     rN   r-  zScreen._clear_tooltip  s^    	,,W5G ??"".##((*#GO   		s   A 	AAc                    | j                   G	  | j                  | j                  j                   \  }}|| j                   ur| j	                          yyy# t
        $ r Y yw xY w)zCheck if the widget under the mouse cursor still pertains to the tooltip.

        If they differ, the tooltip will be removed.
        N)r   r  r   mouse_positionr-  r.   )rM   r  under_mouses      rN   r  zScreen._maybe_clear_tooltip  so     +*!3!3!3TXX5L5L!MQ
 d&:&::'') ; ,  s   &A 	A! A!c                F   	 | j                  t              }d}|j                  D ].  }t        |t              s n|j
                  "|j
                  } n |d|_        yd|_        | j                  j                  |_	        |j                  |       y# t        $ r Y yw xY w)zCalled by a timer from _handle_mouse_move to update the tooltip.

        Args:
            widget: The widget under the mouse.
        NFT)r=  r>   r   r,  r=   r   r>  r   rC  absolute_offsetr  r+   )rM   r   r   tooltip_contentr   s        rN   r?  zScreen._handle_tooltip_timer  s    	0,,W5G 6:O22 !$/<<+&*llO &"'"&*.((*A*A'/!  		s   B 	B B c                   d }	 | j                   j                  r2| j                   j                  }| j                  |      j                  }n3| j	                  |j
                  |j                        \  \  }}}||d   }| j                   j                  ||       |j                  |_	        || u r| j                  |       n4| j                  |||      }|j                          |j                  |       | j                   j                  s	 | j                  t               }| j"                  |k7  s|j$                  so|| _        | j&                  | j&                  j)                          | j+                  | j                   j,                  t/        | j0                  |      d      | _        y d|_        y y # t2        $ r Y y w xY w# t4        j6                  $ r | j                   j                  d d        | j&                  | j&                  j)                          | j                   j                  s-	 d| j                  t               _        Y y # t2        $ r Y Y y w xY wY y w xY w)Nr   ztooltip-timer)r   F)r   mouse_capturedr5  r'  r(  r  r  r,  stylehover_styler  _translate_mouse_move_event_set_forwarded_forward_eventr   r=  r>   r   r>  r   r  	set_timerTOOLTIP_DELAYr   r?  r+   r   r.   )rM   r  hover_widgetr   r'  hovermouse_eventr   s           rN   _handle_mouse_movezScreen._handle_mouse_move  s   &*,	0xx&&00))&188*.*C*CEGGUWW*U' %$#(8L HH$$V\:!&F~!!%(">>uff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   A;G F5 5	G GA+I0I	IIIIIc                T   t        j                  || j                  |j                  z
  | j                  |j
                  z
  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                        S )z
        Returns a mouse move event whose relative coordinates are translated to
        the origin of the specified region.
        )screen_xscreen_yrJ  )r   	MouseMove_xr  _yr  _delta_x_delta_ybuttonshiftmetactrl	_screen_x	_screen_yrJ  )r  r   r'  s      rN   rL  z"Screen._translate_mouse_move_event3  sy     HHvxxHHvxxNNNNLLKKJJJJ____++
 	
rP   c                .	   |j                   ry |j                          t        |t        j                  t        j
                  f      r| j                  |       y t        |t        j                        r| j                  |j                  |j                        |_        | j                  |       | j                  r|j                  | _        | j!                  |j"                  |j$                        \  }}| j&                  b|`|j$                  | j&                  d   j$                  kD  r:| j&                  d   }|j(                  j*                  }||j,                  |f| _        y |%|j.                  r|||j,                  |f| _        y y y y y t        |t        j0                        rt        |t        j2                        rD| j4                  )| j4                  |j6                  k(  r| j9                          d | _        d| _        nt        |t        j:                        r| j<                  j>                  s|j                  | _        |j6                  | _        | j!                  |j                  |j                        \  }}|s|j.                  rg| j@                  j.                  rQ| j<                  jB                  r;d| _        |9|7| jD                  jG                  |        ||j6                  |f| _$        nd| _        	 | j<                  j>                  r2| j<                  j>                  }| jK                  |      jL                  }n)| jO                  |j"                  |j$                        \  }}t        |t        j:                        r;| jQ                  |j"                  |j$                        }|r| jS                  |d       | j                  |j                  |j                        |_        |jT                  ry || u r"|j                          | j                  |       y |jW                  |jY                  |j"                   |j$                                y | j                  |       y # tZ        j\                  $ r | jS                  d        Y y w xY w)NrC   r   FT)r  )/is_forwardedrM  r,  r   EnterLeaver  rX  r1  rV  rW  rJ  rT  
_selectingr^  _box_selectr3  r  r  r   content_regionbottom_right_inclusiveoffsetr  
MouseEventMouseUpr   screen_offsetr7  	MouseDownr   rI  r   r  r   r   r   r5  r'  r  r/  r^  r   rN  _apply_offsetr   r.   )rM   r  select_widgetselect_offset
end_widgetr   r'  focusable_widgets           rN   rN  zScreen._forward_eventJ  s   efllFLL9:e$v//0++ENNENNKEK##E*#(;; /3/L/LGGUWW0,} $$0%-$"2"21"5"7"77!%!1!1!!4J$.$=$=$T$TM(2ELL-'PD$ "-%22%1(5u||]'SD$ 2 3 . * v001%0++7//53F3FF((**.'"'E6#3#34TXX=T=T#(;; */*=*='/3/L/LNNENN0,} "-%2200--&*DO$0]5N::BB4H)!//).* ',DOU88**!XX44F!--f5<<F%)%7%7%INFF eV%5%56'+'C'CEGGUWW'U$''7N"//O>>T>((*%%e,))%*=*=vxxi&((*ST e$# ?? %t$%s   ?A1Q- -$RRc                $    | j                          y rg   )r7  rL   s    rN   _key_escapezScreen._key_escape  s    rP   c           
        || j                   y| j                   }|\  }}}|\  }}}||u r|t        j                  ||      i| _        yt	        ||gd       \  }}|\  }}	}|\  }}
}g }|j
                  }|j
                  }|j                  |j                  k  s| j                  r'|j                  t        j                  ||             nT	 t        j                  |j                  j
                  |j                  j
                  g      }t        j                  |j                   |j                  |j"                  |j                        }t        j                  |j                   |j                  |j"                  |j                        }|j                  |       |j                  |       |j                  |j                  z
  }|dkD  rTt        j                  |j                   |j                  |j"                  |j                  |z         }|j                  |       t%               }|j'                  | j(                  j*                  j-                         D cg c]  }|j.                  t0        dd|f c}       t3               }|D ]N  }|j5                  |      }|D cg c]  }|j7                  |j
                        r|! }}|j9                  |       P || ||hz  }t:        }|t        |d      it	        |d       D ci c]  }|| c}|t        d|      i| _        y# t        $ r Y yw xY wc c}w c c}w c c}w )zWhen select_end changes, we need to compute which widgets and regions are selected.

        Args:
            select_end: The end selection.
        Nc                H    | d   j                   j                  j                  S )Nr   )r'  rk  	transpose)r  s    rN   <lambda>z+Screen._watch__select_end.<locals>.<lambda>  s    9Q<#6#6#=#=#G#G rP   r@  r   Fc                B    | j                   j                  j                  S rg   )ri  rk  ry  )r   s    rN   rz  z+Screen._watch__select_end.<locals>.<lambda>	  s    v'<'<'C'C'M'M rP   )r   r:   from_offsetsr   rC  ri  r  bottomrh  r   r1   union
from_unionselect_containerr+   from_cornersr  rightr!   r   r   visible_widgetsr   r'  r/   r   get_values_in_regionoverlapsr  r9   )rM   
select_endselect_startstart_widgetscreen_startstart_offsetrs  
screen_end
end_offset_screen_start_screen_endselect_regionsstart_region
end_regioncontainer_region
mid_height
mid_regionspatial_mapr   highlighted_widgetsr'  covered_widgetsr;  s                          rN   _watch__select_endzScreen._watch__select_end  sU    !3!3!;))3?0lL-7*
J
:% i44\:NDO #):&H$
 j
 5A1m\.8+
K')#22..
<<<...$2B2B!!&,,|Z"HI#)#4#4$55DD"33BB$  ".. &&##	L  ,, ""  !!	J !!,/!!*-#(;(;;JA~#00$&& ''$** ''*4	
 %%j1*4, #..>>CCE UE6B	
 ,/5$ 	8F)>>vFO .??6#8#89 O 
  &&7	8 	lJ??
)L$7

 %'M 
"

 	$
3

_  :s$   ?L+ L:%$L?	
M+	L76L7c                    d} j                   s% j                  j                  d       t               S  j                  r j                  d   } ||        j
                  j                         }d fd}|j                  |       |S )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.

        Only the active screen may be dismissed. This method will produce a warning in the logs if
        called on an inactive screen (but otherwise have no effect).

        !!! 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.

        TzCan't dismiss inactive screenr   c                 R    d} t        j                         u rddlm}  |d      y)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   r  )_rich_traceback_omitr  rM   s     rN   	pre_awaitz!Screen.dismiss.<locals>.pre_await*  s2    #' "&&(D03!u  1rP   rQ   ri   )r	  r  warningr$   r   r   
pop_screenset_pre_await_callback)rM   re   r  r]   	await_popr  s   `     rN   dismisszScreen.dismiss  s{    $  $~~HH<= ?"!!--b1HVHH'')		 	((3rP   c                t    ddl m} 	 | j                  j                  |        y# |$ r  |d|  d      dw xY w)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   r  zCan't make z* active as it is not in the current stack.N)r   r  r   _pop_to_screen)rM   r  s     rN   pop_until_activezScreen.pop_until_active8  sJ     	,	HH##D) 	dV#MN	s   $ 7c                b   K   | j                          d{    | j                  |       y7 w)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  rd   s     rN   action_dismisszScreen.action_dismissI  s+      ((***V 	+s   /-/c                    || j                   j                  vry|j                  j                  dk(  r|j                  | j                  v S t
        |   |      S )au  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   r  r   overlayr'  r   r  rM   r   r   s     rN   r  zScreen.can_view_entireR  sQ     ))999==  H,==DKK//w&v..rP   c                    || j                   j                  vry|j                  j                  dk(  r|j                  | j                  v S t
        |   |      S )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   r  r   r  r'  r   can_view_partialr  s     rN   r  zScreen.can_view_partialg  sQ     ))999==  H,==DKK//w'//rP   c                     |dS t        |      S )z'Ensure the title is a string or `None`.Nr\  )rM   ry   s     rN   validate_titlezScreen.validate_titley  s    }t4#e*4rP   c                     |dS t        |      S )z+Ensure the sub-title is a string or `None`.Nr  )rM   rx   s     rN   validate_sub_titlezScreen.validate_sub_title}  s     (t<c)n<rP   NNNr   
str | Noner   r  r   r  rQ   ri   )rQ   r   )rQ   r<   )rQ   ztuple[str, ...])rQ   r2   )r   dict[Widget, Selection]r   r  r  )r   Widget | Noner   r  rQ   ri   )rQ   z!list[tuple[DOMNode, BindingsMap]])rQ   zdict[str, ActiveBinding])r   r2   rQ   r4   )rQ   r   )r   r=   rQ   r0   )r  r  r  r  rQ   rH   )r  r  r  r  rQ   rG   )r  r  r  r  rQ   zIterable[tuple[Widget, Region]])r  r  r  r  rQ   r  )r  r  r  r  rQ   r   )r  r  r  r  rQ   z#tuple[Widget | None, Offset | None])r   r=   rQ   r   r  )rQ   r   )r   r9  )rb  r  rc  str | type[QueryType]rQ   r  )r9  )rc  r  rQ   r  )T)r   r=   rs  r   rQ   r   )rQ   r  )rc  r\  rQ   ri   rg   )r   r=   r  zlist[Widget] | NonerQ   ri   )NN)rt   r  r  r  rQ   ri   )TF)r   r  r  r   r  r   rQ   ri   )rO   r   rQ   ri   )r  zevents.MountrQ   ri   )r  zevents.IdlerQ   ri   )r]   r"   r  rB   rQ   ri   )r\   rB   r]   rh   r^   z.asyncio.Future[ScreenResultType | None] | NonerQ   ri   )NF)r   zSize | Noner  r   rQ   ri   )r  zmessages.UpdaterQ   ri   )r  zmessages.LayoutrQ   ri   )r  zmessages.UpdateScrollrQ   ri   )r   r2   rQ   r  )r   r2   rQ   ri   )r  zevents.ResizerQ   ri   )r6  r  r7  zlist[tuple[int, str]]rQ   ri   )r  events.MouseMoverQ   ri   )r  r  r   r=   r'  r1   rQ   r  )r  zevents.EventrQ   ri   )r  z$tuple[Widget, Offset, Offset] | NonerQ   ri   )re   ScreenResultType | NonerQ   r$   )re   r  rQ   ri   )r   r=   rQ   r   )ry   r   rQ   r  )rx   r   rQ   r  )vrR   rS   rT   rU   rl   rV   rn   ro   COMPONENT_CLASSESDEFAULT_CSSrp   rq   rr   rs   r5   rt   rv   rx   ry   r   rz   r{   r|   r   r6   dictr   rg  rh  r   r   r   r&   BINDINGSr`   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r  r  r  r(  r   r/  r1  r3  r5  r7  r=  rT  ri  rm  ro  ru  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.  r3  r0  r@  r-  r  r?  rT  staticmethodrL  rN  rv  r  r  r  r  r  r  r  r  __classcell__r   s   @rN   rk   rk      s   %'+J$+ C
 .2H*1 --K< #'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3e*K4DLTNMARPBJ4.K?PM-0Y*6F 	'EB13C%P,.BOH  "	4$4$ 4$ 	4$
 
4$l     # # * * 9 9  C/C ,C3	.$1	.>K	.		. &" &"P   ( (T5n   ! !!,	34P6
56
3???	,?4 

 - -` 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
 ?	

 

"%K'Z0'
$" @0+@	"3	$*$06.0` 

)/
9?
	
 
,Y%ve
>e
	e
N'R"/*0$5=rP   rk   c                  >     e Zd ZdZdZ	 	 	 d	 	 	 	 	 	 	 d fdZ xZS )ModalScreenzA 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                8    t         |   |||       d| _        y )Nr   T)r   r`   r   )rM   r   r   r   r   s       rN   r`   zModalScreen.__init__  s      	dr7;rP   r  r  )rR   rS   rT   rU   r  r`   r  r  s   @rN   r  r    sJ    
	K  "	  	
 
 rP   r  c                      e Zd ZdZy)SystemModalScreena  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.
    N)rR   rS   rT   rU   rX   rP   rN   r  r    s    rP   r  F)inherit_css)trU   
__future__r   asyncio	functoolsr   operatorr   typingr   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._callbackr   textual._compositorr   r   textual._contextr   r   textual._pathr   r   r    textual._spatial_mapr!   textual._typesr"   textual.actionsr#   textual.await_completer$   textual.bindingr%   r&   r'   textual.css.matchr)   textual.css.parser*   textual.css.queryr+   r,   textual.domr-   textual.errorsr.   textual.geometryr/   r0   r1   r2   textual.keysr3   textual.layoutr4   textual.reactiver5   r6   %textual.renderables.background_screenr7   textual.renderables.blankr8   textual.selectionr9   r:   textual.signalr;   textual.timerr<   textual.widgetr=   textual.widgetsr>   textual.widgets._toastr?   typing_extensionsr@   textual.commandrA   textual.message_pumprB   MAX_FPSrD   rV   rE   ScreenResultCallbackTyperG   reprautorZ   rk   r  r  rX   rP   rN   <module>r     s   #        '  7 7 $ $ 7 F 
 , ' & 0 ? ? # - 2  # > > ) , * B + 3 !  ! # ,'( 1  )"3"33| 3-.  " h'()4/0h'()9T?:;=  1
: 
" $W-. $ $N n=W%& n= n=b7 &)*  6	$455 	rP   