403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/prompt_toolkit/layout/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/prompt_toolkit/layout/__pycache__/containers.cpython-311.pyc
�

�Ïc����dZddlmZmZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZddlmZddlmZddlmZdd	lmZmZmZmZdd
lmZmZm Z ddl!m"Z"m#Z#ddl$m%Z%dd
l&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8m9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z?m@Z@mAZAddlBmCZCe	rddlDmEZEmFZFddlGmHZHgd�ZIGd�de���ZJe	rGd�deE��ZKeeJdfZLdCd �ZMGd!�d"e��ZNGd#�d$e��ZOGd%�d&eJ��ZPGd'�d(eP��ZQGd)�d*eP��ZRGd+�d,eJ��ZSGd-�d.��ZTGd/�d0��ZUGd1�d2��ZVGd3�d4��ZWeezZXGd5�d6e��ZYGd7�deJ��ZZGd8�d9eJ��Z[Gd:�d;eJ��Z\d<eLdeJfd=�Z]d<eLdeZfd>�Z^d?e_dd@fdA�Z`dBS)Dza
Container for the layout.
(Containers can contain other containers or user interface controls.)
�)�ABCMeta�abstractmethod)�Enum)�partial)	�
TYPE_CHECKING�Callable�Dict�List�Optional�Sequence�Tuple�Union�cast)�get_app)�SimpleCache)�Point)�FilterOrBool�emacs_insert_mode�	to_filter�vi_insert_mode)�AnyFormattedText�StyleAndTextTuples�to_formatted_text)�fragment_list_to_text�fragment_list_width)�KeyBindingsBase)�
MouseEvent�MouseEventType)�
get_cwidth�take_using_weights�to_int�to_str�)�DummyControl�FormattedTextControl�GetLinePrefixCallable�	UIContent�	UIControl)�AnyDimension�	Dimension�max_layout_dimensions�sum_layout_dimensions�to_dimension)�Margin)�
MouseHandlers)�_CHAR_CACHE�Screen�
WritePosition)�explode_text_fragments)�Protocol�	TypeGuard)�NotImplementedOrNone)�AnyContainer�	Container�HorizontalAlign�
VerticalAlign�HSplit�VSplit�FloatContainer�Float�WindowAlign�Window�WindowRenderInfo�ConditionalContainer�
ScrollOffsets�ColorColumn�to_container�	to_window�is_container�DynamicContainerc��eZdZdZedd���Zededefd���Zedededefd	���Z	ed
e
deded
e
dedeeddfd���Zdefd�Zdeefd�Zededfd���ZdS)r8z/
    Base class for user interface layout.
    �returnNc��dS)zu
        Reset the state of this container and all the children.
        (E.g. reset scroll offsets, etc...)
        N���selfs �B/usr/lib/python3/dist-packages/prompt_toolkit/layout/containers.py�resetzContainer.reset^������max_available_widthc��dS)z�
        Return a :class:`~prompt_toolkit.layout.Dimension` that represents the
        desired width for this container.
        NrL�rNrSs  rO�preferred_widthzContainer.preferred_widtherQrR�width�max_available_heightc��dS)z�
        Return a :class:`~prompt_toolkit.layout.Dimension` that represents the
        desired height for this container.
        NrL�rNrWrXs   rO�preferred_heightzContainer.preferred_heightlrQrR�screen�mouse_handlers�write_position�parent_style�erase_bg�z_indexc��dS)a=
        Write the actual content to the screen.

        :param screen: :class:`~prompt_toolkit.layout.screen.Screen`
        :param mouse_handlers: :class:`~prompt_toolkit.layout.mouse_handlers.MouseHandlers`.
        :param parent_style: Style string to pass to the :class:`.Window`
            object. This will be applied to all content of the windows.
            :class:`.VSplit` and :class:`.HSplit` can use it to pass their
            style down to the windows that they contain.
        :param z_index: Used for propagating z_index from parent to child.
        NrL�rNr\r]r^r_r`ras       rO�write_to_screenzContainer.write_to_screensrQrRc��dS)z�
        When this container is modal, key bindings from parent containers are
        not taken into account if a user control in this container is focused.
        FrLrMs rO�is_modalzContainer.is_modal�s	��
�urRc��dS)z�
        Returns a :class:`.KeyBindings` object. These bindings become active when any
        user control in this container has the focus, except if any containers
        between this container and the focused user control is modal.
        NrLrMs rO�get_key_bindingszContainer.get_key_bindings�s	���trRc��gS)zG
        Return the list of child :class:`.Container` objects.
        rLrMs rO�get_childrenzContainer.get_children�s	��
�	rR�rJN)�__name__�
__module__�__qualname__�__doc__rrP�intr*rVr[r1r/r2�str�boolrrdrfrrhr
rjrLrRrOr8r8Ysp�������������^����3��9�����^����c���������^������&��&�	�
���
��#���
�����^��*�$������(�?�";�������d�;�/�����^���rRr8)�	metaclassc��eZdZdZdd�ZdS)�MagicContainerzY
        Any object that implements ``__pt_container__`` represents a container.
        rJr7c��dS�NrLrMs rO�__pt_container__zMagicContainer.__pt_container__�s���CrRN)rJr7)rlrmrnrorxrLrRrOruru�s2������	�	�	�	�	�	�	�	rRrurJr@c�>�ttdg�����S)z<Create a `Window` that displays the 'Window too small' text.)zclass:window-too-smallz Window too small... )�text)r@r%rLrRrO�_window_too_smallr{�s&����#V�"W�X�X�X���rRc�"�eZdZdZdZdZdZdZdS)r:zAlignment for `HSplit`.�TOP�CENTER�BOTTOM�JUSTIFYN)rlrmrnror}r~rr�rLrRrOr:r:�s(��������
�C�
�F�
�F��G�G�GrRr:c�"�eZdZdZdZdZdZdZdS)r9zAlignment for `VSplit`.�LEFTr~�RIGHTr�N)rlrmrnror�r~r�r�rLrRrOr9r9�s(���������D�
�F��E��G�G�GrRr9c��eZdZdZdejd��ddddddddf
deedee	de
d	eed
ede
de
d
eede
deedeeegeffddfd�Zde
fd�Zdeefd�Zdee	fd�ZdS)�_Splitz4
    The common parts of `VSplit` and `HSplit`.
    Nr�F�children�window_too_small�padding�padding_char�
padding_stylerW�heightra�modal�key_bindings�stylerJc���d�|D��|_|p
t��|_||_||_||_||_||_||_|	|_	|
|_
||_dS)Nc�,�g|]}t|����SrL)rE)�.0�cs  rO�
<listcomp>z#_Split.__init__.<locals>.<listcomp>�s��;�;�;�Q��a���;�;�;rR)r�r{r�r�r�r�rWr�rar�r�r�)rNr�r�r�r�r�rWr�rar�r�r�s            rO�__init__z_Split.__init__�ss��<�;�(�;�;�;��
� 0� G�4E�4G�4G������(���*�����
���������
�(�����
�
�
rRc��|jSrw�r�rMs rOrfz_Split.is_modal��
���z�rRc��|jSrw�r�rMs rOrhz_Split.get_key_bindings����� � rRc��|jSrw)r�rMs rOrjz_Split.get_children�s
���}�rR)rlrmrnror*�exactrr7rr8r)rqrprrrrrr�rfrhr
rjrLrRrOr�r��s]��������15� /�	��� 2� 2�&*��"�#�!%��26�/1����<�(��#�9�-���	�
�s�m���
������#�������/���S�(�2�s�7�+�+�,��
�����:�$�����!�(�?�";�!�!�!�!��d�9�o������rRr�c���eZdZdZdejdddddddddfdeedee	ded	e
d
eedede
d
e
deede
deedeeegeffddf�fd�
Zdedefd�Zdededefd�Zd!d�Zedee	fd���Zdedededede
deeddfd�Zdedeeefd �Z�xZS)"r;a�
    Several layouts, one stacked above/under the other. ::

        +--------------------+
        |                    |
        +--------------------+
        |                    |
        +--------------------+

    By default, this doesn't display a horizontal line between the children,
    but if this is something you need, then create a HSplit as follows::

        HSplit(children=[ ... ], padding_char='-',
               padding=1, padding_style='#ffff00')

    :param children: List of child :class:`.Container` objects.
    :param window_too_small: A :class:`.Container` object that is displayed if
        there is not enough space for all the children. By default, this is a
        "Window too small" message.
    :param align: `VerticalAlign` value.
    :param width: When given, use this width instead of looking at the children.
    :param height: When given, use this height instead of looking at the children.
    :param z_index: (int or None) When specified, this can be used to bring
        element in front of floating elements.  `None` means: inherit from parent.
    :param style: A style string.
    :param modal: ``True`` or ``False``.
    :param key_bindings: ``None`` or a :class:`.KeyBindings` object.

    :param padding: (`Dimension` or int), size to be used for the padding.
    :param padding_char: Character to be used for filling in the padding.
    :param padding_style: Style to applied to the padding.
    Nrr�Fr�r��alignr�r�r�rWr�rar�r�r�rJc

���t���||||||||	|
||���||_td���|_t��|_dS�N)r�r�r�r�r�rWr�rar�r�r�r#��maxsize��superr�r�r�_children_cacher@�_remaining_space_window�rNr�r�r�r�r�r�rWr�rar�r�r��	__class__s             �rOr�zHSplit.__init__�|��� 	������-��%�'�����%��	�	
�	
�	
���
�
��"�"�"�	
��(.�x�x��$�$�$rRrSc���|j�t|j��S|jr"�fd�|jD��}t|��St	��S)Nc�:��g|]}|������SrL�rV�r�r�rSs  �rOr�z*HSplit.preferred_width.<locals>.<listcomp>=s(���X�X�X�Q�!�+�+�,?�@�@�X�X�XrR)rWr-r�r+r*�rNrS�
dimensionss ` rOrVzHSplit.preferred_width8sX����:�!���
�+�+�+��=�	�X�X�X�X�$�-�X�X�X�J�(��4�4�4��;�;�rRrXc����|j�t|j��S��fd�|jD��}t|��S)Nc�<��g|]}|�������SrL�r[)r�r�rXrWs  ��rOr�z+HSplit.preferred_height.<locals>.<listcomp>Fs7���
�
�
�@A�A���u�&:�;�;�
�
�
rR)r�r-�
_all_childrenr,)rNrWrXr�s `` rOr[zHSplit.preferred_heightBs\�����;�"����,�,�,�
�
�
�
�
�EI�EW�
�
�
�
�%�Z�0�0�0rRc�B�|jD]}|����dSrw�r�rP�rNr�s  rOrPzHSplit.resetK�,����	�	�A�
�G�G�I�I�I�I�	�	rRc���dttf�fd�}�j�t	�j��|��S)�;
        List of child objects, including padding.
        rJc���g}�jtjtjfvr1|�tt
