Sindbad~EG File Manager
3
.�]�/�@s
dZddlmZddlmZddlZdd�Zdd �Zd
d�Zdd
�Zdd�Z dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�ZGd6d7�d7ej�ZGd8d9�d9e�ZdS):a�This implements an ANSI (VT100) terminal emulator as a subclass of screen.
PEXPECT LICENSE
This license is approved by the OSI and FSF as GPL-compatible.
http://opensource.org/licenses/isc-license.txt
Copyright (c) 2012, Noah Spurrier <noah@noah.org>
PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
�)�screen)�FSM�NcCs|jd}|j|j�dS)Nr)�memory�write_ch�input_symbol)�fsmr�r �/usr/lib/python3.6/ANSI.py�DoEmit$s
rcCs|jj|j�dS)N)r�appendr)rr r r
�
DoStartNumber)sr
cCs$|jj�}||j}|jj|�dS)N)r�poprr)r�nsr r r
�
DoBuildNumber-s
rcCs|jd}|j�dS)Nr)r�cursor_back)rrr r r
� DoBackOne3s
rcCs&t|jj��}|jd}|j|�dS)Nr)�intrrr)r�countrr r r
�DoBack8s
rcCs|jd}|j�dS)Nr)r�cursor_down)rrr r r
� DoDownOne>s
rcCs&t|jj��}|jd}|j|�dS)Nr)rrrr)rrrr r r
�DoDownCs
rcCs|jd}|j�dS)Nr)r�cursor_forward)rrr r r
�DoForwardOneIs
rcCs&t|jj��}|jd}|j|�dS)Nr)rrrr)rrrr r r
� DoForwardNs
rcCs|jd}|j�dS)Nr)rZcursor_up_reverse)rrr r r
�DoUpReverseTs
rcCs|jd}|j�dS)Nr)r� cursor_up)rrr r r
�DoUpOneYs
rcCs&t|jj��}|jd}|j|�dS)Nr)rrrr)rrrr r r
�DoUp^s
rcCs6t|jj��}t|jj��}|jd}|j||�dS)Nr)rrr�cursor_home)r�c�rrr r r
�DoHomeds
r#cCs"d}d}|jd}|j||�dS)Nrr)rr )rr!r"rr r r
�DoHomeOriginks
r$cCs|jd}|j�dS)Nr)r�
erase_down)rrr r r
�DoEraseDownrs
r&cCsPt|jj��}|jd}|dkr*|j�n"|dkr<|j�n|dkrL|j�dS)Nrr�)rrrr%Zerase_upZerase_screen)r�argrr r r
�DoErasews
r)cCs|jd}|j�dS)Nr)r�erase_end_of_line)rrr r r
�DoEraseEndOfLine�s
r+cCsPt|jj��}|jd}|dkr*|j�n"|dkr<|j�n|dkrL|j�dS)Nrrr')rrrr*Zerase_start_of_line�
erase_line)rr(rr r r
�DoEraseLine�s
r-cCs|jd}|j�dS)Nr)rZ
scroll_screen)rrr r r
�DoEnableScroll�s
r.cCs|jd}|j�dS)Nr)rZcursor_save_attrs)rrr r r
�DoCursorSave�s
r/cCs|jd}|j�dS)Nr)rZcursor_restore_attrs)rrr r r
�DoCursorRestore�s
r0cCs6|jd}t|jj��}t|jj��}|j||�dS)Nr)rrrZscroll_screen_rows)rrZr2Zr1r r r
�DoScrollRegion�s
r1cCs|jd}|jj�}dS)Nr)rr)rr�moder r r
�DoMode�s
r3cCsB|jd}|g|_tdd�}|j|jd|jd�|j�dS)Nr�log�a�,�
)r�open�writerZ
current_state�close)rrZfoutr r r
�DoLog�s
r;c@seZdZdZddd�ZdS)�termz�This class is an abstract, generic terminal.
This does nothing. This is a placeholder that
provides a common base class for other terminals
such as an ANSI terminal. ��PcOstjj|||f|�|�dS)N)r�__init__)�selfr"r!�args�kwargsr r r
r?�sz
term.__init__N)r=r>)�__name__�
__module__�__qualname__�__doc__r?r r r r
r<�sr<c@sZeZdZdZddd�Zdd�Zdd �Zd
d�Zdd
�Zdd�Z dd�Z
dd�Zdd�ZdS)�ANSIz�This class implements an ANSI (VT100) terminal.
It is a stream filter that recognizes ANSI terminal
escape sequences and maintains the state of a screen object. r=r>cOsrtj|||f|�|�tjd|g�|_|jjtd�|jjdtd�|jjdddd�|jjdtd�|jjdddd�|jjdddd�|jj dddd�|jj dddd�|jjd dt
d�|jjd
dtd�|jjddtd�|jjddtd�|jjd
dtd�|jjdddd�|jjdddd�|jjddd�|jjdddd�|jjddt
d�|jjddtd�|jjddtd�|jjddtd�|jjddtd�|jjddtd�|jjddtd�|jjddtd�|jjdd|jd�|jjdddd�|jj tjdtd�|jj tjdtd�|jjddtd�|jjddtd�|jjddtd�|jjddtd�|jjddtd�|jjddtd�|jjddt d�|jjdd|jd�|jjd d|j!d�|jj tjdtd!�|jj tjd!td!�|jjdd!|j"d�|jjd"d!|j"d�|jjd#ddd$�|jjd$td�|jj tjd$td%�|jj tjd%td%�|jjd%td�|jjdd%t#d�|jjd&d%t#d�|jjdd%t$d�|jjdd%|jd�|jjd d%|j!d�|jjd#d%dd'�|jjd'td�|jj tjd'td(�|jj tjd(td(�|jjd(td�|jjdd(|jd�|jjd d(|j!d�|jjd#d(dd'�dS))NZINIT�ZESC�(ZG0SCS�)ZG1SCSZAB012�7�8�M�>�<�=�#ZGRAPHICS_POUND�[ZELB�H�D�B�C�A�J�Kr"�m�?ZMODECRAPZNUMBER_1�l�qZMODECRAP_NUM�h�;Z SEMICOLONZNUMBER_2�fZSEMICOLON_XZNUMBER_X)%r<r?r�stateZset_default_transitionr;Zadd_transition_anyrZadd_transitionZadd_transition_listr/r0rr$rrrrr&r+r.�do_sgr�stringZdigitsr
rrrrrr)r-r3� do_decsca�do_modecrapr#r1)r@r"r!rArBr r r
r?�s|z
ANSI.__init__cCs$t|t�r|j|�}|jj|�dS)z4Process a single character. Called by :meth:`write`.N)�
isinstance�bytes�_decodera�process)r@r!r r r
ris
zANSI.processcCs|j|�dS)N)r9)r@r\r r r
�process_listszANSI.process_listcCs0t|t�r|j|�}x|D]}|j|�qWdS)zaProcess text, writing it to the virtual screen while handling
ANSI escape codes.
N)rfrgrhri)r@�sr!r r r
r9#s
z
ANSI.writecCsdS)Nr )r@r r r
�flush,sz
ANSI.flushcCs�t|t�r|j|�}|d}|dkr0|j�dS|dkrD|j�dS|ttj�kr^|j�dS|j |j
|j|�|j
}|j}|j�||jkr�|j
�||j
kr�|j|j
d�n|j�|j|j
d�|j�dS)z�This puts a character at the current cursor position. The cursor
position is moved forward with wrap-around, but no scrolling is done if
the cursor hits the lower-right corner of the screen. r�
Nr7r)rfrgrhZcrZcrlf�chrrZBSrZput_absZcur_rZcur_crrr Z scroll_upr,)r@ZchZold_rZold_cr r r
r/s.
z
ANSI.write_chcCs|jd}|g|_dS)z&Select Graphic Rendition, e.g. color. rN)r)r@rrr r r
rbPs
zANSI.do_sgrcCs|jd}|g|_dS)z'Select character protection attribute. rN)r)r@rrr r r
rdUs
zANSI.do_decscacCs|jd}|g|_dS)z�Handler for [?<number>h and [?<number>l. If anyone
wanted to actually use these, they'd need to add more states to the
FSM rather than just improve or override this method. rN)r)r@rrr r r
reZs
zANSI.do_modecrapN)r=r>)
rCrDrErFr?rirjr9rlrrbrdrer r r r
rG�s
S !rG)rF�rrrcrr
rrrrrrrrrrr#r$r&r)r+r-r.r/r0r1r3r;r<rGr r r r
�<module>s:
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists