%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2599/usr/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2599/usr/lib/python3/dist-packages/urwid/__pycache__/vterm.cpython-38.pyc

U

��dZ9��>@sTddlmZmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZzddl
Z
ddlZddlZWnek
r�YnXddlmZddlmZmZddlmZddlmZmZddlmZmZmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%e&d	�Z'e&d
�e&d�e&d�e'e'd
e'de'de'de'de'de'de'de'de'de'de'de'de'de'de'de'de'de'de'd e'd!e'd"d#�Z(e'd$e'd%e'd&e'd'e'd(e'd)e'd*e'd+e'd,d-�	Z)e"d.�d/d/d0d1�fe"d2�d/d/d3d1�fe"d4�d/d/d5d1�fe"d6�d/d/d7d1�fe"d8�d/d/d9d1�fe"d:�d/d/d;d1�fe"d<�d/d/d=d1�fe"d>�d/d/d?d1�fe"d@�dAd/dBd1�fe"dC�d/ddDd1�fe"dE�d/ddFd1�fe"dG�d/d/dHd1�fe"dI�d/d/dJd1�fe"dK�d/d/dLd1�fe"dM�d/d/dNd1�fe"dO�dPe"d6�fe"dQ�dddRd1�fe"dS�d/d/dTd1�fe"dU�dPe"d4�fe"dV�dPe"d@�fe"dW�d/ddXd1�fe"dY�d/ddZd1�fe"d[�d/dd\d1�fe"d]�d/dd^d1�fe"d_�d/dd`d1�fe"da�d/ddbd1�fe"dc�dAdddd1�fe"de�dddfd1�fe"dg�dddhd1�fe"di�dPe"d>�fiZ*d/Z+dAZ,Gdjdk�dke-�Z.Gdldm�dme-�Z/Gdndo�doe0�Z1Gdpdq�dqe�Z2Gdrds�dse�Z3dS)t�)�division�print_functionN)�util)�DEC_SPECIAL_CHARS�ALT_DEC_SPECIAL_CHARS)�Canvas)�Widget�BOX)�AttrSpec�RealTerminal�
_BASIC_COLORS)�ord2�chr2�B�bytes�PYTHON3�xrange��
��	z[Az[Bz[Cz[Dz[1~z[2~z[3~z[4~z[5~z[6~z[[Az[[Bz[[Cz[[Dz[[Ez[17~z[18~z[19~z[20~z[21~z[23~z[24~)�enterZ	backspace�tabZesc�up�down�right�left�home�insert�delete�end�page up�	page down�f1�f2�f3�f4�f5Zf6Zf7Zf8Zf9Zf10Zf11Zf12ZOAZOBZOCZOD�OPZOQ�ORZOSz[15~)	rrrrr#r$r%r&r'�@�cCs|j|dd�S�Nr)�chars)�insert_chars��sZnumber�q�r2�-/usr/lib/python3/dist-packages/urwid/vterm.py�<lambda>g�r4�AcCs|jd|ddd�S�NrT)�relative��move_cursor�r0�rowsr1r2r2r3r4hr5rcCs|jd|ddd�Sr7r9r;r2r2r3r4ir5�CcCs|j|dddd�Sr7r9�r0�colsr1r2r2r3r4jr5�DcCs|j|dddd�Sr7r9r>r2r2r3r4kr5�EcCs|jd|ddd�S�NrT��
relative_yr9r;r2r2r3r4lr5�FcCs|jd|ddd�SrBr9r;r2r2r3r4mr5�GcCs|j|ddddd�S)Nrr+TrCr9)r0�colr1r2r2r3r4nr5�H�cCs|�|dd|dd�S)Nr+rr9)r0Zx_yr1r2r2r3r4or5�JcCs|�|d�S�Nr)�csi_erase_display�r0�moder1r2r2r3r4pr5�KcCs|�|d�SrK)�csi_erase_linerMr2r2r3r4qr5�LcCs|j|dd�S�Nr)�lines)�insert_linesr/r2r2r3r4rr5�McCs|j|dd�SrR)�remove_linesr/r2r2r3r4sr5�PcCs|j|dd�Sr,)�remove_charsr/r2r2r3r4tr5�XcCs*|�|j|jd|dd|jdf�S�Nrr+)�erase�term_cursorr/r2r2r3r4us���a�alias�ccCs
|�|�S�N)�csi_get_device_attributes�r0Znoner1r2r2r3r4yr5�dcCs|jd|dddd�S)Nrr+T)�
relative_xr9)r0�rowr1r2r2r3r4zr5�e�f�gcCs|�|d�SrK)�csi_clear_tabstoprMr2r2r3r4}r5�hcCs|�||�Sr`��
csi_set_modes�r0�modesr1r2r2r3r4~r5�lcCs|j||dd�S)NT��resetrkrmr2r2r3r4r5�mcCs
|�|�Sr`)�csi_set_attr)r0�attrsr1r2r2r3r4�r5�ncCs|�|d�SrK)�csi_status_reportrMr2r2r3r4�r5r1cCs|�|d�SrK)�csi_set_keyboard_ledsrMr2r2r3r4�r5�rcCs|�|d|d�SrZ)�csi_set_scroll)r0Zt_br1r2r2r3r4�r5r0cCs|��Sr`)�save_cursorrbr2r2r3r4�r5�ucCs|��Sr`)�restore_cursorrbr2r2r3r4�r5�`c@seZdZdd�Zdd�ZdS)�	TermModescCs|��dSr`rp��selfr2r2r3�__init__�szTermModes.__init__cCs:d|_d|_d|_d|_d|_d|_d|_d|_t|_	dS�NFT)
�display_ctrlr�lfnl�keys_decckm�
reverse_video�constrain_scrolling�autowrap�visible_cursor�CHARSET_DEFAULT�main_charsetrr2r2r3rq�szTermModes.resetN)�__name__�
__module__�__qualname__r�rqr2r2r2r3r~�sr~c@sJeZdZddddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)�TermCharsetN�0�U)�default�vt100�ibmpc�usercCsddg|_d|_|�d�dS)Nr�r�Fr)�_g�_sgr_mapping�activaterr2r2r3r��s
�zTermCharset.__init__cCs||j|<|j|jd�dS)z1
        Redefine G'g' with new mapping.
        �rhN)r�r��active)r�rh�charsetr2r2r3�define�s