d���������jD]K}|�|��|�t�j�j	�j
������L|r|����jtjtjfvr1|�tt
d��������|S)Nr��	preferred�rW)r��charr�)
r�r:r~r�appendr@r*r�r�r�r��popr}��result�childrNs  �rO�getz!HSplit._all_children.<locals>.getUs���&(�F��z�m�2�M�4H�I�I�I��
�
�f�9�q�+A�+A�+A�B�B�B�C�C�C���
�
���
�
�e�$�$�$��
�
��#�|�!�.�"�0���������
��
�
�����z�m�2�M�4E�F�F�F��
�
�f�9�q�+A�+A�+A�B�B�B�C�C�C��MrR�r
r8r�r��tupler��rNr�s` rOr�zHSplit._all_childrenO�Q���	�T�)�_�	�	�	�	�	�	�4�#�'�'��d�m�(<�(<�c�B�B�BrRr\r]r^r_r`c��|�|��}|dzt|j��z}|j�|n|j}|�!|j�||||||��dS|j}	|j}
|j}t||j
��D]4\}}
|
�||t|
|	||��|||��|	|z
}	�5|j|jz|	z
}|dkr1|j
�||t|
|	||��|||��dSdS)��
        Render the prompt to a `Screen` instance.

        :param screen: The :class:`~prompt_toolkit.layout.screen.Screen` class
            to which the output has to be written.
        � Nr)�_divide_heightsr"r�rar�rd�ypos�xposrW�zipr�r2r�r�)rNr\r]r^r_r`ra�sizesr�r�r�rW�sr��remaining_heights               rOrdzHSplit.write_to_screenqsk���$�$�^�4�4���s�"�V�D�J�%7�%7�7��!�\�1�'�'�t�|���=��!�1�1�����x��
�
�
�
�
�
"�&�D�!�&�D�"�(�E��E�4�#5�6�6�	
�	
���1��!�!��"�!�$��e�Q�7�7����
�����	��� .�2�^�5J�J�T�Q���!�#�#��,�<�<��"�!�$��e�5E�F�F����
�����$�#rRc	�X���|jsgS|j�|j���fd�|jD��}t	|��}|j�krdSd�|D��}t
ttt|������d�|D�����}t|��}t�|j��}d�|D��}t|��|krD||||kr||xxdz
cc<t|��}t|��|k�Dt��jsxt�|j��}	d�|D��}
t|��|	krD|||
|kr||xxdz
cc<t|��}t|��|	k�D|S)	zb
        Return the heights for all rows.
        Or None when there is not enough space.
        c�<��g|]}|�������SrLr�)r�r�r�rWs  ��rOr�z*HSplit._divide_heights.<locals>.<listcomp>�s)���T�T�T�A�a�(�(���7�7�T�T�TrRNc��g|]	}|j��
SrL��min�r��ds  rOr�z*HSplit._divide_heights.<locals>.<listcomp>����+�+�+�1���+�+�+rRc��g|]	}|j��
SrL��weightr�s  rOr�z*HSplit._divide_heights.<locals>.<listcomp>����8V�8V�8V�a���8V�8V�8VrR��items�weightsc��g|]	}|j��
SrLr�r�s  rOr�z*HSplit._divide_heights.<locals>.<listcomp>����@�@�@����@�@�@rRr#c��g|]	}|j��
SrL��maxr�s  rOr�z*HSplit._divide_heights.<locals>.<listcomp>�s��8�8�8��a�e�8�8�8rR)r�rWr�r�r,r�r �list�range�len�nextr��sumr�is_doner�)
rNr^r��sum_dimensionsr��child_generator�i�preferred_stop�preferred_dimensions�max_stop�max_dimensionsr�rWs
           @@rOr�zHSplit._divide_heights�s�����
�}�	��I��$���&��U�T�T�T�T��AS�T�T�T�
�/�z�:�:�����&�&��4�,�+�
�+�+�+��,��u�S��_�_�-�-�.�.�8V�8V�:�8V�8V�8V�
�
�
��
��!�!���V�^�%=�>�>��@�@�Z�@�@�@���%�j�j�>�)�)��Q�x�.�q�1�1�1��a����A�
�����_�%�%�A��%�j�j�>�)�)��y�y� �	*��6�>�#5�6�6�H�8�8�Z�8�8�8�N��e�*�*�x�'�'���8�n�Q�/�/�/��!�H�H�H��M�H�H�H���)�)���e�*�*�x�'�'�
�rRrk)rlrmrnror:r�rr7rr8r)rqrprrrrrr�r*rVr[rP�propertyr
r�r1r/r2rdr��
__classcell__�r�s@rOr;r;�s6���������H15�,�4� !�&*��"�#�!%��26�/1�#0�#0��<�(�#0�#�9�-�#0��	#0�
�#0��s�m�
#0��#0��#0��#0��#��#0��#0���/�#0��S�(�2�s�7�+�+�,�#0�
�#0�#0�#0�#0�#0�#0�J�3��9�����1�c�1��1��1�1�1�1������C�t�I��C�C�C��X�C�B7��7�&�7�&�	7�
�7��
7��#��7�
�7�7�7�7�r3�m�3���c��@S�3�3�3�3�3�3�3�3rRr;c���eZdZdZdejdddddddddfdeedee	ded	e
d
eedede
d
e
deede
deedeeegeffddf�fd�
Zdedefd�Zdededefd�Zd!d�Zedee	fd���Zdedeeefd�Zdedededede
deeddfd �Z�xZS)"r<a�
    Several layouts, one stacked left/right of the other. ::

        +---------+----------+
        |         |          |
        |         |          |
        +---------+----------+

    By default, this doesn't display a vertical line between the children, but
    if this is something you need, then create a HSplit as follows::

        VSplit(children=[ ... ], padding_char='|',
               padding=1, padding_style='#ffff00')

    :param children: List of child :class:`.Container` objects.
    :param window_too_small: A :class:`.Container` object that is displayed if
        there is not enough space for all the children. By default, this is a
        "Window too small" message.
    :param align: `HorizontalAlign` value.
    :param width: When given, use this width instead of looking at the children.
    :param height: When given, use this height instead of looking at the children.
    :param z_index: (int or None) When specified, this can be used to bring
        element in front of floating elements.  `None` means: inherit from parent.
    :param style: A style string.
    :param modal: ``True`` or ``False``.
    :param key_bindings: ``None`` or a :class:`.KeyBindings` object.

    :param padding: (`Dimension` or int), size to be used for the padding.
    :param padding_char: Character to be used for filling in the padding.
    :param padding_style: Style to applied to the padding.
    Nrr�Fr�r�r�r�r�r�rWr�rar�r�r�rJc

