Ë
    £cgj†6  ã                  ó²   — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZmZmZ g d¢Zeez  ez  e	z  Z G d	„ d
«      Z G d„ de«      Zddd„Zy)z
Wrapper for the layout.
é    )Úannotations)Ú	GeneratorÚIterable)ÚBufferé   )ÚAnyContainerÚConditionalContainerÚ	ContainerÚWindowÚto_container)ÚBufferControlÚSearchBufferControlÚ	UIControl)ÚLayoutÚInvalidLayoutErrorÚwalkc                  óp  — e Zd ZdZ	 d	 	 	 	 	 dd„Zdd„Zd d„Zd!d„Zd"d„Zd#d„Z	e
d$d	„«       Zej                  d%d
„«       Ze
d&d„«       Zej                  d'd„«       Ze
d(d„«       Ze
d)d„«       Zd*d„Zd+d„Ze
d,d„«       Zd-d„Ze
d(d„«       Ze
d$d„«       Zd.d„Zd.d„Zd.d„Zd/d„Zd/d„Zd.d„Zd.d„Zd0d„Zy)1r   aL  
    The layout for a prompt_toolkit
    :class:`~prompt_toolkit.application.Application`.
    This also keeps track of which user control is focused.

    :param container: The "root" container for the layout.
    :param focused_element: element to be focused initially. (Can be anything
        the `focus` function accepts.)
    Nc                ó2  — t        |«      | _        g | _        i | _        i | _        |€;	 | j                  j                  t        | j                  «       «      «       g | _        y | j                  |«       g | _        y # t        $ r}t        d«      |‚d }~ww xY w)Nz>Invalid layout. The layout does not contain any Window object.)r   Ú	containerÚ_stackÚsearch_linksÚ_child_to_parentÚappendÚnextÚfind_all_windowsÚStopIterationr   ÚfocusÚvisible_windows)Úselfr   Úfocused_elementÚes       úm/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/prompt_toolkit/layout/layout.pyÚ__init__zLayout.__init__(   sŸ   € ô
 & iÓ0ˆŒØ$&ˆŒð GIˆÔð
 =?ˆÔàÐ"ðØ—‘×"Ñ"¤4¨×(=Ñ(=Ó(?Ó#@ÔAð .0ˆÕð �J‰J�Ô'ð .0ˆÕøô !ò Ü(ØTóàðûðús   ©2A< Á<	BÂBÂBc                ó<   — d| j                   ›d| j                  ›d�S )NzLayout(z, current_window=Ú))r   Úcurrent_window©r   s    r"   Ú__repr__zLayout.__repr__J   s%   € Ø˜Ÿ™Ð*Ð*;¸D×<OÑ<OÐ;RÐRSÐTÐTó    c              #  ó`   K  — | j                  «       D ]  }t        |t        «      sŒ|–— Œ y­w)zJ
        Find all the :class:`.UIControl` objects in this layout.
        N)r   Ú
isinstancer   )r   Úitems     r"   r   zLayout.find_all_windowsM   s'   è ø€ ð —I‘I–KˆDÜ˜$¤Õ'Ø“
ñ  ùs   ‚$.§.c              #  óR   K  — | j                  «       D ]  }|j                  –— Œ y ­w©N)r   Úcontent©r   r   s     r"   Úfind_all_controlszLayout.find_all_controlsU   s%   è ø€ Ø×.Ñ.Ö0ˆIØ×#Ñ#Ó#ñ 1ùs   ‚%'c                óþ  — t        |t        «      ra| j                  «       D ]?  }t        |t        «      sŒ|j                  j
                  |k(  sŒ.| j                  |«        y t        d|›d�«      ‚t        |t        «      rW| j                  «       D ]5  }t        |t        «      sŒ|j                  |k(  sŒ$| j                  |«        y t        d|›d�«      ‚t        |t        «      r@|| j                  «       vrt        d«      ‚|j                  «       st        d«      ‚|| _        yt        |«      }t        |t        «      r(|| j                  «       vrt        d|›�«      ‚|| _        yg }t!        |d¬«      D ]?  }t        |t        «      sŒ|j"                  j                  «       sŒ/|j%                  |«       ŒA t'        | j(                  «      D ]  }||v sŒ|| _         y |r|d	   | _        yt        d
|›�«      ‚)a¨  
        Focus the given UI element.

        `value` can be either:

        - a :class:`.UIControl`
        - a :class:`.Buffer` instance or the name of a :class:`.Buffer`
        - a :class:`.Window`
        - Any container object. In this case we will focus the :class:`.Window`
          from this container that was focused most recent, or the very first
          focusable :class:`.Window` of the container.
        Nz,Couldn't find Buffer in the current layout: Ú.z7Invalid value. Container does not appear in the layout.z*Invalid value. UIControl is not focusable.z5Invalid value. Window does not appear in the layout: T©Úskip_hiddenr   z,Invalid value. Container cannot be focused: )r+   Ústrr1   r   ÚbufferÚnamer   Ú