zTermCharset.definecCs ||_|j�|j|d�|_dS)z2
        Activate the given charset slot.
        N)r��MAPPING�getr��current)r�rhr2r2r3r��szTermCharset.activatecCs
d|_dS)zA
        Set graphics rendition mapping to IBM PC CP437.
        TN)r�rr2r2r3�
set_sgr_ibmpc�szTermCharset.set_sgr_ibmpccCsd|_|j|jd�dS)zC
        Reset graphics rendition mapping to IBM PC CP437.
        Fr�N)r�r�r�rr2r2r3�reset_sgr_ibmpc�szTermCharset.reset_sgr_ibmpccCsT|js|j|jdkrLt�|�d��}|dkr@d|_tt|�Sd|_|Sn|SdS)Nr��cp437rr�r�)	r�r�r�r�find�decoder��strr)r��charZdec_posr2r2r3�
apply_mapping�szTermCharset.apply_mapping)
r�r�r�r�r�r�r�r�r�r�r2r2r2r3r��s�
r�csDeZdZdZdZdd�Z�fdd�Z�fdd�Z�fd	d
�Z�Z	S)�TermScrollerzd
    List subclass that handles the terminal scrollback buffer,
    truncating it as necessary.
    i'cCst|�|jkr|�d�dSrK)�len�SCROLLBACK_LINES�poprr2r2r3�trunc�szTermScroller.trunccs|��tt|��|�dSr`)r��superr��append)r��obj��	__class__r2r3r��szTermScroller.appendcs|��tt|��||�dSr`)r�r�r�r)r��idxr�r�r2r3r�szTermScroller.insertcs|��tt|��|�dSr`)r�r�r��extend)r��seqr�r2r3r��szTermScroller.extend)
r�r�r��__doc__r�r�r�rr��
__classcell__r2r2r�r3r��sr�c@s&eZdZdZdd�Zd|dd�Zdd�Zd}d
d�Zdd
�Zd~dd�Z	ddd�Z
d�dd�Zed�fdd�Z
ed�fdd�Zdd�Zdd�Zdd�Zdd �Zd�d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd�d/d0�Zd�d1d2�Zd�d3d4�Zd5d6�Zd7d8�Zd�d9d:�Zd;d<�Z d�d=d>�Z!d�d?d@�Z"d�dAdB�Z#d�dDdE�Z$d�dFdG�Z%dHdI�Z&dJdK�Z'd�dMdN�Z(d�dOdP�Z)d�dQdR�Z*d�dSdT�Z+dUdV�Z,dWdX�Z-dYdZ�Z.d�d[d\�Z/d�d]d^�Z0d_d`�Z1d�dadb�Z2d�ddde�Z3d�dfdg�Z4dhdi�Z5djdk�Z6dldm�Z7dndo�Z8d�dpdq�Z9d�drds�Z:dtdu�Z;dvdw�Z<d�dxdy�Z=dzd{�Z>dS)��
TermCanvasFcCsXt�|�|||_|_||_|j|_t�|_d|_	d|_
t�|_d|j
d<|��dS)Nr)rrN�cursor)rr��width�height�widget�
term_modesrnr��scrollback_buffer�scrolling_up�utf8_eat_bytesr�utf8_bufferZcoordsrq)r�r�r�r�r2r2r3r��s

zTermCanvas.__init__NcCsf|dkr|jd}|dkr$|jd}|�||�|_|jjr\|j|j|kr\|||jf|_nd|_dS)z�
        Set terminal cursor to x/y and update canvas cursor. If one or both axes
        are omitted, use the values of the current position.
        Nrr+)r\�constrain_coordsrnr�r�r�r�)r��x�yr2r2r3�set_term_cursors