���t���||||||||	|
||���||_td���|_t��|_dSr�r�r�s             �rOr�zVSplit.__init__r�rRrSc�~��|j�t|j��S�fd�|jD��}t|��S)Nc�:��g|]}|������SrLr�r�s  �rOr�z*VSplit.preferred_width.<locals>.<listcomp>*s5���
�
�
�78�A���1�2�2�
�
�
rR)rWr-r�r,r�s ` rOrVzVSplit.preferred_width&sV����:�!���
�+�+�+�
�
�
�
�<@�<N�
�
�
�
�%�Z�0�0�0rRrXc����|j�t|j��S|�|��}|j}|�t	��S�fd�t||��D��}t
|��S)Nc�B��g|]\}}|�|�����SrLr�)r�r�r�rXs   �rOr�z+VSplit.preferred_height.<locals>.<listcomp>Bs>�������A�q��"�"�1�&:�;�;���rR)r�r-�_divide_widthsr�r*r�r+)rNrWrXr�r�r�s  `   rOr[zVSplit.preferred_height0s�����;�"����,�,�,��#�#�E�*�*���%���=��;�;��������x�0�0����J�)��4�4�4rRc�B�|jD]}|����dSrwr�r�s  rOrPzVSplit.resetHr�rRc���dttf�fd�}�j�t	�j��|��S)r�rJc���g}�jtjtjfvr1|�tt
d���������jD]K}|�|��|�t�j�j	�j
������L|r|����jtjtjfvr1|�tt
d��������|S)Nrr�r�)rWr�r�)
r�r9r~r�r�r@r*r�r�r�r�r�r�r�s  �rOr�z!VSplit._all_children.<locals>.getRs���&(�F��z�o�4�o�6K�L�L�L��
�
�f�9�q�+A�+A�+A�B�B�B�C�C�C���
�
���
�
�e�$�$�$��
�
��"�l�!�.�"�0���������
��
�
�����z�o�4�o�6J�K�K�K��
�
�f�9�q�+A�+A�+A�B�B�B�C�C�C��MrRr�r�s` rOr�zVSplit._all_childrenLr�rRc	���|j}|sgS�fd�|D��}d�|D��}t|��}|j�krdSd�|D��}tt	tt
|������d�|D�����}t|��}t�|j��}	t|��|	krD||||kr||xxdz
cc<t|��}t|��|	k�Dd�|D��}
t�|j
��}t|��|krD|||
|kr||xxdz
cc<t|��}t|��|k�D|S)	zd
        Return the widths for all columns.
        Or None when there is not enough space.
        c�:��g|]}|������SrLr�)r�r�rWs  �rOr�z)VSplit._divide_widths.<locals>.<listcomp>ys'���A�A�A�1�a�'�'��.�.�A�A�ArRc��g|]	}|j��
SrLr�r�s  rOr�z)VSplit._divide_widths.<locals>.<listcomp>zr�rRNc��g|]	}|j��
SrLr�r�s  rOr�z)VSplit._divide_widths.<locals>.<listcomp>�r�rRc��g|]	}|j��
SrLr�r�s  rOr�z)VSplit._divide_widths.<locals>.<listcomp>�r�rRr�r#c��g|]	}|j��
SrLr�r�s  rOr�z)VSplit._divide_widths.<locals>.<listcomp>�s��4�4�4�A�!�%�4�4�4rR)r�r,r�r r�r�r�r�r�r�r�)rNrWr�r�r�r�r�r�r�r�r�r�s `          rOr�zVSplit._divide_widthsns����
�%���	��I�B�A�A�A��A�A�A�
�@�@�Z�@�@�@��/�z�:�:�����%�%��4�,�+�
�+�+�+��,��u�S��_�_�-�-�.�.�8V�8V�:�8V�8V�8V�
�
�
��
��!�!���U�N�$<�=�=���%�j�j�>�)�)��Q�x�.�q�1�1�1��a����A�
�����_�%�%�A��%�j�j�>�)�)�5�4��4�4�4���u�n�0�1�1���%�j�j�8�#�#��Q�x�.��+�+�+��a����A�
�����_�%�%�A��%�j�j�8�#�#�
�rRr\r]r^r_r`c����|jsdS|j}|��j��}|dzt	|j��z}	|j�|n|j}|�!|j�||�|	||��dS�fd�t||��D��}
t�jt�jt|
������}�j
}�j}
t||��D]4\}}|�||t|
|||��|	||��|
|z
}
�5�j�jz|
z
}|dkr1|j�||t|
|||��|	||��dSdS)r�Nr�c�V��g|]%\}}|�|�j��j��&SrL)r[r�r�)r�rWr�r^s   �rOr�z*VSplit.write_to_screen.<locals>.<listcomp>�sC���
�
�
���u�
�"�"�5�.�*?�@�@�J�
�
�
rRr)r�r�r�rWr"r�rar�rdr�r�r�r�r�r�r2r�)rNr\r]r^r_r`rar�r�r��heightsr�r�r�r�r��remaining_widths   `             rOrdzVSplit.write_to_screen�s�����}�	��F��%���#�#�N�$8�9�9���s�"�V�D�J�%7�%7�7��!�\�1�'�'�t�|���=��!�1�1�����x��
�
�
�
�F�
�
�
�
� #�E�8� 4� 4�
�
�
���^�*�C��0E�s�7�|�|�,T�,T�U�U���"���"����x�(�(�		�		�D�A�q�
������d�D�!�V�4�4����

�
�
�
�A�I�D�D�)�-��0D�D�t�K���Q����(�8�8����d�D�/�6�B�B����

�
�
�
�
��rRrk)rlrmrnror9r�rr7rr8r)rqrprrrrrr�r*rVr[rPr�r
r�r�r1r/r2rdr�r�s@rOr<r<�sE���������F15�!0�!8� !�&*��"�#�!%��26�/1�#0�#0��<�(�#0�#�9�-�#0��	#0�
�#0��s�m�
#0��#0��#0��#0��#��#0��#0���/�#0��S�(�2�s�7�+�+�,�#0�
�#0�#0�#0�#0�#0�#0�J1�3�1�9�1�1�1�1�5�c�5��5��5�5�5�5�0�����C�t�I��C�C�C��X�C�B1�C�1�H�T�#�Y�,?�1�1�1�1�fD��D�&�D�&�	D�
�D��
D��#��D�
�D�D�D�D�D�D�D�DrRr<c�d�eZdZdZ				d dededded	eed
e	e
ege
ffdeeddfd
�Z
d!d�Zdedefd�Zdededefd�Zdededede
dedeeddfd�Zdddededed
e
dedeeddfd�Zdededefd�Zdefd�Zdeefd�Zdeefd�ZdS)"r=a�
    Container which can contain another container for the background, as well
    as a list of floating containers on top of it.

    Example Usage::

        FloatContainer(content=Window(...),
                       floats=[
                           Float(xcursor=True,
                                ycursor=True,
                                content=CompletionsMenu(...))
                       ])

    :param z_index: (int or None) When specified, this can be used to bring
        element in front of floating elements.  `None` means: inherit from parent.
        This is the z_index for the whole `Float` container as a whole.
    FNr��content�floatsr>r�r�r�rarJc�t�t|��|_||_||_||_||_||_dSrw)rEr
rr�r�r�ra)rNr
rr�r�r�ras       rOr�zFloatContainer.__init__�s;��$�G�,�,��������
�(�����
�����rRc�~�|j���|jD]}|j����dSrw)r
rPr)rN�fs  rOrPzFloatContainer.reset
sF�����������	�	�A�
�I�O�O�����	�	rRrSc�6�|j�|��Srw)r
rVrUs  rOrVzFloatContainer.preferred_widths���|�+�+�,?�@�@�@rRrWrXc�8�|j�||��S)z�
        Return the preferred height of the float container.
        (We don't care about the height of the floats, they should always fit
        into the dimensions provided by the container.)
        )r
r[rZs   rOr[zFloatContainer.preferred_heights���|�,�,�U�4H�I�I�IrRr\r]r^r_r`c���|dzt|j��z}|j�|n|j}|j�||||||��t|j��D]�\}}	|pd|	jz}
|dzt|j��z}|	jdup|	jdu}|r6|dz}
|�	|
t|j|	||||||
������u|�|	||||||
����dS)Nr�ri��ra�	draw_func)r"r�rar
rd�	enumerater�xcursor�ycursor�draw_with_z_indexr�_draw_float)rNr\r]r^r_r`rar��number�fl�new_z_index�postpones            rOrdzFloatContainer.write_to_screens[���s�"�V�D�J�%7�%7�7��!�\�1�'�'�t�|����$�$��N�N�E�8�W�	
�	
�	
�$�D�K�0�0�'	�'	�J�F�B�#�<�a�2�:�5�K� �3�&���
�);�);�;�E��z��-�G���4�1G�H��
��U�N���(�(�'�%��(���&�&�� �#�	�	�)������ � ���"�"��������?'	�'	rRrc��|�|jpt��jj��}t|j|jz
|j|j	z
���}	|�
��}
|���}|j�
|
�|j}|
}
�nz|j�'|j
� |j}|j|jz
|j
z
}
�nL|
�|j
�|j|j
z
|
z
}|
}
�n-|jrl|
�:|j�|j��j}
t'|j|
��}
n|
}
|	j}||
z|jkrt)d|j|
z
��}n�|
rt+|j|
z
dz��}|
}
n�|j�|j��j}
|j�|j}nP|j
�!t)d|j|
z
|j
z
��}n(t)dt+|j|
z
dz����}t'|
|j|z
��}
|j�
|�|j}|}�n�|j�'|j� |j}|j|jz
|jz
}�nh|�|j�|j|z
|jz
}|}�nI|jr�|	j|jrdndz}|�&|j�|
|j��j}n|}||j|z
kr;|j|z
dz|kr|j|z
}n�t'||	j��}|	j|z
}n�|rt+|j|z
dz��}|}n�|j�|
|j��j}|j�|j}nP|j�!t)d|j|z
|jz
��}n(t)dt+|j|z
dz����}t'||j|z
��}|dkr{|
dkrwt9||jz||j	z|
|���}|jr|�||��r9|j�|||||� ��|���dSdSdSdS)zDraw a single Float.��x�yNr�r#�r�r�rWr�)r`ra)!�get_menu_position�attach_to_windowr�layout�current_windowrr"r�r#r��	get_width�
get_height�left�rightrWrr
rVr�r�r�rp�top�bottomr�r�allow_cover_cursorr[r2�hide_when_covering_content�_area_is_emptyrd�transparent)rNrr\r]r^r�r`ra�cpos�cursor_position�fl_width�	fl_heightr�rWr�r��wps                 rOrzFloatContainer._draw_floatWs��� �'�'���B�7�9�9�#3�#B�
�
�� ��f�~�*�*�d�f�~�7J�.J�
�
�
���<�<�>�>���M�M�O�O�	��7��8�#7��7�D��E�E�
�W�
 �R�X�%9��7�D�"�(�2�7�2�R�X�=�E�E�
�
!�b�h�&:�!�'�"�(�2�X�=�D��E�E�
�Z�	<����
�2�2�>�3G�H�H�R���N�0�%�8�8��� ��"�$�D��e�|�n�2�2�2��1�n�2�U�:�;�;���
�	<���,�x�7�1�<�=�=�D��E�E��J�.�.�~�/C�D�D�N�E��w�"��w�����%��1�n�2�U�:�R�X�E�F�F����1�c�>�#7�%�#?�1�"D�E�E�F�F����~�3�d�:�;�;�E��6��)�"7��6�D��F�F�
�V�
�B�I�$9��6�D�#�*�R�V�3�b�i�?�F�F�
�
"�r�y�'<�!�(�9�4�r�y�@�D��F�F�
�Z�&	?�"�$�R�-B�(I����J�D�� ���4�4��>�0������#����-��4�4�4�!�(�4�/�!�3�t�;�;�,�2�T�9�F�F�!���):�;�;�F�*�,�v�5�D���	?���-�	�9�Q�>�?�?�D��F�F��Z�0�0���8M�N�N�X�F��v�!��v�����&��1�n�3�f�<�r�y�H�I�I����1�c�>�#8�6�#A�Q�"F�G�G�H�H�����!6��!=�>�>�F��A�:�:�%�!�)�)���N�/�/��N�/�/���	���B��0�
�D�4G�4G��PR�4S�4S�
��
�*�*��"���!#���!1�!1�1�#�
+�������:�)�)�
�
rRc��|}t|j|j|jz��D]T}||jvrI|j|}t|j|j|jz��D]}||}|jdkrdS��UdS)z�
        Return True when the area below the write position is still empty.
        (For floats that should not hide content underneath.)
        r�FT)r�r�r��data_bufferr�rWr�)rNr\r^r8r#�rowr"r�s        rOr2zFloatContainer._area_is_empty�s���
���r�w���"�)� 3�4�4�	%�	%�A��F�&�&�&��(��+���r�w���"�(�(:�;�;�%�%�A��A��A��v��}�}�$�u�u�u�%���trRc��|jSrwr�rMs rOrfzFloatContainer.is_modal�r�rRc��|jSrwr�rMs rOrhzFloatContainer.get_key_bindings�r�rRc�^�|jg}|�d�|jD����|S)Nc3�$K�|]}|jV��dSrw�r
)r�rs  rO�	<genexpr>z.FloatContainer.get_children.<locals>.<genexpr>s$����7�7�a��	�7�7�7�7�7�7rR)r
�extendr)rNr�s  rOrjzFloatContainer.get_children�s3���L�>�����7�7�4�;�7�7�7�7�7�7��rR)FNr�Nrk)rlrmrnror7r
rrrrrrqrrpr�rPr*rVr[r1r/r2rdrr2rfrhr8rjrLrRrOr=r=�sh��������,�26�/1�!%������W�
���	�
��/���S�(�2�s�7�+�+�,�
��#���
�����$����A�3�A�9�A�A�A�A�J�c�J��J��J�J�J�J�7��7�&�7�&�	7�
�7��
7��#��7�
�7�7�7�7�rN��N��N�&�	N�
&�N��
N��N��#��N�
�N�N�N�N�`�V��]��t�����$�$�����!�(�?�";�!�!�!�!��d�9�o������rRr=c�B�eZdZdZ													ddedeedeedeed	eed
eeeegeffdeeeegeffde	d
e	deede	de	dede	ddfd�Z
deefd�Zdeefd�Zde
fd�ZdS)r>a�
    Float for use in a :class:`.FloatContainer`.
    Except for the `content` parameter, all other options are optional.

    :param content: :class:`.Container` instance.

    :param width: :class:`.Dimension` or callable which returns a :class:`.Dimension`.
    :param height: :class:`.Dimension` or callable which returns a :class:`.Dimension`.

    :param left: Distance to the left edge of the :class:`.FloatContainer`.
    :param right: Distance to the right edge of the :class:`.FloatContainer`.
    :param top: Distance to the top of the :class:`.FloatContainer`.
    :param bottom: Distance to the bottom of the :class:`.FloatContainer`.

    :param attach_to_window: Attach to the cursor from this window, instead of
        the current window.
    :param hide_when_covering_content: Hide the float when it covers content underneath.
    :param allow_cover_cursor: When `False`, make sure to display the float
        below the cursor. Not on top of the indicated position.
    :param z_index: Z-index position. For a Float, this needs to be at least
        one. It is relative to the z_index of the parent container.
    :param transparent: :class:`.Filter` indicating whether this float needs to be
        drawn transparently.
    NFr#r
r.r-r/r,rWr�rrr'r1r0rar3rJc�0�|
dksJ�||_||_||_||_||_||_||_|	|_|
rt|
��nd|_	t|��|_||_||_
|
|_t|��|_dS)Nr#)r,r-r.r/rWr�rrrFr'rEr
r1r0rarr3)rNr
r.r-r/r,rWr�rrr'r1r0rar3s               rOr�zFloat.__init__s���$�!�|�|�|�|���	���
���������
����������,<�E�I�&�'�'�'��	
��$�G�,�,���*D��'�"4������$�[�1�1����rRc�`�t|j��r|���S|jSrw)�callablerWrMs rOr*zFloat.get_widthHs*���D�J���	 ��:�:�<�<���z�rRc�`�t|j��r|���S|jSrw)rFr�rMs rOr+zFloat.get_heightMs*���D�K� � �	!��;�;�=�=� ��{�rRc��d|jzS)NzFloat(content=%r)r@rMs rO�__repr__zFloat.__repr__Rs��"�T�\�1�1rR)
NNNNNNFFNFFr#F)rlrmrnror7rrprrrrr�r*r+rqrIrLrRrOr>r>s���������8"�#� $�"�9=�:>���37�+0�#(��!�'2�'2��'2��c�]�'2���}�	'2�
��
�'2��s�m�
'2���c�8�B��G�#4�4�5�6�'2���s�H�R��W�$5�5�6�7�'2��'2��'2�#�<�0�'2�%)�'2�!�'2��'2��'2� 
�!'2�'2�'2�'2�R�8�C�=�����
�H�S�M�����
2�#�2�2�2�2�2�2rRr>c�*�eZdZdZdddededededed	d
deeeeeffdeeeefeeeffd
edededdfd�Z	e
deeeffd���Ze
defd���Z
e
d%d���Ze
deefd���Ze
deeeffd���Zd&dedefd�Zd&dedefd�Z	d'dededefd�Ze
defd���Ze
defd���Ze
defd ���Ze
defd!���Ze
defd"���Zd#edefd$�ZdS)(rAa{
    Render information for the last render time of this control.
    It stores mapping information between the input buffers (in case of a
    :class:`~prompt_toolkit.layout.controls.BufferControl`) and the actual
    render position on the output screen.

    (Could be used for implementation of the Vi 'H' and 'L' key bindings as
    well as implementing mouse support.)

    :param ui_content: The original :class:`.UIContent` instance that contains
        the whole input, without clipping. (ui_content)
    :param horizontal_scroll: The horizontal scroll of the :class:`.Window` instance.
    :param vertical_scroll: The vertical scroll of the :class:`.Window` instance.
    :param window_width: The width of the window that displays the content,
        without the margins.
    :param window_height: The height of the window that displays the content.
    :param configured_scroll_offsets: The scroll offsets as configured for the
        :class:`Window` instance.
    :param visible_line_to_row_col: Mapping that maps the row numbers on the
        displayed screen (starting from zero for the first visible line) to
        (row, col) tuples pointing to the row and column of the :class:`.UIContent`.
    :param rowcol_to_yx: Mapping that maps (row, column) tuples representing
        coordinates of the :class:`UIContent` to (y, x) absolute coordinates at
        the rendered screen.
    �windowr@�
