U
    
W[Ã  ã                   @   s2   d Z ddlmZ ddlmZ G dd„ dejƒZdS )zC
You don't really want to use this module. Try insults.py instead.
é    )Úprint_function)Úprotocolc                   @   sˆ   e Zd Z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„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd S )!ÚInsultsClientgš™™™™™É?c                 C   s(   d  | _ | _d | _| _g | _d| _d S )Nr   Ú )ÚwidthÚheightÚxposÚyposÚcommandQueueÚinEscape©Úself© r   ú>/usr/lib/python3/dist-packages/twisted/conch/insults/client.pyÚ__init__   s    zInsultsClient.__init__c                 C   s*   d}| j rd}|| _ || _|r&|  ¡  d S )Nr   é   )r   r   ÚwindowSizeChanged)r   r   r   Úcallr   r   r   ÚsetSize   s    zInsultsClient.setSizec                 C   sâ   ddl m} |D ]Ì}|dkrN| jr4|  |¡ d| _qÜ|| _| | j| j¡| _q|dkr¼| jr¼d| _| j ¡  |dkr€|  d¡ qÜ|dkr”|  d	¡ qÜ|d
kr¨|  d¡ qÜ|dkrÜ|  d¡ q| jrÒ|  j|7  _q|  |¡ qd S )Nr   )Úreactorúr   ZABCDÚAz<Up>ÚBz<Down>ÚCz<Right>ÚDz<Left>)	Útwisted.internetr   r   ÚkeyReceivedZ	callLaterÚescapeTimeoutÚ	endEscapeZ
escapeCallZcancel)r   Údatar   Úchr   r   r   ÚdataReceived   s0    
ÿ
zInsultsClient.dataReceivedc                 C   s   | j }d| _ |  |¡ d S )Nr   )r   r   ©r   r    r   r   r   r   7   s    zInsultsClient.endEscapec                 C   s   | j  d¡ d S )Nz=[?1h)Ú	transportÚwriter   r   r   r   Ú
initScreen<   s    zInsultsClient.initScreenc                 C   s"   || _ || _| j d||f¡ dS )z(Go to a position on the screen.
        ÚgotoxyN)r   r	   r
   Úappend)r   ÚxÚyr   r   r   ÚgotoXY?   s    zInsultsClient.gotoXYc                 C   s2   | j | jd k r.| j d|f¡ |  j d7  _ dS )zdWrite a character to the screen.  If we're at the end of the row,
        ignore the write.
        r   r$   N)r   r   r
   r'   r"   r   r   r   ÚwriteChF   s    zInsultsClient.writeChc                 C   sn   |d| j | j … }d|kr.|d| d¡… }d|krH|d| d¡… }| j d|f¡ |  jt|ƒ7  _dS )ztWrite a string to the screen.  This does not wrap a the edge of the
        screen, and stops at \r and \n.
        NÚ
úr$   )r   r   Úfindr
   r'   Úlen)r   Úsr   r   r   ÚwriteStrN   s    zInsultsClient.writeStrc                 C   s   | j  d¡ dS )z@Erase from the current position to the end of the line.
        )ÚeraseeolN©r
   r'   r   r   r   r   ÚeraseToLineZ   s    zInsultsClient.eraseToLinec                 C   s   | j  d¡ dS )zBErase from the current position to the end of the screen.
        )ÚeraseeosNr3   r   r   r   r   ÚeraseToScreen_   s    zInsultsClient.eraseToScreenc                 C   s   dg| _ d | _| _dS )z9Clear the screen, and return the cursor to 0, 0.
        )Úclsr   N)r
   r   r	   r   r   r   r   ÚclearScreend   s    zInsultsClient.clearScreenc                 G   s   | j  d|f¡ dS )z6Set the attributes for drawing on the screen.
        Ú
attributesNr3   )r   Zattrsr   r   r   ÚsetAttributesj   s    zInsultsClient.setAttributesc              	   C   sâ   d}| j D ]À}|d dkr<|d|d d |d d f 7 }q
|d dkrV||d 7 }q
|d dkrl|d	7 }q
|d d
kr‚|d7 }q
|d dkr˜|d7 }q
|d dkrÂ|dd tt|d ƒ¡ 7 }q
t|ƒ q
g | _ | j |¡ dS )zRedraw the screen.
        r   r   r&   z[%i;%iHé   r   r$   r2   z[0Kr5   z[OJr7   z[H[Jr9   z[%smú;N)r
   ÚjoinÚmapÚstrÚprintr#   r$   )r   ZredrawZcommandr   r   r   Úrefresho   s"    
"



zInsultsClient.refreshc                 C   s   dS )zpCalled when the size of the window changes.
        Might want to redraw the screen here, or something.
        Nr   r   r   r   r   r   …   s    zInsultsClient.windowSizeChangedc                 C   s   dS )z)Called when the user hits a key.
        Nr   )r   Úkeyr   r   r   r   Š   s    zInsultsClient.keyReceivedN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r!   r   r%   r*   r+   r1   r4   r6   r8   r:   rA   r   r   r   r   r   r   r   	   s    	r   N)Ú__doc__Z
__future__r   r   r   ZProtocolr   r   r   r   r   Ú<module>   s   