B
    't\"                 @   s   d dl mZ d dlmZ d dlmZ d dlmZmZ ddddgZ	edd	Z
edd
ZG dd deZeeddZdZG dd deZG dd deZdS )    )unicode_literals)FastDictCache)
get_cwidth)defaultdict
namedtuplePointSizeScreenCharzx yzrows columnsc            B   @   s   e Zd Z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@dAdBdCdDAZdOdFdGZdHdI ZdJdK ZdLdM Z	dNS )Pr
   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<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> )A 	
                                                                                                     c             C   sH   || j kr.|dkr|d7 }n|d7 }| j | }|| _|| _t|| _d S )NrO   z class:nbsp z class:control-character )display_mappingsr   r   r   r   )selfr   r    rS   ;lib/python3.7/site-packages/prompt_toolkit/layout/screen.py__init__m   s    


zChar.__init__c             C   s   | j |j ko| j|jkS )N)r   r   )rR   otherrS   rS   rT   __eq__~   s    zChar.__eq__c             C   s   | j |j kp| j|jkS )N)r   r   )rR   rV   rS   rS   rT   __ne__   s    zChar.__ne__c             C   s   d| j j| j| jf S )Nz
%s(%r, %r))	__class____name__r   r   )rR   rS   rS   rT   __repr__   s    zChar.__repr__N)r   rP   )
rZ   
__module____qualname____doc__	__slots__rQ   rU   rW   rX   r[   rS   rS   rS   rT   r
      s   
i@B )sizez[transparent]c               @   s\   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	dd Z
dd ZdddZdS )r	   z=
    Two dimensional buffer of :class:`.Char` instances.
    Nr   c                sj    d krt dtf  t fdd| _tdd | _i | _d| _i | _|pLd| _|pVd| _	g | _
g | _d S )Nr   c                  s   t  fddS )Nc                  s    S )NrS   rS   )default_charrS   rT   <lambda>   s    z3Screen.__init__.<locals>.<lambda>.<locals>.<lambda>)r   rS   )ra   rS   rT   rb      s    z!Screen.__init__.<locals>.<lambda>c               S   s   t dd S )Nc               S   s   dS )NrP   rS   rS   rS   rS   rT   rb      s    z3Screen.__init__.<locals>.<lambda>.<locals>.<lambda>)r   rS   rS   rS   rT   rb      s    Tr   )_CHAR_CACHETransparentr   data_bufferZzero_width_escapescursor_positionsZshow_cursormenu_positionsr   heightZvisible_windows_draw_float_functions)rR   ra   Zinitial_widthZinitial_heightrS   )ra   rT   rU      s    

zScreen.__init__c             C   s   || j |< dS )z- Set the cursor position for a given window. N)rf   )rR   windowpositionrS   rS   rT   set_cursor_position   s    zScreen.set_cursor_positionc             C   s   || j |< dS )z- Set the cursor position for a given window. N)rg   )rR   rj   rk   rS   rS   rT   set_menu_position   s    zScreen.set_menu_positionc             C   s,   y
| j | S  tk
r&   tdddS X dS )zX
        Get the cursor position for a given window.
        Returns a `Point`.
        r   )xyN)rf   KeyErrorr   )rR   rj   rS   rS   rT   get_cursor_position   s    
zScreen.get_cursor_positionc             C   sL   y
| j | S  tk
rF   y
| j| S  tk
r@   tddd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   )rn   ro   N)rg   rp   rf   r   )rR   rj   rS   rS   rT   get_menu_position   s    

zScreen.get_menu_positionc             C   s2   t |tst|t|st| 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)
isinstanceintAssertionErrorcallableri   append)rR   Zz_indexZ	draw_funcrS   rS   rT   draw_with_z_index   s    zScreen.draw_with_z_indexc             C   s>   x8| j r8t| j dd d}|dd | _ |d d   qW dS )z?
        Draw all float functions in order of z-index.
        c             S   s   | d S )Nr   rS   )itemrS   rS   rT   rb      s    z(Screen.draw_all_floats.<locals>.<lambda>)key   Nr   )ri   sorted)rR   Z	functionsrS   rS   rT   draw_all_floats   s    zScreen.draw_all_floatsc       	      C   s^   | j }t}d| }xF| D ]:\}}x0| D ]$\}}||j|j| f || |< q.W qW dS )zn
        For all the characters in the screen.
        Set the style string to the given `style_str`.
        r   N)re   rc   itemsr   r   )	rR   Z	style_strb
char_cacheappend_stylero   rowrn   r   rS   rS   rT   append_style_to_content   s    zScreen.append_style_to_contentrP   Fc             C   s   |  sdS |j}|j|j }t}| j}|r:d| }d}	nd}|d }	x\t|j|j|j D ]D}
||
 }x6t||D ](}|| }||j|	|j	 | f ||< qtW q\W dS )z
        Fill the content of this area, using the given `style`.
        The style is prepended before whatever was here before.
        Nr   rP   )
stripxposr   rc   re   rangeyposrh   r   r   )rR   Zwrite_positionr   ZafterZxminZxmaxr   re   r   Zprepend_stylero   r   rn   ZcellrS   rS   rT   	fill_area   s     zScreen.fill_area)Nr   r   )rP   F)rZ   r\   r]   r^   rU   rl   rm   rq   rr   rx   r}   r   r   rS   rS   rS   rT   r	      s   
 

c               @   s   e Zd Zdd Zdd ZdS )WritePositionc             C   s4   |dkst |dkst || _|| _|| _|| _d S )Nr   )ru   r   r   r   rh   )rR   r   r   r   rh   rS   rS   rT   rU     s    zWritePosition.__init__c             C   s   d| j j| j| j| j| jf S )Nz#%s(x=%r, y=%r, width=%r, height=%r))rY   rZ   r   r   r   rh   )rR   rS   rS   rT   r[     s    zWritePosition.__repr__N)rZ   r\   r]   rU   r[   rS   rS   rS   rT   r     s   
r   N)Z
__future__r   Zprompt_toolkit.cacher   Zprompt_toolkit.utilsr   collectionsr   r   __all__r   r   objectr
   rc   rd   r	   r   rS   rS   rS   rT   <module>   s   

v 