ui_content�horizontal_scroll�vertical_scroll�window_width�
window_height�configured_scroll_offsetsrC�visible_line_to_row_col�rowcol_to_yx�x_offset�y_offset�
wrap_linesrJNc
��||_||_||_||_||_||_||_||_|	|_|
|_	||_
dSrw)rKrLrNrOrPrQrRrV�
_rowcol_to_yx�	_x_offset�	_y_offset)
rNrKrLrMrNrOrPrQrRrSrTrUrVs
             rOr�zWindowRenderInfo.__init__qs[�� ���$���.���(���*���)B��&�'>��$�$���)���!���!����rRc�H�d�|j���D��S)Nc�&�i|]\}}||d��S)rrL)r��visible_line�rowcols   rO�
<dictcomp>z?WindowRenderInfo.visible_line_to_input_line.<locals>.<dictcomp>�s2��
�
�
�$��f�
�&��)�
�
�
rR)rRr�rMs rO�visible_line_to_input_linez+WindowRenderInfo.visible_line_to_input_line�s2��
�
�(,�(D�(J�(J�(L�(L�
�
�
�	
rRc���|jj}	|j|j|jf\}}t||jz
||jz
���S#t$rtdd���cYSwxYw)zy
        Return the cursor position coordinates, relative to the left/top corner
        of the rendered screen.
        r!r)	rLr5rXr#r"rrYrZ�KeyError)rNr4r#r"s    rOr5z WindowRenderInfo.cursor_position�s�����.��	E��%�d�f�d�f�n�5�D�A�q��1�t�~�-��T�^�1C�D�D�D�D���	#�	#�	#��1��?�?�?�"�"�"�	#���s�A�A)�(A)c�"�|jddkrd}n6|j|jjj}t||jj��}t|t|jj	|jdz
dz
|jj
��dd���S)a
        Return a :class:`.ScrollOffsets` instance that indicates the actual
        offset. This can be less than or equal to what's configured. E.g, when
        the cursor is completely at the top, the top offset will be zero rather
        than what's configured.
        r���r#)r.r/r,r-)�displayed_lines�input_line_to_visible_linerLr5r#r�rQr.rC�
line_countr/)rNr.r#s   rO�applied_scroll_offsetsz'WindowRenderInfo.applied_scroll_offsets�s������"�a�'�'��C�C��/���0O�0Q�R�A��a��7�;�<�<�C������*�T�-A�"�-E�E��I��.�5�����
�
�
�	
rRc�b�td�|j���D����S)z�
        List of all the visible rows. (Line numbers of the input buffer.)
        The last line may not be entirely visible.
        c3� K�|]	\}}|V��
dSrwrL)r�r;�cols   rOrAz3WindowRenderInfo.displayed_lines.<locals>.<genexpr>�s&����P�P�h�c�3�c�P�P�P�P�P�PrR)�sortedrR�valuesrMs rOrez WindowRenderInfo.displayed_lines�s0���P�P�$�*F�*M�*M�*O�*O�P�P�P�P�P�PrRc��i}|j���D](\}}||vrt|||��||<�#|||<�)|S)z�
        Return the dictionary mapping the line numbers of the input buffer to
        the lines of the screen. When a line spans several rows at the screen,
        the first row appears in the dictionary.
        )r`r�r�)rNr��k�vs    rOrfz+WindowRenderInfo.input_line_to_visible_line�s]��"$���3�9�9�;�;�	�	�D�A�q��F�{�{���q�	�1�-�-��q�	�	���q�	�	��
rRF�after_scroll_offsetc�N�|r|j|jjS|jdS)z~
        Return the line number (0 based) of the input document that corresponds
        with the first visible line.
        r)rerhr.)rNrqs  rO�first_visible_linez#WindowRenderInfo.first_visible_line�s.��
�	+��'��(C�(G�H�H��'��*�*rR�before_scroll_offsetc�T�|r|jd|jjz
S|jdS)zK
        Like `first_visible_line`, but for the last visible line.
        rd)rerhr/)rNrts  rO�last_visible_linez"WindowRenderInfo.last_visible_line�s3�� �	,��'��T�-H�-O�(O�P�P��'��+�+rRc��|�|��|�|��|�|��z
dzzS)zM
        Like `first_visible_line`, but for the center visible line.
        r$)rsrv)rNrtrqs   rO�center_visible_linez$WindowRenderInfo.center_visible_line�sS��
�#�#�$7�8�8��&�&�';�<�<��)�)�*=�>�>�?��	�
�	
rRc��|jjS)z6
        The full height of the user control.
        )rLrgrMs rO�content_heightzWindowRenderInfo.content_height�s��
��)�)rRc�R�|jdko|���|jkS)zU
        True when the full height is visible (There is no vertical scroll.)
        r)rNrvrzrMs rO�full_height_visiblez$WindowRenderInfo.full_height_visibles1��
� �A�%�
@��&�&�(�(�D�,?�?�	
rRc��|jdkS)z=
        True when the top of the buffer is visible.
        r)rNrMs rO�top_visiblezWindowRenderInfo.top_visible
s��
�#�q�(�(rRc�B�|���|jdz
kS)z@
        True when the bottom of the buffer is visible.
        r#)rvrzrMs rO�bottom_visiblezWindowRenderInfo.bottom_visibles#��
�%�%�'�'�4�+>��+B�B�BrRc�8�|jrdSd|jz|jzS)z{
        Vertical scroll as a percentage. (0 means: the top is visible,
        100 means: the bottom is visible.)
        �d)r�rNrzrMs rO�vertical_scroll_percentagez+WindowRenderInfo.vertical_scroll_percentages+����	E��3���-�-��1D�D�DrR�linenoc�j�|jr+|j�||j|jj��SdS)z|
        Return the height of the given line.
        (The height that it would take, if this line became visible.)
        r#)rVrL�get_height_for_linerOrK�get_line_prefix)rNr�s  rOr�z$WindowRenderInfo.get_height_for_line&s>��
�?�	��?�6�6���)�4�;�+F���
��1rR)rJrC�F)FF)rlrmrnror'rpr	r
rrr�r�r`rr5rhr
rerfrsrvrxrzr|r~r�r�r�rLrRrOrArAVs-��������4"��"��"��	"�
�"��
"��"�$3�"�"&�c�5��c��?�&:�!;�"��5��c��?�E�#�s�(�O�;�<�"��"��"��"�
�"�"�"�"�>�
�D��c��N�
�
�
��X�
��
E��
E�
E�
E��X�
E��
�
�
��X�
�6�Q��c��Q�Q�Q��X�Q���D��c��N�����X��+�+�d�+�s�+�+�+�+�,�,�d�,�s�,�,�,�,�OT�

�

�$(�

�GK�

�	�

�

�

�

��*��*�*�*��X�*��
�T�
�
�
��X�
��)�T�)�)�)��X�)��C��C�C�C��X�C��E�C�E�E�E��X�E�
�#�
�#�
�
�
�
�
�
rRrAc
�4�eZdZdZ				ddeeegeffdeeegeffdeeegeffdeeegeffddf
d	�Zedefd
���Z	edefd���Z
edefd���Zedefd
���Zde
fd�ZdS)rCz�
    Scroll offsets for the :class:`.Window` class.

    Note that left/right offsets only make sense if line wrapping is disabled.
    rr.r/r,r-rJNc�>�||_||_||_||_dSrw)�_top�_bottom�_left�_right)rNr.r/r,r-s     rOr�zScrollOffsets.__init__:s$����	������
