o
    i	(                     @  s   U 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 d dlmZ d dlmZ d dlmZ er9ddlmZ d	d
gZG dd
 d
ZeeddZded< dZG dd	 d	ZG dd dZdS )    )annotationsdefaultdict)TYPE_CHECKINGCallableDefaultDictDictListOptionalTuple)FastDictCache)Point)
get_cwidth   )WindowScreenCharc                   @  s  e Zd ZU dZdZi ddddddd	d
dddddddddddddddddddddd d!d"d#d$i d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFi dGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxZdyedz< ddddZdddZdddZ	e
seZe	ZdddZdS )r   z
    Represent a single character in a :class:`.Screen`.

    This should be considered immutable.

    :param char: A single character (can be a double-width character).
    :param style: A style string. (Can contain classnames.)
    )charstylewidth z^@z^Az^Bz^Cz^Dz^Ez^Fz^Gz^H	z^I
z^Jz^Kz^Lz^Mz^Nz^Oz^Pz^Qz^Rz^Sz^Tz^Uz^Vz^Wz^Xz^Yz^Zz^[z^\z^]z^^z^_z^?   z<80>   z<81>   z<82>   z<83>   z<84>   z<85>   z<86>   z<87>   z<88>   z<89>   z<8a>   z<8b>   z<8c>   z<8d>   z<8e>   z<8f>   z<90>   z<91>z<92>z<93>z<94>z<95>z<96>z<97>z<98>z<99>z<9a>z<9b>z<9c>z<9d>z<9e>z<9f> )                                              zdict[str, str]display_mappings r   strr   returnNonec                 C  sH   || j v r|dkr|d7 }n|d7 }| j | }|| _|| _t|| _d S )NrX   z class:nbsp z class:control-character )rY   r   r   r   r   )selfr   r    r_   W/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/prompt_toolkit/layout/screen.py__init__l   s   


zChar.__init__otherboolc                 C  s   | j |j ko| j|jkS Nr   r   r^   rb   r_   r_   r`   _equal   s   zChar._equalc                 C  s   | j |j kp| j|jkS rd   re   rf   r_   r_   r`   
_not_equal   s   zChar._not_equalc                 C  s   | j j d| jd| jdS )N(z, ))	__class____name__r   r   r^   r_   r_   r`   __repr__   s   zChar.__repr__N)rI   rZ   )r   r[   r   r[   r\   r]   )rb   r   r\   rc   r\   r[   )rl   
__module____qualname____doc__	__slots__rY   __annotations__ra   rg   rh   r   __eq____ne__rn   r_   r_   r_   r`   r      s  
 		
 !#$%&'()*+,-./012345I

i@B )sizez$FastDictCache[tuple[str, str], Char]_CHAR_CACHEz[transparent]c                   @  s   e Zd ZdZ			d0d1ddZed2ddZd3ddZd3ddZd4ddZ	d4ddZ
d5dd Zd6d!d"Zd7d%d&Z	(d8d9d.d/ZdS ):r   z=
    Two dimensional buffer of :class:`.Char` instances.
    Nr   default_charChar | Noneinitial_widthintinitial_heightr\   r]   c                   sp   |d u rt dtf  n| t fdd| _tdd | _i | _d| _i | _|p)d| _|p.d| _	i | _
g | _d S )NrI   c                     s   t  fddS )Nc                     s    S rd   r_   r_   default_char2r_   r`   <lambda>       3Screen.__init__.<locals>.<lambda>.<locals>.<lambda>r   r_   r~   r_   r`   r      s    z!Screen.__init__.<locals>.<lambda>c                   S  s   t dd S )Nc                   S  s   dS )NrZ   r_   r_   r_   r_   r`   r      r   r   r   r_   r_   r_   r`   r      s    Tr   )rx   Transparentr   data_bufferzero_width_escapescursor_positionsshow_cursormenu_positionsr   height"visible_windows_to_write_positions_draw_float_functions)r^   ry   r{   r}   r_   r~   r`   ra      s$   