ValueErrorr   r   Úis_focusableÚcurrent_controlr   r   r   r&   r   r/   r   Úreversedr   )r   ÚvalueÚcontrolÚwindowsÚcÚws         r"   r   zLayout.focusY   sæ  € ô �eœSÔ!Ø×1Ñ1Ö3�Ü˜g¤}Õ5¸'¿.¹.×:MÑ:MÐQVÓ:VØ—J‘J˜wÔ'Ùð 4ô ÐKÈEÈ9ÐTUÐVÓWÐWô ˜œvÔ&Ø×1Ñ1Ö3�Ü˜g¤}Õ5¸'¿.¹.ÈEÓ:QØ—J‘J˜wÔ'Ùð 4ô ÐKÈEÈ9ÐTUÐVÓWÐWô ˜œyÔ)Ø˜D×2Ñ2Ó4Ñ4Ü ØMóð ð ×%Ñ%Ô'Ü Ð!MÓNÐNà#(ˆDÕ ô ! Ó'ˆEä˜%¤Ô(à × 5Ñ 5Ó 7Ñ7Ü$ØOÐPUÈyÐYóð ð ',�Õ#ð �Ü˜e°×6�AÜ! !¤VÕ,°·±×1GÑ1GÕ1IØŸ™ qÕ)ð 7ô
 " $§+¡+Ö.�AØ˜G’|Ø./˜Ô+Ùð /ñ Ø*1°!©*�DÔ'Øä ØBÀ5À)ÐLóð r)   c                ó‚  — t        |t        «      r&| j                  €y| j                  j                  |k(  S t        |t        «      r| j                  |k(  S t        |t
        «      r| j                  |k(  S t        |«      }t        |t        «      r| j                  |k(  S t        |«      D ]  }|| j                  k(  sŒ y y)zˆ
        Check whether the given control has the focus.
        :param value: :class:`.UIControl` or :class:`.Window` instance.
        FT)r+   r6   Úcurrent_bufferr8   r   r   r;   r   r   r&   r   )r   r=   Úelements      r"   Ú	has_focuszLayout.has_focus§   sµ   € ô
 �eœSÔ!Ø×"Ñ"Ð*ØØ×&Ñ&×+Ñ+¨uÑ4Ð4Ü�eœVÔ$Ø×&Ñ&¨%Ñ/Ð/Ü�eœYÔ'Ø×'Ñ'¨5Ñ0Ð0ä  Ó'ˆEÜ˜%¤Ô(Ø×*Ñ*¨eÑ3Ð3ô  $ Ež{�GØ $×"5Ñ"5Ó5Ù#ð  +ð r)   c                ó4   — | j                   d   j                  S )zI
        Get the :class:`.UIControl` to currently has the focus.
        éÿÿÿÿ)r   r/   r'   s    r"   r;   zLayout.current_controlÀ   s   € ð
 �{‰{˜2‰×&Ñ&Ð&r)   c                ór   — | j                  «       D ]  }|j                  |k(  sŒ|| _         y t        d«      ‚)zC
        Set the :class:`.UIControl` to receive the focus.
        Nz(Control not found in the user interface.)r   r/   r&   r9   )r   r>   Úwindows      r"   r;   zLayout.current_controlÇ   s<   € ð
 ×+Ñ+Ö-ˆFØ�~‰~ Ó(Ø&,�Ô#Ùð .ô
 ÐCÓDÐDr)   c                ó    — | j                   d   S )z=Return the :class:`.Window` object that is currently focused.rG   )r   r'   s    r"   r&   zLayout.current_windowÓ   s   € ð �{‰{˜2‰Ðr)   c                ó:   — | j                   j                  |«       y)z8Set the :class:`.Window` object to be currently focused.N)r   r   )r   r=   s     r"   r&   zLayout.current_windowØ   s   € ð 	�‰×Ñ˜5Õ!r)   c                ó2   — | j                   | j                  v S )z#True if we are searching right now.)r;   r   r'   s    r"   Úis_searchingzLayout.is_searchingÝ   s   € ð ×#Ñ# t×'8Ñ'8Ð8Ð8r)   c                ór   — | j                   }t        |t        «      r| j                  j	                  |«      S y)zY
        Return the :class:`.BufferControl` in which we are searching or `None`.
        N)r;   r+   r   r   Úget)r   r>   s     r"   Úsearch_target_buffer_controlz#Layout.search_target_buffer_controlâ   s4   € ð ×&Ñ&ˆä�gÔ2Ô3Ø×$Ñ$×(Ñ(¨Ó1Ð1àr)   c              #  ó–   K  — | j                  «       D ]2  }t        |t        «      sŒ|j                  j	                  «       sŒ/|–— Œ4 y­w)zl
        Return all the :class:`.Window` objects which are focusable (in the
        'modal' area).
        N)Úwalk_through_modal_arear+   r   r/   r:   )r   rA   s     r"   Úget_focusable_windowszLayout.get_focusable_windowsð   s9   è ø€ ð
 ×-Ñ-Ö/ˆAÜ˜!œVÕ$¨¯©×)?Ñ)?Õ)AØ“ñ 0ùs   ‚$A	§A	ÁA	c                ój   — | j                   }| j                  «       D �cg c]	  }||v sŒ|‘Œ c}S c c}w )zO
        Return a list of :class:`.Window` objects that are focusable.
        )r   rS   )r   r   rA   s      r"   Úget_visible_focusable_windowsz$Layout.get_visible_focusable_windowsù   s9   € ð ×.Ñ.ˆØ×5Ñ5Ô7ÓPÑ7�a¸1ÀÒ;O’Ð7ÑPÐPùÒPs   Ÿ	0©0c                óT   — | j                   }t        |t        «      r|j                  S y)zD
        The currently focused :class:`~.Buffer` or `None`.
        N)r;   r+   r   r7   ©r   Ú