�����rRc�*�t|j��Srw)r!r�rMs rOr.zScrollOffsets.topGs���d�i� � � rRc�*�t|j��Srw)r!r�rMs rOr/zScrollOffsets.bottomKs���d�l�#�#�#rRc�*�t|j��Srw)r!r�rMs rOr,zScrollOffsets.leftOs���d�j�!�!�!rRc�*�t|j��Srw)r!r�rMs rOr-zScrollOffsets.rightSs���d�k�"�"�"rRc�Z�d�|j|j|j|j��S)Nz;ScrollOffsets(top={!r}, bottom={!r}, left={!r}, right={!r}))�formatr�r�r�r�rMs rOrIzScrollOffsets.__repr__Ws.��L�S�S��I��L��J��K�	
�
�	
rR)rrrr)rlrmrnrorrprr�r�r.r/r,r-rqrIrLrRrOrCrC3sx��������./�01�./�/0���
�3���S��)�)�
*���c�8�B��G�,�,�-���C��"�c�'�*�*�+�	�
�S�(�2�s�7�+�+�,��
�
�����!�S�!�!�!��X�!��$��$�$�$��X�$��"�c�"�"�"��X�"��#�s�#�#�#��X�#�
�#�
�
�
�
�
�
rRrCc�(�eZdZdZddededdfd�ZdS)	rDz6
    Column for a :class:`.Window` to be colored.
    �class:color-column�positionr�rJNc�"�||_||_dSrw)r�r�)rNr�r�s   rOr�zColorColumn.__init__es�� ��
���
�
�
rR)r�)rlrmrnrorprqr�rLrRrOrDrD`sL������������S��D������rRrDc��eZdZdZdZdZdZdS)r?z�
    Alignment of the Window content.

    Note that this is different from `HorizontalAlign` and `VerticalAlign`,
    which are used for the alignment of the child containers in respectively
    `VSplit` and `HSplit`.
    r�r�r~N)rlrmrnror�r�r~rLrRrOr?r?ms)���������D��E�
�F�F�FrRr?c2��eZdZdZdddddddddddddddddddejdddfdeedededee	d	e
d
e
de
de
d
eeedeeedee
de
de
deedge	fdeedge	fde
de
de
dedeeegeeffdeeegeffdeeegeffdedeegeffdeeddf0d�Zdefd�ZdRd�Zd ede	fd!�Zde	fd"�Zd#e	defd$�Zde	d%e	defd&�Ze	dSd'eed(egee	fd)edefd*���Zde	de	defd+�Z deefd,�Z!d-e"d.e#d/e$d0ed1edee	ddfd2�Z%d-e"d.e#d/e$d0ed1eddfd3�Z&d4d4ddd4ddejdf	d5ed6e"d/e$d7e	de	d8e	d9e	ded:ed;e	ded<ededeee	e	ge'fde(e)e	e(e	e	ffe)e(e	e	fe(e	e	ffffd=�Z*d-e"d/e$d1eddfd>�Z+d6e"d/e$d0eddfd?�Z,d6e"ddfd@�Z-d6e"ddfdA�Z.d6e"dBe/dCe	dDe	de	de	ddfdE�Z0dFed6e"d/e$d7e	de	ddfdG�Z1d5ede	de	ddfdH�Z2d5ede	de	ddfdI�Z3d5ede	de	ddfdJ�Z4dKe5ddLfdM�Z6dRdN�Z7dRdO�Z8dee9fdP�Z:dee;fdQ�Z<dS)Tr@a^
    Container that holds a control.

    :param content: :class:`.UIControl` instance.
    :param width: :class:`.Dimension` instance or callable.
    :param height: :class:`.Dimension` instance or callable.
    :param z_index: When specified, this can be used to bring element in front
        of floating elements.
    :param dont_extend_width: When `True`, don't take up more width then the
                              preferred width reported by the control.
    :param dont_extend_height: When `True`, don't take up more width then the
                               preferred height reported by the control.
    :param ignore_content_width: A `bool` or :class:`.Filter` instance. Ignore
        the :class:`.UIContent` width when calculating the dimensions.
    :param ignore_content_height: A `bool` or :class:`.Filter` instance. Ignore
        the :class:`.UIContent` height when calculating the dimensions.
    :param left_margins: A list of :class:`.Margin` instance to be displayed on
        the left. For instance: :class:`~prompt_toolkit.layout.NumberedMargin`
        can be one of them in order to show line numbers.
    :param right_margins: Like `left_margins`, but on the other side.
    :param scroll_offsets: :class:`.ScrollOffsets` instance, representing the
        preferred amount of lines/columns to be always visible before/after the
        cursor. When both top and bottom are a very high number, the cursor
        will be centered vertically most of the time.
    :param allow_scroll_beyond_bottom: A `bool` or
        :class:`.Filter` instance. When True, allow scrolling so far, that the
        top part of the content is not visible anymore, while there is still
        empty space available at the bottom of the window. In the Vi editor for
        instance, this is possible. You will see tildes while the top part of
        the body is hidden.
    :param wrap_lines: A `bool` or :class:`.Filter` instance. When True, don't
        scroll horizontally, but wrap lines instead.
    :param get_vertical_scroll: Callable that takes this window
        instance as input and returns a preferred vertical scroll.
        (When this is `None`, the scroll is only determined by the last and
        current cursor position.)
    :param get_horizontal_scroll: Callable that takes this window
        instance as input and returns a preferred vertical scroll.
    :param always_hide_cursor: A `bool` or
        :class:`.Filter` instance. When True, never display the cursor, even
        when the user control specifies a cursor position.
    :param cursorline: A `bool` or :class:`.Filter` instance. When True,
        display a cursorline.
    :param cursorcolumn: A `bool` or :class:`.Filter` instance. When True,
        display a cursorcolumn.
    :param colorcolumns: A list of :class:`.ColorColumn` instances that
        describe the columns to be highlighted, or a callable that returns such
        a list.
    :param align: :class:`.WindowAlign` value or callable that returns an
        :class:`.WindowAlign` value. alignment of content.
    :param style: A style string. Style to be applied to all the cells in this
        window. (This can be a callable that returns a string.)
    :param char: (string) Character to be used for filling the background. This
        can also be a callable that returns a character.
    :param get_line_prefix: None or a callable that returns formatted text to
        be inserted before a line. It takes a line number (int) and a
        wrap_count and returns formatted text. This can be used for
        implementation of line continuations, things like Vim "breakindent" and
        so on.
    NFr�r
rWr�ra�dont_extend_width�dont_extend_height�ignore_content_width�ignore_content_height�left_margins�
right_margins�scroll_offsets�allow_scroll_beyond_bottomrV�get_vertical_scroll�get_horizontal_scroll�always_hide_cursor�
cursorline�cursorcolumn�colorcolumnsr�r�r�r�rJc���t|��|_t|��|_t|
��|_t|��|_t|��|_|p
t
��|_t|��|_t|��|_	t|��|_
t|��|_|	pg|_|
pg|_
|p
t��|_||_||_|pg|_||_||_||_||_||_||_||_t5d���|_t5d���|_|���dS)N�r�r#)rr�r�rVr�r�r$r
r�r�r�r�r�r�rCr�r�r�r�r�r�r�r�rWr�rar�_ui_content_cache�_margin_width_cacherP)rNr
rWr�rar�r�r�r�r�r�r�r�rVr�r�r�r�r�r�r�r�r�r�s                        rOr�zWindow.__init__�sn��:+4�4N�*O�*O��'�"+�,>�"?�"?���#�J�/�/���#�J�/�/���%�l�3�3����0�,�.�.���!*�+<�!=�!=���"+�,>�"?�"?���$-�.B�$C�$C��!�%.�/D�%E�%E��"�(�.�B���*�0�b���,�?�
�����#6�� �%:��"�(�.�B�����
���
���	�.�����
�������

��"�"�"�	
��JU��J
�J
�J
�� �	
�
�
�����rRc��d|jzS)NzWindow(content=%r)r@rMs rOrIzWindow.__repr__�s��#�d�l�2�2rRc�p�|j���d|_d|_d|_d|_dS)Nr)r
rPrNrM�vertical_scroll_2�render_inforMs rOrPzWindow.reset�sB��������� !���!"���
"#���8<����rR�marginc�����dtf�fd��dtf��fd�}�t��jf}�j�||��S)zb
        Return the width for this margin.
        (Calculate only once per render time.)
        rJc�2����dd���S)Nr�rWr�)�_get_ui_contentrMs�rO�get_ui_contentz0Window._get_margin_width.<locals>.get_ui_contents����'�'�a��'�:�:�:rRc�.�������Srw)r*)r�r�s��rOr*z+Window._get_margin_width.<locals>.get_widths����#�#�N�3�3�3rR)r'rpr�render_counterr�r�)rNr�r*�keyr�s``  @rO�_get_margin_widthzWindow._get_margin_width
s������	;�	�	;�	;�	;�	;�	;�	;�	4�3�	4�	4�	4�	4�	4�	4�	4��w�y�y�/�0���'�+�+�C��;�;�;rRc���t�fd��jD����t�fd��jD����zS)zN
        Calculate and return the width of the margin (left + right).
        c3�B�K�|]}��|��V��dSrw�r��r��mrNs  �rOrAz1Window._get_total_margin_width.<locals>.<genexpr> s1�����H�H��4�)�)�!�,�,�H�H�H�H�H�HrRc3�B�K�|]}��|��V��dSrwr�r�s  �rOrAz1Window._get_total_margin_width.<locals>.<genexpr> sJ�����O
�O
�*+�D�"�"�1�%�%�O
�O
�O
�O
�O
�O
rR)r�r�r�rMs`rO�_get_total_margin_widthzWindow._get_total_margin_widthsp����H�H�H�H�d�6G�H�H�H�H�H�3�O
�O
�O
�O
�/3�/A�O
�O
�O
�L
�L
�
�	
rRrSc����dttf��fd�}��t�j��|�������S)z@
        Calculate the preferred width for this window.
        rJc�������rdS����}�j��|z
��}|�||z
}|S)zYContent width: is only calculated if no exact width for the
            window was given.N)r�r�r
rV)�total_margin_widthrVrSrNs  ��rO�preferred_content_widthz7Window.preferred_width.<locals>.preferred_content_width)sm����(�(�*�*�
��t�"&�!=�!=�!?�!?��#�l�:�:�#�&8�8���O��*��#5�5��"�"rR��	dimension�
get_preferred�dont_extend)rrp�_merge_dimensionsr-rWr�)rNrSr�s`` rOrVzWindow.preferred_width$sp����
	#��#��	#�	#�	#�	#�	#�	#�	#�(�%�%�"�4�:�.�.�1��.�.�0�0�&�
�
�	
rRrXc�����dttf���fd�}��t�j��|�������S)zA
        Calculate the preferred height for this window.
        rJc��������rdS����}����}�j��|z
�|�j��S)z[Content height: is only calculated if no exact height for the
            window was given.N)r�r�rVr
r[r�)r�rVrXrNrWs  ���rO�preferred_content_heightz9Window.preferred_height.<locals>.preferred_content_heightHsn����)�)�+�+�
��t�!%�!=�!=�!?�!?�����*�*�J��<�0�0��*�*�$���$�	��
rRr�)rrpr�r-r�r�)rNrWrXr�s``` rOr[zWindow.preferred_heightCsv�����
	�(�3�-�	�	�	�	�	�	�	�	� �%�%�"�4�;�/�/�2��/�/�1�1�&�
�
�	
rRr�r�r�c�l�|p
t��}|jr|j}n
|��}|�8|jrt	||j��}|jrt||j��}|r|�t	|j|��}n|jr|jnd}|jr|jnd}t||||j���S)z�
        Take the Dimension from this `Window` class and the received preferred
        size from the `UIControl` and return a `Dimension` to report to the
        parent container.
        N)r�r�r�r�)r*�preferred_specifiedr��
max_specifiedr�r��
min_specifiedr�)r�r�r�r��max_�min_s      rOr�zWindow._merge_dimensions^s����,����	��(�	(�!�+�I�I�&�
���I�� ��&�
:��	�9�=�9�9�	��&�
:��	�9�=�9�9�	��	F�9�0��y�}�i�0�0�D�D�$-�$;�E�9�=�=��D� )� 7�A�y�}�}�T����$�)�I�<L�
�
�
�	
rRc�����dtf���fd�}t��j��f}�j�||��S)z0
        Create a `UIContent` instance.
        rJc�<���j������S)Nr�)r
�create_content)r�rNrWs���rO�get_contentz+Window._get_ui_content.<locals>.get_content�s����<�.�.�U�6�.�J�J�JrR)r'rr�r�r�)rNrWr�r�r�s```  rOr�zWindow._get_ui_content�sk�����
	K�Y�	K�	K�	K�	K�	K�	K�	K�	K��y�y�'���7���%�)�)�#�{�;�;�;rRc��t��}|jrdS|jjr|jjr|jjSdSdS)z1Return `False`, or the Digraph symbol to be used.�^�?N)r�
quoted_insert�vi_state�waiting_for_digraph�digraph_symbol1)rN�apps  rO�_get_digraph_charzWindow._get_digraph_char�sJ���i�i����	��3��<�+�	��|�+�
4��|�3�3��3��trRr\r]r^r_r`c�4�t|j|j|j|j���}|���r7t
|j|�|j��j��|_|�	��r=t
|j|�
|j|j��j��|_|j�|n|j}t|j
|||||��}|�|dkr|��dS|�||���dS)z�
        Write window to screen. This renders the user control, the margins and
        copies everything over to the absolute position at the given screen.
        r%Nrr)r2r�r�rWr�r�r�rVr�r�r[rar�_write_to_screen_at_indexr)rNr\r]r^r_r`rars        rOrdzWindow.write_to_screen�s;��"'��$��$� �&�!�(�	
�
�
���!�!�#�#�	�#&��$��$�$�^�%9�:�:�D�$�$�N� �
�"�"�$�$�	�$'��%��%�%�"�(�.�*?����	%�%�N�!�"�\�1�'�'�t�|����*������

�
�	��?�g��l�l��I�K�K�K�K�K�
�$�$�W�	�$�J�J�J�J�JrRc�t�������jdks�jdkrdS�fd��jD��}�fd��jD��}t	||z��}�j��j|z
�j��}	t|	t��sJ���	��}
��
|	�j|z
�j����|�|��t�j
��r��
��n�j
}��|	|�t	|���j|z
�j�j|
d�j����t'��jj�jk|�j���\���jt	|��z}�j}
t3�|	�j�j�j|z
�j�j��||
|
������_dt8dd	f����fd
�}|��jt	|��z�j�jz|z
�j�j�jz|���d}dt<d
t>dtf��fd�}tA�j|��D]5\}}|dkr*|||��}��!||�||��||z
}�6�jt	|��z
}tA�j|��D]/\}}|||��}��!||�||��||z
}�0��"|�|���|j#�<dS)Nrc�:��g|]}��|����SrLr�r�s  �rOr�z4Window._write_to_screen_at_index.<locals>.<listcomp>�s'���S�S�S�A�d�4�4�Q�7�7�S�S�SrRc�:��g|]}��|����SrLr�r�s  �rOr�z4Window._write_to_screen_at_index.<locals>.<listcomp>�s'���U�U�U�Q�t�5�5�a�8�8�U�U�UrRT)rV�highlight_linesr�r��	has_focusr�r�)rKrLrMrNrOrPrQrRrSrTrUrV�mouse_eventrJr6c�����	t��j���vrtSd�����D��}|jj}|jj}�jt�
��zdz
}t||��}|dkrs	|||f\}}�	j�tt||���|j|j|j�����}nd#t$$r|dz}YnwxYw|dk�s�	j�ttdd���|j|j|j�����}|tkr�	�|��}|S)z�
            Wrapper around the mouse_handler of the `UIControl` that turns
            screen coordinates into line coordinates.
            Returns `NotImplemented` if no UI invalidation should be done.
            c��i|]\}}||��	SrLrL)r�rorps   rOr_zKWindow._write_to_screen_at_index.<locals>.mouse_handler.<locals>.<dictcomp>5s��B�B�B�T�Q��A�q�B�B�BrRr#rr!)r��
event_type�button�	modifiers)rr(�walk_through_modal_area�NotImplementedr�r�r#r"r�r�r�r
�
mouse_handlerrrr�r�r�rb�_mouse_handler)r��yx_to_rowcolr#r"�max_yr;rkr�rSrNrRr^s        ����rOr�z7Window._write_to_screen_at_index.<locals>.mouse_handler)s�����7�9�9�+�C�C�E�E�E�E�%�%�C�B�\�-?�-?�-A�-A�B�B�B�L��$�&�A��$�&�A�#�'�#�.E�*F�*F�F��J�E��E�1�
�
�A��q�&�&��+�A�q�D�1�H�C��"�\�7�7�"�%*�S�C�%8�%8�%8�'2�'=�#.�#5�&1�&;�	�����F��� ������F�A�A�A������q�&�&�.��3�3��!&��a����#.�#9�*�1�"-�"7�	��������'�'��,�,�[�9�9���Ms�
C.�.D�?D)�x_min�x_max�y_min�y_max�handlerr�rWc���|��|�j��}t|���|dz�j��S)zRender margin. Return `Screen`.r#)�
create_marginr�r%r�)r�rW�	fragmentsr�r^s   ��rO�
render_marginz7Window._write_to_screen_at_index.<locals>.render_marginpsK�������U�N�<Q�R�R�I�(�	�2�2�A�A���	�>�0���
rR)$r�rWr�r�r�r
r��
isinstancer'rV�_scroll�_fill_bgrFr��
_copy_bodyrNrMr�r�rr(�current_controlr�r�r�rAr�r�r�set_mouse_handler_for_ranger.rpr��_copy_margin�_apply_style�"visible_windows_to_write_positions)rNr\r]r^r_r`�left_margin_widths�right_margin_widthsr�rLrVr�rTrUr��move_xr�r�rW�margin_contentr�rSrRs`  `                @@@rOr�z Window._write_to_screen_at_index�s�������� �A�%�%��)=��)B�)B��F�T�S�S�S��AR�S�S�S��U�U�U�U�$�BT�U�U�U�� �!3�6I�!I�J�J���\�0�0�� �#5�5�~�7L�
�
�
��*�i�0�0�0�0�0��_�_�&�&�
������,�/A�A�>�CX�	
�	
�	
�
	
�
�
�f�n�h�7�7�7�!)��� 4� 4�D��
�
����$�*��15�������"�#�#�� �#5�5�� ��"�!� �"�4�#�6�6�8�8��i�i�&�6�$�,�F�� �0�1@�1
�1
�-���$"�&��-?�)@�)@�@��!�&��&��!�"�4� �0�'�-�0B�B�(�/�&*�&9�$;�%���!�

�

�

��'���:	�z�:	�6L�:	�:	�:	�:	�:	�:	�:	�:	�:	�x	�2�2� �%��,>�(?�(?�?� �%��(<�<�?Q�Q� �%� �%��(=�=�!�	3�	
�	
�	
���		�V�		�C�		�I�		�		�		�		�		�		�		��D�-�/A�B�B�	 �	 �H�A�u��q�y�y�!.��q�%�!8�!8���!�!�.�&�.�&�RW�X�X�X��%�����%��,?�(@�(@�@���D�.�0C�D�D�	�	�H�A�u�*�]�1�e�4�4�N�
���n�f�n�f�e�T�T�T��e�O�F�F�	
���&�.�,�?�?�?�;I��1�$�7�7�7rRrrL�
new_screenrrNrMr�r�r�c���������
�
�����������j|z��j��j��j�td�i�i�	ddt
dtdtdtdtdtttff�
�������������fd	�
�dtf������
��fd
�}|��dtdtdtf�fd
�}�j
r�|�j
j�j
j��}|rA��
||��|rd�_n�j�_|����|	r|��|����j��|r�j
r|�����jr4��||�jj�jj����t+�j��jz���_��fS)a
        Copy the UIContent into the output screen.
        Return (visible_line_to_row_col, rowcol_to_yx) tuple.

        :param get_line_prefix: None or a callable that takes a line number
            (int) and a wrap_count (int) and returns formatted text.
        )r�r�F�liner�r"r#�is_inputrJc	���|r�}ni}|r.�r,t�|d����}�||||d���\}}d}�rP|rN�}t|��}|dkr2|r0|t|dd��z}|dz
}|dd�=|dkr|�0||z}�tjkr!t|��}	|	� kr|� |	z
dzz
}n-�tjkrt|��}	|	� kr|� |	z
z
}d}
d}|D�]�^}}
}�|�$z}d|vr"�j|�$z|�#zxx|
z
cc<�7|
D�]R}t||f}|j	}�!r|||z� krs|�|d|zf�|dz<|dz
}|dz
}d}|r.�r,t�||����}�||||d���\}}�|�$z}|�"j
kr||fccS|dkr�|dkr�|� kr�|||�#z<|dkrtd|��D]
}�||�#z|z<�n`|dkrZdD]W}||z
dkrL||�#z|z
j	|kr5||�#z|z
}t|j|z|j
f}|||�#z|z
<�X|�$z|�#zf|||
|zf<|
dz
}
||z
}��T���||fS)	z�
            Copy over a single line to the output screen. This can wrap over
            multiple lines in the output. It will call the prefix (prompt)
            function before every line.
            rF�r
r#Nr$z[ZeroWidthEscape])r$r#)rr3rr?r~rr��zero_width_escapesr0rWr�r�r�r�)%rr�r"r#r
�current_rowcol_to_yx�prompt�skipped�h_scroll�
line_widthrk�
wrap_countr�rz�_�new_buffer_rowr�r��
char_widthr��pw�	prev_char�char2r��	copy_line�
empty_charr�rM�
new_bufferr
rSrRrWrVr^r�r�s%                       ��������������rOrz$Window._copy_body.<locals>.copy_line�s�����
*�'3�$�$�')�$��
G�O�
G�*�?�?�6�1�+E�+E�F�F�� �y����A��F�F�F���1��G� �
�X�
�,��-�d�3�3����l�l�t�l��
�4��7�1�:� 6� 6�6�H��q�L�G��R�a�R����l�l�t�l�
�X�
��
��*�*�*�0��6�6�
���%�%��%�*�,��2�2�A���+�+�+�+�0��6�6�
���%�%����+�+�A��C��J�#'�I
$�I
$���t�a�!+�A��H�!5��'�%�/�/��1�!�d�(�;�A��H�E�E�E��M�E�E�E���@$�@$�A�&�q�%�x�0�D�!%��J�"�(�a�*�n�u�&<�&<�"�3�A�6�q�9�A�=�:�/��A��6��Q���"�a��
���$�S��S�%6� /���
� C� C�&�&�F�$-�9�V�V�Q��E�#R�#R�#R�D�A�q�)3�A��H�)=���� 5�5�5�#$�a�4�K�K�K�K�K��A�v�v�!�q�&�&�Q��Y�Y�37��q�4�x�0�&��>�>�%*�1�j�%9�%9�J�J��?I��q�4�x�!�|� <� <�J�(�1�_�_�'-�	J�	J��$%��F�a�K�K�(6�q�4�x�"�}�(E�(K�r�(Q�(Q�0>�q�4�x�"�}�0M�I�,7�(1���(:�I�O�(K�-&�E�EJ�N�1�t�8�b�=�$A����H���H�G�,�V�S�7�]�-B�C�
�1�H�C���O�A�A�A@$�B�a�4�KrRc�����	}�}|�jkrR|�krL��|��}|�f�
|<d}�||||d���\}}|dz
}|dz
}|�jkr|�k�L|S)NrTrr#)r��get_line)r#r�rr"rrMrgrLrNr�rRr^s    ��������rO�copyzWindow._copy_body.<locals>.copy7s����"�"�A�$�F��n�+�+�+���0C�0C�!�*�*�6�2�2��.4�6G�-H�'��*��� �y��v�q�!�d�C�C�C���1��!����Q����n�+�+�+���0C�0C��HrRr;rkc���	�||f\}}t||���S#t$rtdd���cYSwxYw)z<Translate row/col from UIContent to real Screen coordinates.r!r)rrb)r;rkr#r"rSs    �rO�cursor_pos_to_screen_posz3Window._copy_body.<locals>.cursor_pos_to_screen_posKsa���
'�#�C��H�-���1��q�A����&���
'�
'�
'��q�A����&�&�&�
'���s�
!�?�?r�)r�r�rgr:r0rrprrr
rr5r#r"�set_cursor_position�show_cursor�_highlight_digraph�_highlight_cursorlinesr��_show_key_processor_key_buffer�
menu_position�set_menu_positionr�)rNrLr
r^rrWrNrMrVr�r�r�r�r�r�r"r$�screen_cursor_positionrrrgrrSrRr�r�s ``` ```` `  ``   @@@@@@@@rOrzWindow._copy_body�s���������������������0�"�V�+���"���*�
��+�
� ��(�
�?A��@B��#�z	�z	�$�z	��z	��z	��	z	�
�z	��3��8�_�
z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�z	�c�	�	�	�	�	�	�	�	�	�	�	�	�	�$	
�����	'�#�	'�C�	'�E�	'�	'�	'�	'�	'�	'�"�%�	�%=�%=��*�,�j�.H�.J�&�&�"��
4��.�.�t�5K�L�L�L�%�D�-2�J�*�*�-7�-C�J�*��'�'�
�3�3�3��
��+�+��*����"�)�
����	<��3�	<��/�/�
�;�;�;��#�	��(�(��(�(��,�.�
�0H�0J���
�
�
� �
� 1�4�.�:O�3O�P�P�
��&��4�4rRc�P�t|j��r|���}n|j}|s|ro|}t|pddf}t|j|j|jz��D];}|j|}t|j|j|jz��D]}	|||	<��:dSdS)zj
        Erase/fill the background.
        (Useful for floats and when a `char` has been given.)
        r�r�N)	rFr�r0r�r�r�r:r�rW)
rNr\r^r`r�r8�char_objr#r;r"s
          rOr�zWindow._fill_bg�s����D�I���	��9�9�;�;�D�D��9�D��	&�t�	&��B�"�4�;�3��?�3�H��2�7�B�G�b�i�$7�8�8�
&�
&���(��+���r�w���"�(�(:�;�;�&�&�A�%�C��F�F�&�
	&�	&�
&�
&rRc���|dzt|j��z}|�||d���t|j|j|jzdz
|jd��}|�|dd���dS)Nr�F)r��afterr#zclass:last-lineT)r0)r"r��	fill_arear2r�r�r�rW)rNr
r^r_r�r8s      rOrzWindow._apply_style�s���
�s�"�V�D�J�%7�%7�7�����^�5���F�F�F������.�"7�7�!�;�� �
�	
�
��	���R�!2�$��?�?�?�?�?rRc��|���}|r>|�|��}t|df|j|j|j<dSdS)zd
        When we are in Vi digraph mode, put a question mark underneath the
        cursor.
        z
class:digraphN)r��get_cursor_positionr0r:r#r")rNr
�digraph_charr4s    rOr'zWindow._highlight_digraph�sc��
�-�-�/�/���	��1�1�$�7�7�D�5@��o�-�6�J�"�4�6�*�4�6�2�2�2�	�	rRc�0�t��}|jj}|rst��rg|jsb|dj}t
|��dkrD|�|��}t|df|j	|j
|j<dSdSdSdSdS)ah
        When the user is typing a key binding that consists of several keys,
        display the last pressed key if the user is in insert mode and the key
        is meaningful to be displayed.
        E.g. Some people want to bind 'jj' to escape in Vi insert mode. But the
             first 'j' needs to be displayed in order to get some feedback.
        rdr#zclass:partial-key-bindingN)r�
key_processor�
key_buffer�_in_insert_moder��datarr3r0r:r#r")rNr
r�r7r9r4s      rOr)z%Window._show_key_processor_key_buffer�s����i�i���&�1�
��
	�/�+�+�
	�C�K�
	��b�>�&�D��$���1�$�$�!�5�5�d�;�;��9D��5�5�:�
�&�t�v�.�t�v�6�6�6�
	�
	�
	�
	�
	�
	�%�$rRr4r"r#c���d}d}|j}	|���rJ|	|j}
t|||z��D])}|
|}t|j|j|zf|
|<�*|���rOt|||z��D];}|	|}
|
|j}t|j|j|zf|
|j<�<|j	}
t|
��r
|
��}
|
D]~}t|t��sJ�|j
}|||zkrUd|jz}t|||z��D]7}|	|}
|
||z}t|j|j|zf|
||z<�8�dS)z.
        Highlight cursor row/column.
        z class:cursor-line z class:cursor-column r�N)r:r�r#r�r0r�r�r�r"r�rFr�rDr�)rNr
r4r"r#rWr��cursor_line_style�cursor_column_styler:r;�
original_char�y2r��cc�column�color_column_styles                 rOr(zWindow._highlight_cursorlines�s���2��5�� �,���?�?���	��d�f�%�C��1�a�%�i�(�(�
�
�� #�A��
�$�!�&�
�(;�>O�(O�O���A���
�����	��A�q�6�z�*�*�
�
��!�"�o�� #�D�F��
�)�!�&�
�(;�>Q�(Q�Q���D�F���
�(���L�!�!�	*�'�<�>�>�L��	�	�B��b�+�.�.�.�.�.��[�F���E�	�!�!�%(�2�8�^�"���1�v�:�.�.���B�%�b�/�C�$'���
�O�M�&1�%�*�M�,?�BT�,T�T�'�C���
�O�O��	�	rRr	c��|j|z}|j}t||||j��}|�|||d|��dS)zL
        Copy characters from the margin screen to the real screen.
        rN)r�r�r2r�r)	rNr	r
r^rrWr�r��margin_write_positions	         rOrzWindow._copy_margin	sQ���"�V�+���"�� -�d�D�%��AV� W� W������
�4I�1�e�T�T�T�T�TrRc�f�|���r|j}n|j}||||��dS)zA
        Scroll body. Ensure that the cursor is visible.
        N)rV�_scroll_when_linewrapping�_scroll_without_linewrapping)rNrLrWr��funcs     rOr�zWindow._scroll	sB���?�?���	5��1�D�D��4�D���Z���'�'�'�'�'rRc������
����jj��jj�d�_dtdtf���fd��
�dkr�jj�_d�_dS�
�jj��}|��z
kr���	�jj��j
�jj���}�jj�_t|dz
|�z
�j���_td|�z
�j���_dSd�_dtf�
���fd�}dtf�
��fd	�}dtf�
��fd
�}|��}	t�jt|	|�������_t�j|�����_����st�j|	���_dSdS)��
        Scroll to make sure the cursor position is visible and that we maintain
        the requested scroll offset.

        Set `self.horizontal_scroll/vertical_scroll`.
        rr�rJc�<����|��j��Srw)r�r�)r�rNrLrWs ���rO�get_line_heightz9Window._scroll_when_linewrapping.<locals>.get_line_height.	s����1�1�&�%��AU�V�V�VrRN)�
slice_stopr#c���d}�jj}t�jjdd��D]}|�|��z
}|��z
kr|cS|}� dS)Nrrd�r5r#r�)�used_height�prev_linenor�rKr��scroll_offsets_bottomrLs   ����rO�get_min_vertical_scrollzAWindow._scroll_when_linewrapping.<locals>.get_min_vertical_scroll[	ss����K�$�4�6�K��
� :� <�b�"�E�E�
)�
)�����v�6�6�6����*?�!?�?�?�&�&�&�&�"(�K�K��1rRc����jj}d}t�jjdz
dd��D]}|�|��z
}|�kr|cS|}�|S)Nrr#rdrN)rPrOr�rK�scroll_offsets_toprLs   ���rO�get_max_vertical_scrollzAWindow._scroll_when_linewrapping.<locals>.get_max_vertical_scrollj	sr���$�4�6�K��K��
� :� <�q� @�"�b�I�I�
)�
)�����v�6�6�6���!3�3�3�&�&�&�&�"(�K�K��rRc����jdz
}d}t�jdz
dd��D]}|�|��z
}|�kr|cS|}�|S)z�
            Calculate the upper most line that can be visible, while the bottom
            is still visible. We should not allow scroll more than this if
            `allow_scroll_beyond_bottom` is false.
            r#rrd)rgr�)rPrOr�rKr�rLs   ���rO�get_topmost_visiblez=Window._scroll_when_linewrapping.<locals>.get_topmost_visiblex	sr���%�/�!�3�K��K��
� 5�� 9�2�r�B�B�
)�
)�����v�6�6�6����'�'�&�&�&�&�"(�K�K��rR)r�r/r.rMrpr5r#rNr�r�r�r"r�r�r�)
rNrLrWr��line_height�text_before_heightrRrUrW�topmost_visiblerKrQrTs
````      @@@rOrEz Window._scroll_when_linewrapping	s����������!%� 3� :��!�0�4��"#���	W�C�	W�C�	W�	W�	W�	W�	W�	W�	W�	W��A�:�:�#-�#=�#?�D� �%&�D�"��F�&�o�j�&@�&B�C�C����"4�4�4�4�",�!?�!?��*�,���$�%�5�7�	"@�"�"��$.�#=�#?�D� �%(�"�Q�&�����&�	&�&�D�"�&)��%��.��0F�&�&�D�"�
�F�%&�D�"�
	��
	�
	�
	�
	�
	�
	�
	�
	�
	�	��	�	�	�	�	�	�	�	�	�S�	�	�	�	�	�	�	�	�$.�-�/�/��
 #�� �#�o�7N�7N�7P�7P�"Q�"Q� 
� 
��� #�4�#7�9P�9P�9R�9R�S�S����.�.�0�0�	N�#&�t�';�_�#M�#M�D� � � �	N�	NrRc���|jptdd���}d�_|jdkrd�_d�_dSt
|�|j����}dtdtdtdtdtd	td
tf�fd�}�j
r6��
����_t�jt��sJ��jr6������_t�jt��sJ��j
}|�j|j|j|jj||j����_�jr;t#t%��|jjd������}nd}|�j|j|jt+|d|jj���||z
t/t+|���j|z������_dS)
rIrr!N�current_scroll�scroll_offset_start�scroll_offset_end�
cursor_pos�window_size�content_sizerJc�t��tt||dz|����}tt||dz|dz
|z
����}|dkrd}����s|||z
krtd||z
��}|||z
krtd||z
��}||dz|z
|zkr|dz|z
|z}|S)zEScrolling algorithm. Used for both horizontal and vertical scrolling.r$r#r)rpr�r�r�)r\r]r^r_r`rarNs      �rO�	do_scrollz6Window._scroll_without_linewrapping.<locals>.do_scroll�	s���#&��'��q��*�E�E�#�#��!$��%�{�Q���q�8H�:�8U�V�V�!�!��
��!�!�!"���3�3�5�5�
D�"�\�K�%?�?�?�!$�Q��{�(B�!C�!C���
�-@� @�@�@�!$�Q�
�5H�(H�!I�!I����a��;� >�AR� R�R�R�",�q�.�K�!?�BS�!S��!�!rR)r\r]r^r_r`ra)r5rr�rgrNrMrr!r#rpr�r�r�r�r.r/r�rrr,r-rr"r�)	rNrLrWr�r5�current_line_textrc�offsets�current_line_prefix_widths	`        rOrFz#Window._scroll_without_linewrapping�	sM���%�4�G���Q�����"#���� �A�%�%�#$�D� �%&�D�"��F� 5��#�#�O�$5�6�6�!�!��&	"��&	"�!$�&	"� #�&	"��	&	"�
�&	"��
&	"��&	"�&	"�&	"�&	"�&	"�&	"�R�#�	9�#'�#;�#;�D�#A�#A�D� ��d�2�C�8�8�8�8�8��%�	;�%)�%?�%?��%E�%E�D�"��d�4�c�:�:�:�:�:��%��(�y��/� '��%�n�!�1�3��#�.�
 
� 
� 
�����	*�(;�!�$�"6�"6�z�7Q�7S�UV�"W�"W�X�X�)�)�%�%�)*�%�!*���1� '��%�m�!�"3�4R�j�6P�6R�4R�"S�T�T�� 9�9���,�-�-�t�/E��/M���"
�"
�"
����rRr�r6c��|jtjkr|���dS|jtjkr|���dStS)z�
        Mouse handler. Called when the UI control doesn't handle this
        particular event.

        Return `NotImplemented` if nothing was done as a consequence of this
        key binding (no UI invalidate required in that case).
        N)r�r�SCROLL_DOWN�_scroll_down�	SCROLL_UP�
_scroll_upr�)rNr�s  rOr�zWindow._mouse_handler
sX���!�^�%?�?�?��������4�
�
#�~�'?�
?�
?��O�O�����4��rRc���|j}|�dS|j|j|jz
krE|jj|jjkr|j�	��|xjdz
c_dSdS)zScroll window down.Nr#)
r�rNrzrPr5r#rQr.r
�move_cursor_down�rN�infos  rOrizWindow._scroll_down
s{������<��F���$�"5��8J�"J�J�J��#�%��)G�)K�K�K���-�-�/�/�/�� � �A�%� � � � �	K�JrRc���|j}|�dS|jdkrP|jj|jdz
|jjz
kr|j���|xjdzc_dSdS)zScroll window up.Nrr#)	r�rNr5r#rPrQr/r
�move_cursor_uprns  rOrkzWindow._scroll_up
s�������<��F���!�#�#��$�&��%��)�D�,J�,Q�Q�R�R���+�+�-�-�-�� � �A�%� � � � �$�#rRc�4�|j���Srw)r
rhrMs rOrhzWindow.get_key_bindings0
s���|�,�,�.�.�.rRc��gSrwrLrMs rOrjzWindow.get_children3
s���	rRrkr�)=rlrmrnror?r�rr(r)rprrr.rCrrr
rDrqr&r�rIrPr�r�r*rVr[�staticmethodrrr�r'r�r�r1r/r2rdr�rr
r	rr�rr'r)rr(rr�rErFrr�rirkrrhr8rjrLrRrOr@r@{s������;�;�~(,�"�#�!%�*/�+0�-2�.3�37�48�26�38�#(�CG�EI�+0�#(�%*�
�?J�?O�/1�48�;?�5?�?��)�$�?��?��	?�
�#��?�(�
?�)�?�+�?� ,�?��x��/�0�?� ��� 0�1�?�!��/�?�%1�?�!�?�&�h��z�3��&?�@�?�  (��(��S��(A�B�!?�")�#?�$!�%?�&#�'?�(��$�{�#�X�b�$�{�2C�.C�%D�D�
�)?�.�[�(�2�{�?�";�;�<�/?�0�S�(�2�s�7�+�+�,�1?�2�D�#�x��C��0�0�1�3?�4"�"7�8�5?�6
�7?�?�?�?�B3�#�3�3�3�3�<�<�<�<� 
<��
<�3�
<�
<�
<�
<�
��
�
�
�
�
�3�
�9�
�
�
�
�>
�c�
��
��
�
�
�
�6�"�.
�.
��I�&�.
���H�S�M� 1�2�.
��.
�
�	.
�.
�.
��\�.
�`	<�S�	<�#�	<�)�	<�	<�	<�	<�	�8�C�=�	�	�	�	�7K��7K�&�7K�&�	7K�
�7K��
7K��#��7K�
�7K�7K�7K�7K�ruI��uI�&�uI�&�	uI�
�uI��
uI�
�uI�uI�uI�uI�| !�!"� � %�!"�#(��(�-�LP�p5�p5��p5��p5�&�	p5�
�p5��
p5��p5��p5��p5��p5��p5�!�p5��p5��p5�"�(�C��:�7G�+G�"H�I�p5� 
�t�C��s�C�x��(�)�4��c�3�h���s�C�x��0P�+Q�Q�	R�!p5�p5�p5�p5�d&��&�.;�&�GK�&�	
�&�&�&�&�,@� �@�2?�@�OR�@�	
�@�@�@�@�&
�V�
��
�
�
�
����D�����..� �.�(-�.�25�.�:=�.�FI�.�SV�.�	
�.�.�.�.�`U�!�U��U�&�	U�
�U��
U�
�U�U�U�U�"	(�)�	(�C�	(��	(��	(�	(�	(�	(�wN�#�wN�,/�wN�9<�wN�	
�wN�wN�wN�wN�rg
�#�g
�,/�g
�9<�g
�	
�g
�g
�g
�g
�R�*��9O�����"&�&�&�&�&�&�&�&�"/�(�?�";�/�/�/�/��d�9�o������rRc��eZdZdZdededdfd�Zdefd�Zdd�Z	d	e
defd
�Zde
de
defd
�Z
dedededededee
ddfd�Zdeefd�ZdS)rBa
    Wrapper around any other container that can change the visibility. The
    received `filter` determines whether the given container should be
    displayed or not.

    :param content: :class:`.Container` instance.
    :param filter: :class:`.Filter` instance.
    r
�filterrJNc�V�t|��|_t|��|_dSrw)rEr
rrv)rNr
rvs   rOr�zConditionalContainer.__init__A
s$��#�G�,�,�����'�'����rRc�(�d|j�d|j�d�S)NzConditionalContainer(z	, filter=�))r
rvrMs rOrIzConditionalContainer.__repr__E
s��P�t�|�P�P���P�P�P�PrRc�8�|j���dSrw)r
rPrMs rOrPzConditionalContainer.resetH
s����������rRrSc��|���r|j�|��Stj��Srw)rvr
rVr*�zerorUs  rOrVz$ConditionalContainer.preferred_widthK
s7���;�;�=�=�	$��<�/�/�0C�D�D�D��>�#�#�#rRrWrXc��|���r|j�||��Stj��Srw)rvr
r[r*r|rZs   rOr[z%ConditionalContainer.preferred_heightQ
s9���;�;�=�=�	$��<�0�0��8L�M�M�M��>�#�#�#rRr\r]r^r_r`rac�l�|���r|j�||||||��SdSrw)rvr
rdrcs       rOrdz$ConditionalContainer.write_to_screenW
sF���;�;�=�=�	��<�/�/�����h�PW���
�	�	rRc��|jgSrwr@rMs rOrjz!ConditionalContainer.get_childrene
s����~�rRrk)rlrmrnror7rr�rqrIrPrpr*rVr[r1r/r2rrrrdr
r8rjrLrRrOrBrB7
sA��������(��(�l�(�t�(�(�(�(�Q�#�Q�Q�Q�Q�����$�3�$�9�$�$�$�$�$�c�$��$��$�$�$�$����&��&�	�
���
��#���
������d�9�o������rRrBc���eZdZdZdegefddfd�Zdefd�Zdd�Z	de
defd	�Zd
e
de
defd�Z
d
edededededee
ddfd�Zdefd�Zdeefd�Zdeefd�ZdS)rHz�
    Container class that dynamically returns any Container.

    :param get_container: Callable that returns a :class:`.Container` instance
        or any widget with a ``__pt_container__`` method.
    �
get_containerrJNc��||_dSrw)r�)rNr�s  rOr�zDynamicContainer.__init__q
s��*����rRc�H�|���}t|��S)z�
        Return the current container object.

        We call `to_container`, because `get_container` can also return a
        widget with a ``__pt_container__`` method.
        )r�rE)rN�objs  rO�_get_containerzDynamicContainer._get_containert
s#��� � �"�"���C� � � rRc�R�|������dSrw)r�rPrMs rOrPzDynamicContainer.reset~
s&�������#�#�%�%�%�%�%rRrSc�P�|����|��Srw)r�rVrUs  rOrVz DynamicContainer.preferred_width�
s#���"�"�$�$�4�4�5H�I�I�IrRrWrXc�R�|����||��Srw)r�r[rZs   rOr[z!DynamicContainer.preferred_height�
s%���"�"�$�$�5�5�e�=Q�R�R�RrRr\r]r^r_r`rac�^�|����||||||��dSrw)r�rdrcs       rOrdz DynamicContainer.write_to_screen�
s?��	
�����-�-��N�N�L�(�G�	
�	
�	
�	
�	
rRc��dS)NFrLrMs rOrfzDynamicContainer.is_modal�
s���urRc��dSrwrLrMs rOrhz!DynamicContainer.get_key_bindings�
s	���trRc�,�|���gSrw)r�rMs rOrjzDynamicContainer.get_children�
s��
�#�#�%�%�&�&rRrk)rlrmrnrorr7r�r8r�rPrpr*rVr[r1r/r2rqrrrrdrfrrhr
rjrLrRrOrHrHi
s���������+�h�r�<�/?�&@�+�T�+�+�+�+�!�	�!�!�!�!�&�&�&�&�J�3�J�9�J�J�J�J�S�c�S��S��S�S�S�S�
��
�&�
�&�	
�
�
��

��#��
�
�
�
�
�
��$������(�?�";�����
'�d�9�o�'�'�'�'�'�'rRrH�	containerc��t|t��r|St|d��r!t|�����Std|�����)zC
    Make sure that the given object is a :class:`.Container`.
    rxzNot a container object: )r�r8�hasattrrErx�
ValueError�r�s rOrErE�
sb���)�Y�'�'�C���	��.�	/�	/�C��I�6�6�8�8�9�9�9��A�I�A�A�B�B�BrRc���t|t��r|St|d��r/tt	d|�������St
d|�d����)zB
    Make sure that the given argument is a :class:`.Window`.
    rxruzNot a Window object: �.)r�r@r�rFrrxr�r�s rOrFrF�
sp���)�V�$�$�A���	��.�	/�	/�A���.�	�:�:�K�K�M�M�N�N�N��?��?�?�?�@�@�@rR�valuezTypeGuard[AnyContainer]c��t|t��rdSt|d��r/tt	d|�������SdS)zb
    Checks whether the given value is a container object
    (for use in assert statements).
    TrxruF)r�r8r�rGrrx)r�s rOrGrG�
sY��
�%��#�#���t��u�(�)�)�N��D�!1�5�9�9�J�J�L�L�M�M�M��5rRN)rJr@)aro�abcrr�enumr�	functoolsr�typingrrr	r
rrr
rr�"prompt_toolkit.application.currentr�prompt_toolkit.cacher�prompt_toolkit.data_structuresr�prompt_toolkit.filtersrrrr�prompt_toolkit.formatted_textrrr�#prompt_toolkit.formatted_text.utilsrr�prompt_toolkit.key_bindingr�prompt_toolkit.mouse_eventsrr�prompt_toolkit.utilsrr r!r"�controlsr$r%r&r'r(r�r)r*r+r,r-�marginsr.r]r/r\r0r1r2�utilsr3�typing_extensionsr4r5�'prompt_toolkit.key_binding.key_bindingsr6�__all__r8rur7r{r:r9r�r;r<r=r>rArCrDr8r?r@rBrHrErF�objectrGrLrRrO�<module>r�s�����(�'�'�'�'�'�'�'�������������
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�7�6�6�6�6�6�,�,�,�,�,�,�0�0�0�0�0�0�����������������������
��������7�6�6�6�6�6�B�B�B�B�B�B�B�B�O�O�O�O�O�O�O�O�O�O�O�O�����������������������������������)�)�)�)�)�)�6�6�6�6�6�6�6�6�6�6�)�)�)�)�)�)��M�5�5�5�5�5�5�5�5�L�L�L�L�L�L�����,D�D�D�D�D�'�D�D�D�D�N������������Y� 0�0�1�����������D���������d����)�)�)�)�)�Y�)�)�)�Xl�l�l�l�l�V�l�l�l�^E�E�E�E�E�V�E�E�E�PZ�Z�Z�Z�Z�Y�Z�Z�Z�zN2�N2�N2�N2�N2�N2�N2�N2�bZ�Z�Z�Z�Z�Z�Z�Z�z*
�*
�*
�*
�*
�*
�*
�*
�Z��������!�#4�4�������$����y�y�y�y�y�Y�y�y�y�x%/�/�/�/�/�9�/�/�/�d8'�8'�8'�8'�8'�y�8'�8'�8'�v	C�L�	C�Y�	C�	C�	C�	C�	A��	A�&�	A�	A�	A�	A�	��	�#<�	�	�	�	�	�	rR

Youez - 2016 - github.com/yon3zu
LinuXploit