zTermCanvas.set_term_cursorcCsd|_|jd|_dS)z?
        Reset scrolling region to full terminal size.
        rr+N)�scrollregion_startr��scrollregion_endrr2r2r3�reset_scrollszTermCanvas.reset_scrollTcCsx|rd|_|��dS|dkr(|jd}|s2|}t|j�}|j|7_|j|kr\||_n|jdkrld|_|��dS)z�
        Scroll the scrolling buffer up (up=True) or down (up=False) the given
        amount of lines or half the screen height.

        If just 'reset' is True, set the scrollbuffer view to the current
        terminal content.
        rNrI)r�r�r�r�r�)r�rrqrSZ	maxscrollr2r2r3�
scroll_buffers



zTermCanvas.scroll_buffercCsZt�|_d|_d|_d|_t�|_d|_d|_d|_	|�
�|��|j�
�|��dS)z%
        Reset the terminal.
        FrN)r�escbuf�
within_escape�
parsestate�attrspecr�r��saved_cursor�saved_attrs�is_rotten_cursorr��
init_tabstopsrnrq�clearrr2r2r3rq9s
zTermCanvas.resetcCsRt|jd�\}}|dkr |d7}|rBt|j�|krN|j�d�q$ndg||_dS)N�rr+)�divmodr�r��tabstopsr�)r�r�Ztablen�modr2r2r3r�SszTermCanvas.init_tabstopscCs~|r&tt|j��D]}d|j|<qdS|dkr8|jd}t|d�\}}|rd|j|d|>M<n|j|d|>O<dS�Nrr�r+)rr�r�r\r�)r�r��remover�r�divr�r2r2r3�set_tabstop^s
zTermCanvas.set_tabstopcCs6|dkr|jd}t|d�\}}|j|d|>@dkSr�)r\r�r�)r�r�r�r�r2r2r3�
is_tabstopms
zTermCanvas.is_tabstop� cCs|�|�g|jSr`)�
empty_charr��r�r�r2r2r3�
empty_linetszTermCanvas.empty_linecCs|j|jj|fSr`)r�r�r�r�r2r2r3r�wszTermCanvas.empty_charcCs4|jdks|jdkrdS|D]}|�t|��qdSrK)r�r��addbyter
)r��data�byter2r2r3�addstrzszTermCanvas.addstrc	Cs�|j\}}||jkrHt|j�D]&}|j||��g||j7<qn2||jkrzt|j�D]}|j|d|�|j|<q\||_||jk�r8t|j|�D]�}z|j��}Wn6tk
r�|j�	|�
��|jd7_Yq�YnXt|�|jk�r||��g|jt|�7}n|d|j�}|d7}|j�
d|�q�n4||jk�rlt||j�D]}|j�	|j�d���qP||_|��|�||�\}}|�||�|jdd�dS)zD
        Resize the terminal to the given width and height.
        Nr+rT)r�)r\r�rr��termr�r�r��
IndexErrorr�r�r�r�rr�r�r�r�)r�r�r�r�r��	last_liner2r2r3�resize�s>

&


�zTermCanvas.resizecCsr|jjtkrdS|td�kr"d}nd}|td�kr8d}n(|td�krJd}n|td	�kr\d
}nd}|j�||�dS)zF
        Set G0 or G1 according to 'char' and modifier 'mod'.
        N�(rr+r�r�r�r�rOr�r�)rnr�r�rr�r�)r�r�r�rhZcsetr2r2r3�set_g01�szTermCanvas.set_g01c	Cs"|j�td��}g}|j|r dp"dd��td��D]4}zt|�}Wntk
r\d}YnX|�|�q4t|dk	�rt|ddkr�tt|d}nt|}|\}}}	t|�|kr�|�|�q�t	t|��D]$}
||
dks�||
dkr�|||
<q�z|	|||�Wntk
�rYnXdS)zL
        Parse ECMA-48 CSI (Control Sequence Introducer) sequences.
        �?r+rN�;r^)
r��
startswithr�split�int�
ValueErrorr��CSI_COMMANDSr�r)r�r��qmarkr��argZnumZcsi_cmdZnumber_of_argsZ
default_value�cmd�ir2r2r3�	parse_csi�s,$


zTermCanvas.parse_csicCsN|td�kr$|td�kr$|���n&|td�kr\|td�krFt|j_n|td�krZt|j_n�|td�kst|td�kr�|�||�n�|td�kr�|jd	d
�n�|td�kr�|��n�|td�kr�|��n�|td
�kr�|�	�nl|td�kr�|�
�nV|td�k�r|j�t
d�n6|td�k�r0|jd	d�n|td�k�rJ|jd	d�dS)z;
        Parse escape sequences which are not CSI.
        �#�8�%r*ZG8r��)rUT��reverser@r_rArH�Z�[?6c�7)�
