a
    õ£Beì'  ã                   @  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@dAdBdCdDdEœBZdFedG< dXdIdIdJdKœdLdM„Zd dNdOœdPdQ„Zd dNdOœdRdS„Z	e
säe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 v 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[   ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/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 u 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  s0   z| j | W S  ty*   tddd� Y S 0 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  sX   z| j | W S  tyR   z| j| W  Y S  tyL   tddd� Y  Y S 0 Y n0 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J ‚|dksJ ‚|| _ || _|| _|| _d S r™   )r©   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$   þ|ÿ "