ui_controls     r"   rC   zLayout.current_buffer  s(   € ð
 ×)Ñ)ˆ
Ü�j¤-Ô0Ø×$Ñ$Ð$Ør)   c                óü   — | j                  «       D ]i  }t        |t        «      sŒt        |j                  t        «      sŒ/|j                  j
                  j                  |k(  sŒS|j                  j
                  c S  y)zt
        Look in the layout for a buffer with the given name.
        Return `None` when nothing was found.
        N)r   r+   r   r/   r   r7   r8   )r   Úbuffer_namerA   s      r"   Úget_buffer_by_namezLayout.get_buffer_by_name  sX   € ð
 —‘–ˆAÜ˜!œVÕ$¬°A·I±I¼}Õ)MØ—9‘9×#Ñ#×(Ñ(¨KÓ7ØŸ9™9×+Ñ+Ò+ð ð r)   c                ó:   — | j                   }t        |t        «      S )zÊ
        Return `True` if the currently focused control is a
        :class:`.BufferControl`. (For instance, used to determine whether the
        default key bindings should be active or not.)
        )r;   r+   r   rW   s     r"   Úbuffer_has_focuszLayout.buffer_has_focus  s   € ð ×)Ñ)ˆ
Ü˜*¤mÓ4Ð4r)   c                ó†   — 	 | j                   d   j                  S # t        $ r | j                   d   j                  cY S w xY w)zJ
        Get the :class:`.UIControl` to previously had the focus.
        éþÿÿÿrG   )r   r/   Ú
IndexErrorr'   s    r"   Úprevious_controlzLayout.previous_control!  s>   € ð
	+Ø—;‘;˜r‘?×*Ñ*Ð*øÜò 	+Ø—;‘;˜r‘?×*Ñ*Ò*ð	+ús   ‚ ›"A ¿A c                ó^   — t        | j                  «      dkD  r| j                  dd | _        yy)z=
        Give the focus to the last focused control.
        r   NrG   )Úlenr   r'   s    r"   Ú
focus_lastzLayout.focus_last+  s,   € ô ˆt�{‰{Ó˜aÒØŸ+™+ c rÐ*ˆD�Kð  r)   c                óæ   — | j                  «       }t        |«      dkD  rB	 |j                  | j                  «      }|dz   t        |«      z  }| j                  ||   «       yy# t        $ r d}Y Œ#w xY w)z:
        Focus the next visible/focusable Window.
        r   r   N©rU   rc   Úindexr&   r9   r   ©r   r?   rg   s      r"   Ú
focus_nextzLayout.focus_next2  óv   € ð ×4Ñ4Ó6ˆäˆw‹<˜!Òð3ØŸ™ d×&9Ñ&9Ó:�ð  ™¤c¨'£lÑ2�à�J‰J�w˜u‘~Õ&ð øô ò Ø’ðúó    A" Á"A0Á/A0c                óæ   — | j                  «       }t        |«      dkD  rB	 |j                  | j                  «      }|dz
  t        |«      z  }| j                  ||   «       yy# t        $ r d}Y Œ#w xY w)z>
        Focus the previous visible/focusable Window.
        r   r   Nrf   rh   s      r"   Úfocus_previouszLayout.focus_previousB  rj   rk   c              #  óJ   K  — t        | j                  «      E d{  –—†  y7 Œ­w)zX
        Walk through all the layout nodes (and their children) and yield them.
        N)r   r   r'   s    r"   r   zLayout.walkR  s   è ø€ ô ˜Ÿ™Ó'×'Ò'ús   ‚#›!œ#c              #  óæ   K  — | j                   }|j                  «       s<|| j                  v r.| j                  |   }|j                  «       s|| j                  v rŒ.t        |«      E d{  –—†  y7 Œ­w)zn
        Walk through all the containers which are in the current 'modal' part
        of the layout.
        N)r&   Úis_modalr   r   )r   Úroots     r"   rR   zLayout.walk_through_modal_areaX  s`   è ø€ ð ×-Ñ-ˆØ—-‘-”/ d¨d×.CÑ.CÑ&CØ×(Ñ(¨Ñ.ˆDð —-‘-”/ d¨d×.CÑ.CÒ&Cô ˜“:×Òús   ‚AA1ÁA1Á)A/Á*A1c                óL   ‡‡— i Šdˆˆfd„Š ‰| j                   «       ‰| _        y)z=
        Update child->parent relationships mapping.
        c                óJ   •— | j                  «       D ]  }| ‰|<    ‰|«       Œ y r.   )Úget_children)r!   r@   Úparentsr   s     €€r"   r   z-Layout.update_parents_relations.<locals>.walkk  s$   ø€ Ø—^‘^Ö%�Ø�˜‘
Ù�Q•ñ &r)   N)r!   r
   ÚreturnÚNone)r   r   )r   ru   r   s    @@r"   Úupdate_parents_relationszLayout.update_parents_relationse  s%   ù€ ð ˆö	ñ
 	ˆT�^‰^Ôà 'ˆÕr)   c                ól   — | j                   j                  «        | j                  j                  «        y r.   )r   Úclearr   Úresetr'   s    r"   r{   zLayout.resett  s&   € ð
 	×Ñ×ÑÔ!à�‰×ÑÕr)   c                ó@   — 	 | j                   |   S # t        $ r Y yw xY w)zo
        Return the parent container for the given container, or ``None``, if it
        wasn't found.
        N)r   ÚKeyErrorr0   s     r"   Ú
get_parentzLayout.get_parent}  s*   € ð
	Ø×(Ñ(¨Ñ3Ð3øÜò 	Ùð	ús   ‚ ‘	œr.   )r   r   r    zFocusableElement | Nonerv   rw   )rv   r6   )rv   zGenerator[Window, None, None])rv   zIterable[UIControl])r=   ÚFocusableElementrv   rw   )r=   r   rv   Úbool)rv   r   )r>   r   rv   rw   )rv   r   )r=   r   rv   rw   )rv   r€   )rv   zBufferControl | None)rv   zIterable[Window])rv   zlist[Window])rv   úBuffer | None)rZ   r6   rv   r�   )rv   rw   )rv   úIterable[Container])r   r
   rv   zContainer | None)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r(   r   r1   r   rE   Úpropertyr;   Úsetterr&   rM   rP   rS   rU   rC   r[   r]   ra   rd   ri   rm   r   rR   rx   r{   r~   © r)   r"   r   r      sD  „ ñð 48ð 0àð 0ð 1ð 0ð 
ó	 0óDUóó$óLó\ð2 ò'ó ð'ð ×Ñò	Eó ð	Eð òó ðð ×Ñò"ó ð"ð ò9ó ð9ð òó ðóóQð òó ðó	ð ò5ó ð5ð ò+ó ð+ó+ó'ó 'ó (óó(óôr)   r   c                  ó   — e Zd Zy)r   N)rƒ   r„   r…   r‰   r)   r"   r   r   ˆ  s   „ Ør)   r   c              #  ó²   K  — |r!t        | t        «      r| j                  «       sy| –— | j                  «       D ]  }t	        ||¬«      E d{  –—†  Œ y7 Œ­w)z:
    Walk through layout, starting at this container.
    Nr4   )r+   r	   Úfilterrt   r   )r   r5   r@   s      r"   r   r   Œ  sP   è ø€ ñ 	Ü�yÔ"6Ô7Ø× Ñ Ô"àà
‚Oà×#Ñ#Ö%ˆä˜ {Ô3×3Ñ3ñ &à3ús   ‚AAÁAÁAN)F)r   r
   r5   r€   rv   r‚   )r†   Ú
__future__r   Úcollections.abcr   r   Úprompt_toolkit.bufferr   Ú
containersr   r	   r
   r   r   Úcontrolsr   r   r   Ú__all__r6   r   r   Ú	Exceptionr   r   r‰   r)   r"   Ú<module>r”      sc   ðñõ #ç /å (÷õ ÷ DÑ Cò€ð ˜‘< )Ñ+¨lÑ:Ð ÷hñ hôV	˜ô 	õ4r)   