with_attrsN)r�decalnr�rnr��CHARSET_UTF8r��linefeedrq�newliner�r��respond�ESCrzr|)r�r�r�r2r2r3�parse_noncsi�s2





zTermCanvas.parse_noncsicCsJ|�td��r$|j�|dd��n"|�td��rF|j�|dd��dS)z1
        Parse operating system command.
        r�r+Nz3;rI)r�rr��	set_title)r��bufr2r2r3�	parse_oscszTermCanvas.parse_osccCsX|jdkr\|t��kr(|�|�d|_n0|td�ksF|jsX|td�krX|j|7_dS�n�|jdkr�|td�kr�t�|_d|_dS|jdkr�|td�kr�|�|j�td����n�|jdk�r|jd	d�|tt	d
�k�r|�|jdd	��td����nJ|jdk�r4|j�
td���r4t|j�dk�r4�n|jdk�rX|j�sX|td
�k�rXn�|jdk�rv|j|7_dS|jdk�r�|td�k�r�t�|_d|_dS|jdk�r�|td�td�td�td�fk�r�||_d|_dS|jdk�r�|�||j�nP|td�td�td�td�td�td�td�td�td�td�f
k�rL|�|�|�
�dS)Nr+rz0123456789;r��]rI�r�����\rWr��R�[r�r�r�r��r_r@rArHrUr�r�r��>�=)r�r��keysr�rr�rr�lstriprr�r�r�leave_escaper�r2r2r3�parse_escapesJ

,"�".F
zTermCanvas.parse_escapecCsd|_d|_t�|_dS)NFr)r�r�rr�rr2r2r3rHszTermCanvas.leave_escapecCs"d}|d@r|dK}|d7}q|S)z�
        Process startbyte and return the number of bytes following it to get a
        valid UTF-8 multibyte sequence.

        bytenum -- an integer ordinal
        r�@r+r2)r�ZbytenumZlengthr2r2r3�get_utf8_lenMs

zTermCanvas.get_utf8_lencCs�|jjtkstjdkr�|dkr8|�|�|_t|�|_dSd|krLdkr�nnt|jdk	r�|jdkr�|jd8_|jt|�7_dSd|_|jt|��	dd�}t
|�dkr�dS|�tjd	�}q�d|_t|�}nt|�}|�|�dS)
z�
        Parse main charset and add the processed byte(s) to the terminal state
        machine.

        byte -- an integer ordinal
        �utf8�N�r+zutf-8�ignorer�replace)
rnr�rrZ_target_encodingrr�rr�r�r��encode�process_char)r�r�Zsequencer�r2r2r3r�\s*�
"

zTermCanvas.addbytecCs�|j\}}t|t�rt|�}|jj}|td�krD|jdkrDd|_�nx|s`|td�kr`|�	��n\|s�|td�kr�|j
�d��n<|s�|td�kr�|j
�d��n|s�|td	�kr�|��|jj
r�|�	�n�|s�|td
�kr�|��n�|�s|td�k�r|dk�r�|�|d|�n�|�s@|td�k�r@|jdk�r@|j��n||�s^|td
�k�r^|��n^|�st|td�k�rtnH|j�r�|�|�n4|�s�|td�k�r�d|_t�|_d|_n
|�|�dS)ze
        Process a single character (single- and multi-byte).

        char -- a byte string
        �rIT�
�r�r+z
�	�r
zz�›N)r\�
isinstancer��chrrnr�rr�r��carriage_returnr�r�rr�rr�r��beeprrrr��push_cursor)r�r�r�r�Zdcr2r2r3r�sD





 
zTermCanvas.process_charcCsR|dkr|jd}|dkr$|jd}|�||�\}}|j|jj|f|j||<dS)z~
        Set character of either the current cursor position
        or a position given by 'x' and/or 'y' to 'char'.
        Nrr+)r\r�r�r�r�r��r�r�r�r�r2r2r3�set_char�s

zTermCanvas.set_charcCs|||jkr|jd}n|dkr"d}|jjrR|sR||jkr@|j}qt||jkrt|j}n"||jkrh|jd}n|dkrtd}||fS)z�
        Checks if x/y are within the terminal and returns the corrected version.
        If 'ignore_scrolling' is set, constrain within the full size of the
        screen and not within scrolling region.
        r+r)r�rnr�r�r�r�)r�r�r��ignore_scrollingr2r2r3r��s



zTermCanvas.constrain_coordscCs�|j\}}|rL|dkr$|jkr*qJnq�||jkrB|jdd�q�|d8}n>||jdkrh|jkrnq�nn||jkr�|��n|d7}|�||�dS)zw
        Move the cursor down (or up if reverse is True) one line but don't reset
        horizontal position.
        rTr�r+N)r\r��scrollr�r�r�)r�r�r�r�r2r2r3r�s


 