zScreen.__init__list[Window]c                 C  s   t | j S rd   )listr   keysrm   r_   r_   r`   visible_windows   s   zScreen.visible_windowswindowr   positionr   c                 C     || j |< dS z=
        Set the cursor position for a given window.
        N)r   r^   r   r   r_   r_   r`   set_cursor_position      zScreen.set_cursor_positionc                 C  r   r   )r   r   r_   r_   r`   set_menu_position   r   zScreen.set_menu_positionc                 C  s,   z| j | W S  ty   tddd Y S w )zX
        Get the cursor position for a given window.
        Returns a `Point`.
        r   xy)r   KeyErrorr   r^   r   r_   r_   r`   get_cursor_position   s
   zScreen.get_cursor_positionc                 C  sP   z| j | W S  ty'   z| j| W  Y S  ty&   tddd Y  Y S w w )z
        Get the menu position for a given window.
        (This falls back to the cursor position if no menu position was set.)
        r   r   )r   r   r   r   r   r_   r_   r`   get_menu_position   s   zScreen.get_menu_positionz_index	draw_funcCallable[[], None]c                 C  s   | j ||f dS )z
        Add a draw-function for a `Window` which has a >= 0 z_index.
        This will be postponed until `draw_all_floats` is called.
        N)r   append)r^   r   r   r_   r_   r`   draw_with_z_index   s   zScreen.draw_with_z_indexc                 C  sB   | j rt| j dd d}|dd | _ |d d   | j sdS dS )z?
        Draw all float functions in order of z-index.
        c                 S  s   | d S Nr   r_   )itemr_   r_   r`   r     s    z(Screen.draw_all_floats.<locals>.<lambda>)keyr   Nr   )r   sorted)r^   	functionsr_   r_   r`   draw_all_floats   s
   zScreen.draw_all_floats	style_strr[   c           	      C  sR   | j }t}d| }| D ]\}}| D ]\}}||j|j| f ||< qqdS )zn
        For all the characters in the screen.
        Set the style string to the given `style_str`.
        rI   N)r   rx   itemsr   r   )	r^   r   b
char_cacheappend_styler   rowr   r   r_   r_   r`   append_style_to_content  s   zScreen.append_style_to_contentrZ   Fwrite_positionWritePositionr   afterrc   c                 C  s   |  sdS |j}|j|j }t}| j}|rd| }d}	nd}|d }	t|j|j|j D ] }
||
 }t||D ]}|| }||j|	|j	 | f ||< q8q-dS )z
        Fill the content of this area, using the given `style`.
        The style is prepended before whatever was here before.
        NrI   rZ   )
stripxposr   rx   r   rangeyposr   r   r   )r^   r   r   r   xminxmaxr   r   r   prepend_styler   r   r   cellr_   r_   r`   	fill_area  s,   
zScreen.fill_area)Nr   r   )ry   rz   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]   )rZ   F)r   r   r   r[   r   rc   r\   r]   )rl   rp   rq   rr   ra   propertyr   r   r   r   r   r   r   r   r   r_   r_   r_   r`   r      s"    0







c                   @  s    e Zd Zddd	ZdddZdS )r   r   r|   r   r   r   r\   r]   c                 C  s4   |dksJ |dksJ || _ || _|| _|| _d S r   )r   r   r   r   )r^   r   r   r   r   r_   r_   r`   ra   8  s   
zWritePosition.__init__r[   c                 C  s   d | jj| j| j| j| jS )Nz+{}(x={!r}, y={!r}, width={!r}, height={!r}))formatrk   rl   r   r   r   r   rm   r_   r_   r`   rn   B  s   zWritePosition.__repr__N)
r   r|   r   r|   r   r|   r   r|   r\   r]   ro   )rl   rp   rq   ra   rn   r_   r_   r_   r`   r   7  s    

r   N)
__future__r   collectionsr   typingr   r   r   r   r	   r
   r   prompt_toolkit.cacher   prompt_toolkit.data_structuresr   prompt_toolkit.utilsr   
containersr   __all__r   rx   rt   r   r   r   r_   r_   r_   r`   <module>   s&    $| "