U
    -e'                     @  s   U d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZ d dlmZ erbd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)FastDictCache)Point)
get_cwidth   )WindowScreenCharc                C   @  s   e Zd ZU dZdZ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$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEBZdFedG< dXdIdIdJdKdLdMZd dNdOdPdQZd dNdOdRdSZ	e
seZe	ZdIdTdUdVZdWS )Yr   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widthz^@z^Az^Bz^Cz^Dz^Ez^Fz^Gz^Hz^Iz^Jz^Kz^Lz^Mz^Nz^Oz^Pz^Qz^Rz^Sz^Tz^Uz^Vz^Wz^Xz^Yz^Zz^[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> )B 	
                                                                                                    zdict[str, str]display_mappings strNone)r   r   returnc                 C  sH   || j kr.|dkr|d7 }n|d7 }| j | }|| _|| _t|| _d S )NrT   z class:nbsp z class:control-character )rU   r   r   r
   r   )selfr   r    r[   ]/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/prompt_toolkit/layout/screen.py__init__l   s    


zChar.__init__bool)otherrY   c                 C  s   | j |j ko| j|jkS Nr   r   rZ   r_   r[   r[   r\   _equal   s    zChar._equalc                 C  s   | j |j kp| j|jkS r`   ra   rb   r[   r[   r\   
_not_equal   s    zChar._not_equalrY   c                 C  s   | j j d| jd| jdS )N(z, ))	__class____name__r   r   rZ   r[   r[   r\   __repr__   s    zChar.__repr__N)r   rV   )ri   
__module____qualname____doc__	__slots__rU   __annotations__r]   rc   rd   r   __eq____ne__rk   r[   r[   r[   r\   r      s   
	Ii@B )sizez$FastDictCache[tuple[str, str], Char]_CHAR_CACHEz[transparent]c                   @  s   e Zd ZdZd+ddddddd	Zed
dddZddddddZddddddZdddddZ	dddddZ
ddddddZddddZd dd!d"d#Zd,d&d d'dd(d)d*ZdS )-r   z=
    Two dimensional buffer of :class:`.Char` instances.
    Nr   zChar | NoneintrX   )default_charinitial_widthinitial_heightrY   c                   sp   |d krt dtf  n| t fdd| _tdd | _i | _d| _i | _|pRd| _|p\d| _	i | _
g | _d S )Nr   c                     s   t  fddS )Nc                     s    S r`   r[   r[   Zdefault_char2r[   r\   <lambda>       3Screen.__init__.<locals>.<lambda>.<locals>.<lambda>r   r[   ry   r[   r\   rz      r{   z!Screen.__init__.<locals>.<lambda>c                   S  s   t dd S )Nc                   S  s   dS )NrV   r[   r[   r[   r[   r\   rz      r{   r|   r   r[   r[   r[   r\   rz      r{   Tr   )rt   Transparentr   data_bufferZzero_width_escapescursor_positionsshow_cursormenu_positionsr   height"visible_windows_to_write_positions_draw_float_functions)rZ   rv   rw   rx   r[   ry   r\   r]      s$    


zScreen.__init__zlist[Window]re   c                 C  s   t | j S r`   )listr   keysrj   r[   r[   r\   visible_windows   s    zScreen.visible_windowsr   r	   )windowpositionrY   c                 C  s   || j |< dS z=
        Set the cursor position for a given window.
        N)r   rZ   r   r   r[   r[   r\   set_cursor_position   s    zScreen.set_cursor_positionc                 C  s   || j |< dS r   )r   r   r[   r[   r\   set_menu_position   s    zScreen.set_menu_position)r   rY   c                 C  s2   z| j | W S  tk
r,   tddd Y S X dS )zX
        Get the cursor position for a given window.
        Returns a `Point`.
        r   xyN)r   KeyErrorr	   rZ   r   r[   r[   r\   get_cursor_position   s    zScreen.get_cursor_positionc                 C  s\   z| j | W S  tk
rV   z| j| W  Y S  tk
rP   tddd Y  Y S X Y nX dS )z
        Get the menu position for a given window.
        (This falls back to the cursor position if no menu position was set.)
        r   r   N)r   r   r   r	   r   r[   r[   r\   get_menu_position   s    zScreen.get_menu_positionzCallable[[], None])z_index	draw_funcrY   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)rZ   r   r   r[   r[   r\   draw_with_z_index   s    zScreen.draw_with_z_indexc                 C  s:   | j r6t| j dd d}|dd | _ |d d   q dS )z?
        Draw all float functions in order of z-index.
        c                 S  s   | d S Nr   r[   )itemr[   r[   r\   rz     r{   z(Screen.draw_all_floats.<locals>.<lambda>)keyr   Nr   )r   sorted)rZ   Z	functionsr[   r[   r\   draw_all_floats   s    zScreen.draw_all_floatsrW   )	style_strrY   c           	      C  sR   | j }t}d| }| D ]2\}}| 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`.
        r   N)r~   rt   itemsr   r   )	rZ   r   b
char_cacheappend_styler   rowr   r   r[   r[   r\   append_style_to_content  s    zScreen.append_style_to_contentrV   FWritePositionr^   )write_positionr   afterrY   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 ||< qpqZdS )z
        Fill the content of this area, using the given `style`.
        The style is prepended before whatever was here before.
        Nr   rV   )
stripxposr   rt   r~   rangeyposr   r   r   )rZ   r   r   r   ZxminZxmaxr   r~   r   Zprepend_styler   r   r   cellr[   r[   r\   	fill_area  s*     
zScreen.fill_area)Nr   r   )rV   F)ri   rl   rm   rn   r]   propertyr   r   r   r   r   r   r   r   r   r[   r[   r[   r\   r      s"      0
   c                   @  s0   e Zd ZddddddddZdddd	Zd
S )r   ru   rX   )r   r   r   r   rY   c                 C  s4   |dkst |dkst || _|| _|| _|| _d S r   )AssertionErrorr   r   r   r   )rZ   r   r   r   r   r[   r[   r\   r]   8  s    zWritePosition.__init__rW   re   c                 C  s   d | jj| j| j| j| jS )Nz+{}(x={!r}, y={!r}, width={!r}, height={!r}))formatrh   ri   r   r   r   r   rj   r[   r[   r\   rk   B  s    zWritePosition.__repr__N)ri   rl   rm   r]   rk   r[   r[   r[   r\   r   7  s   
r   N)
__future__r   collectionsr   typingr   r   r   Zprompt_toolkit.cacher   Zprompt_toolkit.data_structuresr	   Zprompt_toolkit.utilsr
   
containersr   __all__r   rt   rp   r}   r   r   r[   r[   r[   r\   <module>   s(    |  "