zTermCanvas.linefeedcCs|�d|jd�dSrZ)r�r\rr2r2r3r(�szTermCanvas.carriage_returncCs|��|��dS)z?
        Do a carriage return followed by a line feed.
        N)r(rrr2r2r3r�szTermCanvas.newlinecCsT|rd}}|r|jd|}|r2|jd|}n|jjrD||j7}|�||�dS)z�
        Move cursor to position x/y while constraining terminal sizes.
        If 'relative' is True, x/y is relative to the current cursor
        position. 'relative_x' and 'relative_y' is the same but just with
        the corresponding axis.
        Trr+N)r\rnr�r�r�)r�r�r�rdrDr8r2r2r3r:�s
zTermCanvas.move_cursorcCsD|dk	r4|j�|�}|jjr*|j|d�n
|�|�|�||�dS)zS
        Push one character to current position and advance cursor to x/y.
        N)r�)r�r�rnrr.r,r�r+r2r2r3�	push_chars
zTermCanvas.push_charcCs�|j\}}|jjr�|d|jkr<|js<d|_|�|||�q�|d7}||jkr�|jr�||jkrh|��n|d7}d}|�d|�|�|||�d|_n*|d|jkr�|d7}d|_|�|||�dS)z�
        Move cursor one character forward wrapping lines as needed.
        If 'char' is given, put the character into the former position.
        r+TrFN)	r\rnr�r�r�r/r�r.r�r+r2r2r3r*s$


zTermCanvas.push_cursorcCs.t|j�|_|r*t�|j�t�|j�f|_dSr`)�tupler\r��copyr�r�r�)r�r�r2r2r3rz=s


�zTermCanvas.save_cursorcCs\|jdkrdS|j\}}|�||�|rX|jdk	rXt�|jd�t�|jd�|_|_dSrZ)r�r�r�r1r�r�)r�r�r�r�r2r2r3r|Cs

�zTermCanvas.restore_cursorr�cCsR|j\}}||jdkr<|�td��|d7}|�|�r
q<q
d|_|�||�dS)zg
        Moves cursor to the next 'tabstop' filling everything in between
        with spaces.
        r+r�FN)r\r�r,rr�r�r�)r�Ztabstopr�r�r2r2r3rNs

zTermCanvas.tabcCsZ|r(|j�|j�|j�|j|���n.|j�|j�}|j�|�|j�|j|���dS)z�
        Append a new line at the bottom and put the topmost line into the
        scrollback buffer.

        If reverse is True, do exactly the opposite, but don't save into
        scrollback buffer.
        N)r�r�r�rr�r�r�r�)r�r�Zkilledr2r2r3r._szTermCanvas.scrollcCs$t|j�D]}|�d�|j|<q
dS)zB
        DEC screen alignment test: Fill screen with E's.
        rAN)rr�r�r��r�rer2r2r3r�oszTermCanvas.decalncCs|��|j|<dS)zZ
        Blank a single line at the specified row, without modifying other lines.
        N)r�r�r2r2r2r3�
blank_linevszTermCanvas.blank_liner+cCsz|dkr|j}|dkrd}|dkr,|��}n|j|jj|f}|\}}|dkrv|j|�||�|j|��|d8}qDdS)z�
        Insert 'chars' number of either empty characters - or those specified by
        'char' - before 'position' (or the current position if not specified)
        pushing subsequent characters of the line to the right without wrapping.
        Nrr+)r\r�r�r�r�r�rr�)r��positionr-r�r�r�r2r2r3r.|s
zTermCanvas.insert_charscCs\|dkr|j}|dkrd}|\}}|dkrX|j|�|�|j|�|���|d8}q"dS)z�
        Remove 'chars' number of empty characters from 'position' (or the current
        position if not specified) pulling subsequent characters of the line to
        the left without joining any subsequent lines.
        Nrr+)r\r�r�r�r�)r�r4r-r�r�r2r2r3rX�szTermCanvas.remove_charscCs\|dkr|jd}n|j}|dkr&d}|dkrX|j�||���|j�|j�|d8}q&dS)z�
        Insert 'lines' of empty lines after the specified row, pushing all
        subsequent lines to the bottom. If no 'row' is specified, the current
        row is used.
        Nr+r)r\r�r�rr�r�r��r�rerSr2r2r3rT�szTermCanvas.insert_linescCs\|dkr|jd}n|j}|dkr&d}|dkrX|j�|�|j�|j|���|d8}q&dS)z�
        Remove 'lines' number of lines at the specified row, pulling all
        subsequent lines to the top. If no 'row' is specified, the current row
        is used.
        Nr+r)r\r�r�r�rr�r�r5r2r2r3rV�szTermCanvas.remove_linesc	Cs�|j|�\}}|j|�\}}||krNt||d�D]}|��|j||<q2dS|}||kr�||kr�t||j�D]}|��|j||<qnn8||kr�t|d�D]}|��|j||<q�n
|�|�|d7}qRdS)aB
        Erase a region of the terminal. The 'start' tuple (x, y) defines the
        starting position of the erase, while end (x, y) the last position.

        For example if the terminal size is 4x3, start=(1, 1) and end=(1, 2)
        would erase the following region:

        ....
        .XXX
        XX..
        r+N)r�rr�r�r�r3)	r��startr ZsxZsy�exZeyr�r�r2r2r3r[�s 
zTermCanvas.erasecCs�|D�]l}d|krdkr,nn
|d}qd|kr@dkrNnn
|d}q|dkrf|�d�d}q|dkr~|�d�d}q|d	kr�d}q|d
kr�|j��d|j_q|dkr�|j��d
|j_q|dkr�|�d�q|dkr�|�d�q|dk�r|�d�q|dk�r|�d�q|dk�r.|�d�q|dk�rD|�d�q|dk�rZ|�d�q|dkrd}}|��qd|k�r�|dk	�r�|d7}dd�}||�}||�}t|�dk�r�d�	|gt
|��}|dk�r�|dk�r�dSt||�SdS)z�
        Parse SGI sequence and return an AttrSpec representing the sequence
        including all earlier sequences specified as 'fg', 'bg' and
        'attributes'.
        ��%�(�/�&�	underlineN�'�1�
F)��Tr+�bold���blink��standout��rrr�cSs|dkrdSt|SdS)Nr�)r)Zcolorr2r2r3�
_defaulter&sz.TermCanvas.sgi_to_attrspec.<locals>._defaulter�,r�)�add�discardr�r�rnr�r�r�r��join�listr
)r�rt�fg�bg�
attributes�attrrKr2r2r3�sgi_to_attrspec�s\














zTermCanvas.sgi_to_attrspeccCs�|ddkrd|_t�}|jdkr,d}}nvd|jjkr>d}n|jj}|dkrV|d8}d|jjkrhd}n|jj}|dkr�|d8}dD]}t|j|�s�q�|�|�q�|�||||�}|j	j
r�|�|�|_n||_dS)z)
        Set graphics rendition.
        rrNr�r�)rCr=rFrH)r��set�
foregroundZforeground_numberZ
backgroundZbackground_number�getattrrMrUrnr��reverse_attrspec)r�rtrSrQrRrTr�r2r2r3rs7s.

zTermCanvas.csi_set_attrcCsr|dkrtdd�}dd�|j�d�D�}d|krL|rL|�d�d�|�|_n"d|krn|sn|�d�d�|�|_|S)zd
        Put standout mode to the 'attrspec' given and remove it if 'undo' is
        True.
        Nr�cSsg|]}|���qSr2)�strip)�.0rQr2r2r3�
<listcomp>csz/TermCanvas.reverse_attrspec.<locals>.<listcomp>rLrH)r
rWr�r�rOr�)r�r��undortr2r2r3rY\s


zTermCanvas.reverse_attrspeccCs`t|j�D]P}t|j�D]@}|j||}|j|d|d�}|f|dd�|j||<qq
dS)zP
        Reverse video/scanmode (DECSCNM) by swapping fg and bg colors.
        r�r]r+N)rr�r�r�rY)r�r]r�r�r�rtr2r2r3r�ls
zTermCanvas.reverse_videocCs�|r�|dkr||j_q�|dkr(|��q�|dkrT|jj|krJ|j|d�||j_q�|dkrr||j_|�dd�q�|dkr�||j_q�|dkr�||j_|��n4|dkr�||j_n"|d	kr�||j_	n|d
kr�||j_
dS)zC
        Helper method for csi_set_modes: set single mode.
        r+rrEr^�rrGrJrD�N)rnr�r�r�r�r�r�r�r�rr�)r�rN�flagr�rqr2r2r3�set_modevs.






zTermCanvas.set_modecCs$|}|D]}|�||||�q
dS)zX
        Set (DECSET/ECMA-48) or reset modes (DECRST/ECMA-48) if reset is True.
        N)rb)r�rnr�rqrarNr2r2r3rl�szTermCanvas.csi_set_modesrcCsx|dkrd}|dkr|j}||kr0|jkrtnn@|jd|ddd�d|_|jd|ddd�d|_|�dd�dS)z�
        Set scrolling region, 'top' is the line number of first line in the
        scrolling region. 'bottom' is the line number of bottom line. If both
        are set to 0, the whole screen will be used (default).
        rr+T)r-N)r�r�r�r�r�)r��topZbottomr2r2r3ry�s(����zTermCanvas.csi_set_scrollcCs.|dkr|jdd�n|dkr*|jdd�dS)zc
        Clear tabstop at current position or if 'mode' is 3, delete all
        tabstops.
        rT)r�r)r�N)r��r�rNr2r2r3ri�szTermCanvas.csi_clear_tabstopcCs|s|j�td�dS)zz
        Report device attributes (what are you?). In our case, we'll report
        ourself as a VT102 terminal.
        r�N)r�rr)r�r�r2r2r3ra�sz$TermCanvas.csi_get_device_attributescCsP|dkr|j�td�n2|dkrL|j\}}|j�td|d|df�dS)z�
        Report various information about the terminal status.
        Information is queried by 'mode', where possible values are:
            5 -> device status report
            6 -> cursor position report
        rEz[0nr_z[%d;%dRr+N)r�rrr\�r�rNr�r�r2r2r3rv�s

zTermCanvas.csi_status_reportcCs`|j\}}|dkr,|�|j|jd|f�n0|dkrJ|�d|f||f�n|dkr\|�|�dS)z�
        Erase current line, modes are:
            0 -> erase from cursor to end of line.
            1 -> erase from start of line to cursor.
            2 -> erase whole line.
        rr+rIN)r\r[r�r3rer2r2r3rP�s
zTermCanvas.csi_erase_linecCsj|dkr&|�|j|jd|jdf�|dkrP|�d|jdd|jdf�n|dkrf|j|jd�dS)z�
        Erase display, modes are:
            0 -> erase from cursor to end of display.
            1 -> erase from start to cursor.
            2 -> erase the whole display.
        rr+)rrrI)r�N)r[r\r�r�r�rdr2r2r3rL�s"zTermCanvas.csi_erase_displaycCs*ddddd�}||kr&|j�||�dS)a0
        Set keyboard LEDs, modes are:
            0 -> clear all LEDs
            1 -> set scroll lock LED
            2 -> set num lock LED
            3 -> set caps lock LED

        This currently just emits a signal, so it can be processed by another
        widget or the main application.
        r�Zscroll_lockZnum_lockZ	caps_lock)rr+rIrN)r��leds)r�rNZstatesr2r2r3rw�s�z TermCanvas.csi_set_keyboard_ledscs>�fdd�t�j�D��_|dkr0��dd�n
�j|�dS)z�
        Clears the whole terminal screen and resets the cursor position
        to (0, 0) or to the coordinates given by 'cursor'.
        csg|]}����qSr2)r�)r[r�rr2r3r\
sz$TermCanvas.clear.<locals>.<listcomp>Nr)rr�r�r�)r�r�r2rr3r�szTermCanvas.clearcCs|jSr`)r�rr2r2r3r?szTermCanvas.colscCs|jSr`)r�rr2r2r3r<szTermCanvas.rowsccsT|jdkr|jD]
}|Vqn2|j|j}||j|j|j�D]
}|VqDdSrK)r�r�r�r�)r�Z	trim_leftZ
trim_rightr?r<Zattr_map�linerr2r2r3�contents


zTermCanvas.contentcCs"||kr|��g|��S|��Sr`)r?r<rh)r��otherr2r2r3�
content_delta$szTermCanvas.content_delta)NN)TFN)F)NFF)N)N)NN)F)F)FFF)N)F)F)r�)F)Nr+N)Nr+)Nr+)Nr+)F)F)F)rr)r)r)N)rrNNN)?r�r�r�Z	cacheabler�r�r�r�rqr�r�r�rr�r�r�r�r�r�rrrrrr�rr,r�rr(rr:r/r*rzr|rr.r�r3r.rXrTrVr[rUrsrYr�rbrlryrirarvrPrLrwr�r?r<rhrjr2r2r2r3r��s~




5#
	/$/


�

%







#G%


!
	




�

r�c@s�eZdZdZeeg�ZddddgZd-dd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd.dd�Zd d!�Zd"d#�Zd$d%�Zd/d'd(�Zd)d*�Zd+d,�ZdS)0�TerminalT�closedr)rf�titleNcCs�|j��|dkrd|_n||_|dkr6ttj�|_n
t|�|_|dkr\|j�dd�g|_n||_d|_	d|_
g|_t�|_
||_d|_d|_d|_d|_d|_d|_d|_dS)a@
        A terminal emulator within a widget.

        'command' is the command to execute inside the terminal, provided as a
        list of the command followed by its arguments.  If 'command' is None,
        the command is the current user's shell. You can also provide a callable
        instead of a command, which will be executed in the subprocess.

        'env' can be used to pass custom environment variables. If omitted,
        os.environ is used.

        'main_loop' should be provided, because the canvas state machine needs
        to act on input from the PTY master device. This object must have
        watch_file and remove_watch_file methods.

        'escape_sequence' is the urwid key symbol which should be used to break
        out of the terminal widget. If it's not specified, "ctrl a" is used.
        Nzctrl aZSHELLz/bin/shF)Z_Terminal__superr��escape_sequence�dict�os�environ�envr��command�keygrab�last_key�response_bufferr~r��	main_loop�master�pidr�r�r��	has_focus�
terminated)r�rsrrrwrnr2r2r3r�/s,

zTerminal.__init__c	Cs�|j}d|d<t��\|_|_|jdkr�t|j�rzz8z|��Wn&t	j
�t�
��t	j
��YnXW5t�d�Xnt�|jd|j|�|jdkr�t�|jtjtj�t�|j�dS)NZlinuxZTERMr)rr�pty�forkryrx�callablersrp�_exit�sys�stderr�write�	traceback�
format_exc�flush�execvperw�fcntlZF_SETFL�
O_NONBLOCK�atexit�register�	terminate)r�rrr2r2r3�spawnes 


zTerminal.spawnc	Cs�|jr
dSd|_|��|�d�|jdkr�|�dd�tjtjtjtj	tj
fD]\}z&t�|j|�t�
|jtj�\}}Wntk
r�Yq�YnX|dkr�q�t�d�qPzt�
|jd�Wntk
r�YnXt�|j�dS)NTFrg�������?)r{�remove_watch�change_focusry�set_termsize�signal�SIGHUP�SIGCONT�SIGINT�SIGTERM�SIGKILLrp�kill�waitpid�WNOHANG�OSError�time�sleep�closerx)r�ZsigryZstatusr2r2r3r�}s0

�zTerminal.terminatecCs|�d�dS)Nr)��_emitrr2r2r3r)�sz
Terminal.beepcCs|�d|�dS)Nrfr�)r�Zwhichr2r2r3rf�sz
Terminal.ledscCs|j�|�dS)zF
        Respond to the underlying application with 'string'.
        N)rvr��r��stringr2r2r3r�szTerminal.respondcCs*|jD]}t�|j|�d��qg|_dS)N�ascii)rvrpr�rxrr�r2r2r3�flush_responses�s
zTerminal.flush_responsescCs(t�d||dd�}t�|jtj|�dS)NZHHHHr)�structZpackr�Zioctlrx�termiosZ
TIOCSWINSZ)r�r�r�Zwinsizer2r2r3r��szTerminal.set_termsizecCs~d}|jdkr|��d}|j|kr2|j|kr2dS|�||�|jsTt|||�|_n|j�||�||_||_|rz|��dSr�)	ryr�r�r�r�r�r�r��	add_watch)r�r�r�Zprocess_openedr2r2r3�
touch_term�s
zTerminal.touch_termcCs|�d|�dS)Nrmr�)r�rmr2r2r3r�szTerminal.set_titlecCsP|js|j|krdS||_|r>t���|_t�jdgd�nt�j|j�dS)z9
        Ignore SIGINT if this widget has focus.
        NZ	undefinedrE)r{rzrZtty_signal_keysZold_tios)r�rzr2r2r3r��szTerminal.change_focusFcCs<|js6|�|�|\}}|�||�|jdkr6|��|jSr`)r{r�r�rw�feedr�)r��sizeZfocusr�r�r2r2r3�render�s

zTerminal.rendercCs$|jdkrdS|j�|j|j�dSr`)rwZ
watch_filerxr�rr2r2r3r��s
zTerminal.add_watchcCs |jdkrdS|j�|j�dSr`)rwZremove_watch_filerxrr2r2r3r��s
zTerminal.remove_watchcCsdS)NTr2rr2r2r3�
selectable�szTerminal.selectable��?c
Cs`zt�|jggg|�WqTWqtjk
rP}z|jddkr@�W5d}~XYqXq|��dS)NrrD)�selectrx�error�argsr�)r�Ztimeoutrfr2r2r3�
wait_and_feed�szTerminal.wait_and_feedc
Cs�d}zt�|jd�}WnJtk
r`}z,|jdkr8d}n|jtjkrNWY�
dS�W5d}~XYnX|dkr�|��|�d�dS|j�	|�|�
�dS)N�irErl)rp�readrxr��errnoZEWOULDBLOCKr�r�r�r�r�)r�r�rfr2r2r3r��s


z
Terminal.feedcCs�|jr
|S|dkr*|\}}|�||�dS|j|jkrN||jkrN||_d|_n�|jrp|j|krnd|_||_dSn�|dkr�|j��||_|��dS|dkr�|jjdd�||_|��dS|j|jkr�||jkr�||_|S|j|kr�d|_||_dS|j|dk�s|dk�rd|_n
||_|S||_|jjdd�|�	d	��r�|d
�
��rntt|d
�td�d�}ntt|d
�td
�d�}n,|j
j�r�|tk�r�t�|�}nt�||�}|j
j�r�|dk�r�|d7}t�r�|�d�}t�|j|�dS)Nz
window resizeTFr!r")rrrpzctrl rr]r+r6r �
r�)r{r�rurnrtr�r�Z_invalidateZ_command_mapr��islowerr'�ordr�r��KEY_TRANSLATIONS_DECCKMr��KEY_TRANSLATIONSr�rrrpr�rx)r�r��keyr�r�r2r2r3�keypresssj�

�

zTerminal.keypress)NNN)F)r�)r�r�r�Z_selectable�	frozensetr	Z_sizingZsignalsr�r�r�r)rfrr�r�r�rr�r�r�r�r�r�r�r�r2r2r2r3rk)s*

6


rk)4Z
__future__rrrpr�r�r1r�r�r�r�r�r�r|r�r��ImportErrorZurwidrZurwid.escaperrZurwid.canvasrZurwid.widgetrr	Zurwid.display_commonr
rrZurwid.compatr
rrrrrr'rr�r�r�r�r�objectr~r�rPr�r�rkr2r2r2r3�<module>s ��



�+9A

Zerion Mini Shell 1.0