%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core18/current/usr/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core18/current/usr/lib/python3/dist-packages/urwid/__pycache__/vterm.cpython-36.pyc

3

��dZ9��F@sTddlmZmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZyddl
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�tab�esc�up�down�right�left�home�insert�delete�endzpage upz	page down�f1�f2�f3�f4�f5Zf6Zf7Zf8Zf9Zf10Zf11Zf12ZOAZOBZOCZOD�OPZOQ�ORZOSz[15~)	rrrrr"r#r$r%r&�@�cCs|j|dd�S)Nr)�chars)�insert_chars)�s�number�q�r0�-/usr/lib/python3/dist-packages/urwid/vterm.py�<lambda>gsr2�AcCs|jd|ddd�S)NrT)�relative)�move_cursor)r-�rowsr/r0r0r1r2hsrcCs|jd|ddd�S)NrT)r4)r5)r-r6r/r0r0r1r2is�CcCs|j|dddd�S)NrT)r4)r5)r-�colsr/r0r0r1r2js�DcCs|j|dddd�S)NrT)r4)r5)r-r8r/r0r0r1r2ks�EcCs|jd|ddd�S)NrT)�
relative_y)r5)r-r6r/r0r0r1r2ls�FcCs|jd|ddd�S)NrT)r;)r5)r-r6r/r0r0r1r2ms�GcCs|j|ddddd�S)Nrr*T)r;)r5)r-�colr/r0r0r1r2ns�H�cCs|j|dd|dd�S)Nr*r)r5)r-Zx_yr/r0r0r1r2os�JcCs|j|d�S)Nr)�csi_erase_display)r-�moder/r0r0r1r2ps�KcCs|j|d�S)Nr)�csi_erase_line)r-rCr/r0r0r1r2qs�LcCs|j|dd�S)Nr)�lines)�insert_lines)r-r.r/r0r0r1r2rs�McCs|j|dd�S)Nr)rG)�remove_lines)r-r.r/r0r0r1r2ss�PcCs|j|dd�S)Nr)r+)�remove_chars)r-r.r/r0r0r1r2ts�XcCs*|j|j|jd|dd|jdf�S)Nrr*)�erase�term_cursor)r-r.r/r0r0r1r2us�a�alias�ccCs
|j|�S)N)�csi_get_device_attributes)r-�noner/r0r0r1r2ys�dcCs|jd|dddd�S)Nrr*T)�
relative_x)r5)r-�rowr/r0r0r1r2zs�e�f�gcCs|j|d�S)Nr)�csi_clear_tabstop)r-rCr/r0r0r1r2}s�hcCs|j||�S)N)�
csi_set_modes)r-�modesr/r0r0r1r2~s�lcCs|j||dd�S)NT)�reset)r])r-r^r/r0r0r1r2s�mcCs
|j|�S)N)�csi_set_attr)r-�attrsr/r0r0r1r2�s�ncCs|j|d�S)Nr)�csi_status_report)r-rCr/r0r0r1r2�sr/cCs|j|d�S)Nr)�csi_set_keyboard_leds)r-rCr/r0r0r1r2�s�rcCs|j|d|d�S)Nrr*)�csi_set_scroll)r-Zt_br/r0r0r1r2�sr-cCs|j�S)N)�save_cursor)r-rTr/r0r0r1r2�s�ucCs|j�S)N)�restore_cursor)r-rTr/r0r0r1r2�s�`c@seZdZdd�Zdd�ZdS)�	TermModescCs|j�dS)N)r`)�selfr0r0r1�__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_charset)rnr0r0r1r`�szTermModes.resetN)�__name__�
__module__�__qualname__ror`r0r0r0r1rm�srmc@sJeZdZddddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)�TermCharsetN�0�U)�default�vt100�ibmpc�usercCsddg|_d|_|jd�dS)Nrr�Fr)�_g�_sgr_mapping�activate)rnr0r0r1ro�szTermCharset.__init__cCs||j|<|j|jd�dS)z1
        Redefine G'g' with new mapping.
        )rZN)r�r��active)rnrZ�charsetr0r0r1�define�s
zTermCharset.definecCs ||_|jj|j|d�|_dS)z2
        Activate the given charset slot.
        N)r��MAPPING�getr��current)rnrZr0r0r1r��szTermCharset.activatecCs
d|_dS)zA
        Set graphics rendition mapping to IBM PC CP437.
        TN)r�)rnr0r0r1�
set_sgr_ibmpc�szTermCharset.set_sgr_ibmpccCsd|_|j|jd�dS)zC
        Reset graphics rendition mapping to IBM PC CP437.
        F)rZN)r�r�r�)rnr0r0r1�reset_sgr_ibmpc�szTermCharset.reset_sgr_ibmpccCsT|js|j|jdkrLtj|jd��}|dkr@d|_tt|�Sd|_|Sn|SdS)Nr��cp437rr}r~)	r�r�r�r�find�decoder��strr)rn�charZdec_posr0r0r1�
apply_mapping�szTermCharset.apply_mapping)
ryrzr{r�ror�r�r�r�r�r0r0r0r1r|�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|jd�dS)Nr)�len�SCROLLBACK_LINES�pop)rnr0r0r1�trunc�szTermScroller.trunccs|j�tt|�j|�dS)N)r��superr��append)rn�obj)�	__class__r0r1r��szTermScroller.appendcs|j�tt|�j||�dS)N)r�r�r�r)rn�idxr�)r�r0r1r�szTermScroller.insertcs|j�tt|�j|�dS)N)r�r�r��extend)rn�seq)r�r0r1r��szTermScroller.extend)
ryrzr{�__doc__r�r�r�rr��
__classcell__r0r0)r�r1r��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)��
TermCanvasFcCsXtj|�|||_|_||_|j|_t�|_d|_	d|_
t�|_d|j
d<|j�dS)Nr�cursor)rrN)rro�width�height�widget�
term_modesr^r��scrollback_buffer�scrolling_up�utf8_eat_bytesr�utf8_bufferZcoordsr`)rnr�r�r�r0r0r1ro�s

zTermCanvas.__init__NcCsf|dkr|jd}|dkr$|jd}|j||�|_|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*)rO�constrain_coordsr^rvr�r�r�)rn�x�yr0r0r1�set_term_cursors

zTermCanvas.set_term_cursorcCsd|_|jd|_dS)z?
        Reset scrolling region to full terminal size.
        rr*N)�scrollregion_startr��scrollregion_end)rnr0r0r1�reset_scrollszTermCanvas.reset_scrollTcCsx|rd|_|j�dS|dkr(|jd}|s2|}t|j�}|j|7_|j|kr\||_n|jdkrld|_|j�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.
        rNr@)r�r�r�r�r�)rnrr`rGZ	maxscrollr0r0r1�
scroll_buffers



zTermCanvas.scroll_buffercCsZt�|_d|_d|_d|_t�|_d|_d|_d|_	|j
�|j�|jj
�|j�dS)z%
        Reset the terminal.
        FrN)r�escbuf�
within_escape�
parsestate�attrspecr|r��saved_cursor�saved_attrs�is_rotten_cursorr��
init_tabstopsr^r`�clear)rnr0r0r1r`9s
zTermCanvas.resetcCsVt|jd�\}}|dkr |d7}|rFx,t|j�|krB|jjd�q&Wndg||_dS)N�rr*r*r*)�divmodr�r��tabstopsr�)rnr�Ztablen�modr0r0r1r�SszTermCanvas.init_tabstopscCs�|r*x tt|j��D]}d|j|<qWdS|dkr<|jd}t|d�\}}|rh|j|d|>M<n|j|d|>O<dS)Nrr�r*)rr�r�rOr�)rnr��remover�r�divr�r0r0r1�set_tabstop^s
zTermCanvas.set_tabstopcCs6|dkr|jd}t|d�\}}|j|d|>@dkS)Nrr�r*)rOr�r�)rnr�r�r�r0r0r1�
is_tabstopms
zTermCanvas.is_tabstop� cCs|j|�g|jS)N)�
empty_charr�)rnr�r0r0r1�
empty_linetszTermCanvas.empty_linecCs|j|jj|fS)N)r�r�r�)rnr�r0r0r1r�wszTermCanvas.empty_charcCs8|jdks|jdkrdSx|D]}|jt|��qWdS)Nr)r�r��addbyter
)rn�data�byter0r0r1�addstrzs
zTermCanvas.addstrcCs�|j\}}||jkrLxlt|j�D]&}|j||j�g||j7<q Wn6||jkr�x*t|j�D]}|j|d|�|j|<qbW||_||jk�rBx�t|j|�D]�}y|jj�}Wn4tk
r�|jj	|j
��|jd7_w�YnXt|�|jk�r||j�g|jt|�7}n|d|j�}|d7}|jj
d|�q�Wn8||jk�rzx*t||j�D]}|jj	|jjd���q\W||_|j�|j||�\}}|j||�|jdd�dS)zD
        Resize the terminal to the given width and height.
        Nr*rT)r�)rOr�rr��termr�r�r��
IndexErrorr�r�r�r�rr�r�r�r�)rnr�r�r�r��	last_liner0r0r1�resize�s<

(

zTermCanvas.resizecCsr|jjtkrdS|td�kr"d}nd}|td�kr8d}n(|td�krJd}n|td	�kr\d
}nd}|jj||�dS)zF
        Set G0 or G1 according to 'char' and modifier 'mod'.
        N�(rr*r}r�r~r�rDr�r)r^rxrwrr�r�)rnr�r�rZZcsetr0r0r1�set_g01�szTermCanvas.set_g01cCs.|jjtd��}g}xX|j|r"dp$dd�jtd��D]4}yt|�}Wntk
r^d}YnX|j|�q6Wt|dk	�r*t|ddkr�tt|d}nt|}|\}}}	xt|�|kr�|j|�q�Wx4t	t|��D]$}
||
dks�||
dkr�|||
<q�Wy|	|||�Wntk
�r(YnXdS)zL
        Parse ECMA-48 CSI (Control Sequence Introducer) sequences.
        �?r*rN�;rQ)
r��
startswithr�split�int�
ValueErrorr��CSI_COMMANDSr�r)rnr��qmarkr��argZnumZcsi_cmdZnumber_of_argsZ
default_value�cmd�ir0r0r1�	parse_csi�s,&

zTermCanvas.parse_csicCsN|td�kr$|td�kr$|j��n&|td�kr\|td�krFt|j_n|td�krZt|j_n�|td�kst|td�kr�|j||�n�|td�kr�|jd	d
�n�|td�kr�|j�n�|td�kr�|j�n�|td
�kr�|j	�nl|td�kr�|j
�nV|td�k�r|jj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��)rIT)�reverser9rRr:r?�Zz[?6c�7)�
with_attrsN)r�decalnrwr^rx�CHARSET_UTF8r��linefeedr`�newliner�r��respond�ESCrirk)rnr�r�r0r0r1�parse_noncsi�s2





zTermCanvas.parse_noncsicCsJ|jtd��r$|jj|dd��n"|jtd��rF|jj|dd��dS)z1
        Parse operating system command.
        r�r*Nz3;r@)r�rr��	set_title)rn�bufr0r0r1�	parse_oscszTermCanvas.parse_osccCsZ|jdkr^|tj�kr(|j|�d|_n2|td�ksH|jrZ|td�krZ|j|7_dS�n�|jdkr�|td�kr�t�|_d|_dS|jdkr�|td�kr�|j|jjtd����n�|jdko�|jdd�|tt	d	�k�r|j|jdd�jtd����nL|jdk�r4|jj
td
���r4t|j�dk�r4�n|jdk�rZ|j�rZ|td�k�rZn�|jdk�rx|j|7_dS|jdk�r�|td
�k�r�t�|_d|_dS|jdk�r�|td�td�td�td�fk�r�||_d|_dS|jdk�r�|j||j�nP|td�td�td�td�td�td�td�td�td�td�f
k�rN|j|�|j
�dS)Nr*rz0123456789;r��]r@�r}�\rKr��R�[r�r�r�r��rRr9r:r?rIr�r�r��>�=���r�)r�r��keysr�rr�rr��lstripr�r�r�r��leave_escape)rnr�r0r0r1�parse_escapesH

 *"$.F
zTermCanvas.parse_escapecCsd|_d|_t�|_dS)NFr)r�r�rr�)rnr0r0r1r�HszTermCanvas.leave_escapecCs&d}x|d@r |dK}|d7}qW|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*r0)rnZbytenumZlengthr0r0r1�get_utf8_lenMs

zTermCanvas.get_utf8_lencCs�|jjtkstjdkr�|dkr8|j|�|_t|�|_dSd|koJdknr�|jdk	r�|jdkr�|jd8_|jt|�7_dSd|_|jt|�j	dd�}t
|�dkr�dS|jtjd	�}q�d|_t|�}nt|�}|j|�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)
r^rxr�rZ_target_encodingr�r�rr�r�r��encode�process_char)rnr�Zsequencer�r0r0r1r�\s(

"

zTermCanvas.addbytecCs�|j\}}t|t�rt|�}|jj}|td�krD|jdkrDd|_�n�|rb|td�krb|j	��nl|r�|td�kr�|j
jd��nJ|r�|td�kr�|j
jd��n(|r�|td	�kr�|j�|jj
r�|j	�n�|r�|td
�kr�|j�n�|o�|td�k�r|dk�r�|j|d|�n�|�rL|td�k�rL|jdk�rL|jj�n�|�rl|td
�k�rl|j�nb|�r�|td�k�r�nJ|j�r�|j|�n6|�r�|td�k�r�d|_t�|_d|_n
|j|�dS)ze
        Process a single character (single- and multi-byte).

        char -- a byte string
        �r@T�
�r�r*z
�	�r�zz�›N)rO�
isinstancer��chrr^rprr�r��carriage_returnr�r�r�rqrr�r��beepr�r�rr��push_cursor)rnr�r�r�Zdcr0r0r1r�sD





"
zTermCanvas.process_charcCsR|dkr|jd}|dkr$|jd}|j||�\}}|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*)rOr�r�r�r�r�)rnr�r�r�r0r0r1�set_char�s

zTermCanvas.set_charcCs~||jkr|jd}n|dkr"d}|jjrT|rT||jkrB|j}qv||jkrv|j}n"||jkrj|jd}n|dkrvd}||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�r^rtr�r�r�)rnr�r��ignore_scrollingr0r0r1r��s



zTermCanvas.constrain_coordscCs�|j\}}|rL|dko"|jknr*q�||jkrB|jdd�q�|d8}n>||jdkof|jknrnn||jkr�|j�n|d7}|j||�dS)zw
        Move the cursor down (or up if reverse is True) one line but don't reset
        horizontal position.
        rT)r�r*N)rOr��scrollr�r�r�)rnr�r�r�r0r0r1r��s


 

zTermCanvas.linefeedcCs|jd|jd�dS)Nrr*)r�rO)rnr0r0r1r�szTermCanvas.carriage_returncCs|j�|j�dS)z?
        Do a carriage return followed by a line feed.
        N)rr�)rnr0r0r1r��szTermCanvas.newlinecCsT|rd}}|r|jd|}|r2|jd|}n|jjrD||j7}|j||�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)rOr^rtr�r�)rnr�r�rVr;r4r0r0r1r5�s
zTermCanvas.move_cursorcCsD|dk	r4|jj|�}|jjr*|j|d�n
|j|�|j||�dS)zS
        Push one character to current position and advance cursor to x/y.
        N)r�)r�r�r^rr,rr�)rnr�r�r�r0r0r1�	push_chars
zTermCanvas.push_charcCs�|j\}}|jjr�|d|jkr>|jr>d|_|j|||�q�|d7}||jkr�|jr�||jkrj|j�n|d7}d}|jd|�|j|||�d|_n*|d|jkr�|d7}d|_|j|||�dS)z�
        Move cursor one character forward wrapping lines as needed.
        If 'char' is given, put the character into the former position.
        r*TrFN)	rOr^rur�r�rr�rr�)rnr�r�r�r0r0r1rs$


zTermCanvas.push_cursorcCs.t|j�|_|r*tj|j�tj|j�f|_dS)N)�tuplerOr��copyr�r�r�)rnr�r0r0r1ri=s
zTermCanvas.save_cursorcCs\|jdkrdS|j\}}|j||�|rX|jdk	rXtj|jd�tj|jd�|_|_dS)Nrr*)r�r�r�rr�r�)rnr�r�r�r0r0r1rkCs

zTermCanvas.restore_cursorr�cCsV|j\}}x4||jdkr>|jtd��|d7}|j|�rPqWd|_|j||�dS)zg
        Moves cursor to the next 'tabstop' filling everything in between
        with spaces.
        r*r�FN)rOr�rrr�r�r�)rnZtabstopr�r�r0r0r1rNs

zTermCanvas.tabcCsZ|r(|jj|j�|jj|j|j��n.|jj|j�}|jj|�|jj|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�)rnr�Zkilledr0r0r1r_szTermCanvas.scrollcCs(x"t|j�D]}|jd�|j|<qWdS)zB
        DEC screen alignment test: Fill screen with E's.
        r:N)rr�r�r�)rnrWr0r0r1r�oszTermCanvas.decalncCs|j�|j|<dS)zZ
        Blank a single line at the specified row, without modifying other lines.
        N)r�r�)rnrWr0r0r1�
blank_linevszTermCanvas.blank_liner*cCs~|dkr|j}|dkrd}|dkr,|j�}n|j|jj|f}|\}}x4|dkrx|j|j||�|j|j�|d8}qFWdS)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*)rOr�r�r�r�r�rr�)rn�positionr+r�r�r�r0r0r1r,|s

zTermCanvas.insert_charscCs`|dkr|j}|dkrd}|\}}x8|dkrZ|j|j|�|j|j|j��|d8}q$WdS)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*)rOr�r�r�r�)rnrr+r�r�r0r0r1rL�s
zTermCanvas.remove_charscCs`|dkr|jd}n|j}|dkr&d}x4|dkrZ|jj||j��|jj|j�|d8}q(WdS)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)rOr�r�rr�r�r�)rnrWrGr0r0r1rH�s
zTermCanvas.insert_linescCs`|dkr|jd}n|j}|dkr&d}x4|dkrZ|jj|�|jj|j|j��|d8}q(WdS)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)rOr�r�r�rr�r�)rnrWrGr0r0r1rJ�s
zTermCanvas.remove_linesc	Cs�|j|�\}}|j|�\}}||krRx(t||d�D]}|j�|j||<q4WdS|}x�||kr�||kr�xdt||j�D]}|j�|j||<qvWn<||kr�x2t|d�D]}|j�|j||<q�Wn
|j|�|d7}qXWdS)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�r)	rn�startr!ZsxZsy�exZeyr�r�r0r0r1rN�s 

zTermCanvas.erasecCs��xv|D�]l}d|ko dknr0|d}qd|koBdknrR|d}q|dkrj|jd�d}q|dkr�|jd�d}q|d	kr�d}q|d
kr�|jj�d|j_q|dkr�|jj�d|j_q|dkr�|jd�q|dkr�|jd�q|dk�r|jd�q|dk�r|jd�q|dk�r2|jd�q|dk�rH|jd�q|dk�r^|jd�q|dkrd}}|j�qWd|k�r�|dk	�r�|d7}dd�}||�}||�}t|�dk�r�dj	|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)Zcolorr0r0r1�
_defaulter&sz.TermCanvas.sgi_to_attrspec.<locals>._defaulter�,r)r%r&)�add�discardr�r�r^rpr�r�r��join�listr
)rnrc�fg�bg�
attributes�attrr/r0r0r1�sgi_to_attrspec�s\












zTermCanvas.sgi_to_attrspeccCs�|d
dkrd|_t�}|jdkr,d}}nzd|jjkr>d}n|jj}|dkrV|d8}d|jjkrhd}n|jj}|dkr�|d8}x$dD]}t|j|�s�q�|j|�q�W|j||||�}|j	j
r�|j|�|_n||_dS)z)
        Set graphics rendition.
        r*rNrr�r'r!r*r,r�)r'r!r*r,)r��set�
foregroundZforeground_numberZ
backgroundZbackground_number�getattrr1r9r^rs�reverse_attrspec)rnrcr7r5r6r8r�r0r0r1rb7s.


zTermCanvas.csi_set_attrcCst|dkrtdd�}dd�|jjd�D�}d|krL|rL|jd�dj|�|_n$d|krp|rp|jd�dj|�|_|S)zd
        Put standout mode to the 'attrspec' given and remove it if 'undo' is
        True.
        NrcSsg|]}|j��qSr0)�strip)�.0r5r0r0r1�
<listcomp>csz/TermCanvas.reverse_attrspec.<locals>.<listcomp>r0r,)r
r;r�r�r3r�)rnr��undorcr0r0r1r=\s


zTermCanvas.reverse_attrspeccCshxbt|j�D]T}xNt|j�D]@}|j||}|j|d|d�}|f|dd�|j||<qWqWdS)zP
        Reverse video/scanmode (DECSCNM) by swapping fg and bg colors.
        r)rAr*N)rr�r�r�r=)rnrAr�r�r�rcr0r0r1rsls
zTermCanvas.reverse_videocCs�|r�|dkr||j_q�|dkr(|j�q�|dkrT|jj|krJ|j|d�||j_q�|dkrr||j_|jdd�q�|dkr�||j_q�|dkr�||j_|j�n4|dkr�||j_n"|d	kr�||j_	n|d
kr�||j_
dS)zC
        Helper method for csi_set_modes: set single mode.
        r*r�r))rA�rr+r.r(�N)r^rrr�rsrtr�rurvrprrq)rnrC�flagr�r`r0r0r1�set_modevs.






zTermCanvas.set_modecCs(|}x|D]}|j||||�qWdS)zX
        Set (DECSET/ECMA-48) or reset modes (DECRST/ECMA-48) if reset is True.
        N)rE)rnr^r�r`rDrCr0r0r1r]�s
zTermCanvas.csi_set_modesrcCsx|dkrd}|dkr|j}||ko.|jknrt|jd|ddd�d|_|jd|ddd�d|_|jdd�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)rN)r�r�r�r�r�)rn�topZbottomr0r0r1rh�szTermCanvas.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�)rnrCr0r0r1r[�szTermCanvas.csi_clear_tabstopcCs|s|jjtd�dS)zz
        Report device attributes (what are you?). In our case, we'll report
        ourself as a VT102 terminal.
        z[?6cN)r�r�r�)rnr�r0r0r1rS�sz$TermCanvas.csi_get_device_attributescCsP|dkr|jjtd�n2|dkrL|j\}}|jjtd|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
        r)z[0nrBz[%d;%dRr*N)r�r�r�rO)rnrCr�r�r0r0r1re�s

zTermCanvas.csi_status_reportcCs`|j\}}|dkr,|j|j|jd|f�n0|dkrJ|jd|f||f�n|dkr\|j|�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*r@N)rOrNr�r)rnrCr�r�r0r0r1rE�s
zTermCanvas.csi_erase_linecCsj|dkr&|j|j|jd|jdf�|dkrP|jd|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*r@)r�N)rr)rNrOr�r�r�)rnrCr0r0r1rB�s"zTermCanvas.csi_erase_displaycCs*ddddd�}||kr&|jj||�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*r@r�N)r��leds)rnrCZstatesr0r0r1rf�sz TermCanvas.csi_set_keyboard_ledscs>�fdd�t�j�D��_|dkr0�jdd�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|]}�j��qSr0)r�)r?r�)rnr0r1r@
sz$TermCanvas.clear.<locals>.<listcomp>Nr)rr�r�r�)rnr�r0)rnr1r�szTermCanvas.clearcCs|jS)N)r�)rnr0r0r1r8szTermCanvas.colscCs|jS)N)r�)rnr0r0r1r6szTermCanvas.rowsccs\|jdkr"xL|jD]
}|VqWn6|j|j}x(||j|j|j�D]
}|VqJWdS)Nr)r�r�r�r�)rnZ	trim_leftZ
trim_rightr8r6Zattr_map�liner�r0r0r1�contents
 zTermCanvas.contentcCs"||kr|j�g|j�S|j�S)N)r8r6rI)rn�otherr0r0r1�
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)?ryrzr{Z	cacheableror�r�r�r`r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�rrr�r�rr�r5rrrirkrrr�rr,rLrHrJrNr9rbr=rsrEr]rhr[rSrerErBrfr�r8r6rIrKr0r0r0r1r��sz




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�closedrrG�titleNcCs�|jj�|dkrd|_n||_|dkr6ttj�|_n
t|�|_|dkr\|jjdd�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 a�SHELLz/bin/shF)Z_Terminal__superro�escape_sequence�dict�os�environ�envr��command�keygrab�last_key�response_bufferrmr��	main_loop�master�pidr�r�r��	has_focus�
terminated)rnrUrTrYrPr0r0r1ro/s,

zTerminal.__init__cCs�|j}d|d<tj�\|_|_|jdkr�t|j�rzz8y|j�Wn&tjj	t
j��tjj�YnXWdt
jd�Xnt
j|jd|j|�|jdkr�tj|jtjt
j�tj|j�dS)N�linuxZTERMr)rT�pty�forkr[rZ�callablerU�sys�stderr�write�	traceback�
format_exc�flushrR�_exit�execvperY�fcntlZF_SETFL�
O_NONBLOCK�atexit�register�	terminate)rnrTr0r0r1�spawnes 


zTerminal.spawncCs�|jr
dSd|_|j�|jd�|jdkr�|jdd�xrtjtjtjtj	tj
fD]V}y&tj|j|�tj
|jtj�\}}Wntk
r�PYnX|dkr�Ptjd�qRWytj
|jd�Wntk
r�YnXtj|j�dS)NTFrg�������?)r]�remove_watch�change_focusr[�set_termsize�signal�SIGHUP�SIGCONT�SIGINT�SIGTERM�SIGKILLrR�kill�waitpid�WNOHANG�OSError�timeZsleep�closerZ)rnZsigr[Zstatusr0r0r1rn}s,

zTerminal.terminatecCs|jd�dS)Nr)�_emit)rnr0r0r1r�sz
Terminal.beepcCs|jd|�dS)NrG)r)rnZwhichr0r0r1rG�sz
Terminal.ledscCs|jj|�dS)zF
        Respond to the underlying application with 'string'.
        N)rXr�)rn�stringr0r0r1r��szTerminal.respondcCs.x"|jD]}tj|j|jd��qWg|_dS)N�ascii)rXrRrdrZr)rnr�r0r0r1�flush_responses�szTerminal.flush_responsescCs(tjd||dd�}tj|jtj|�dS)NZHHHHr)�structZpackrjZioctlrZ�termiosZ
TIOCSWINSZ)rnr�r�Zwinsizer0r0r1rr�szTerminal.set_termsizecCs~d}|jdkr|j�d}|j|kr2|j|kr2dS|j||�|jsTt|||�|_n|jj||�||_||_|rz|j�dS)NFT)	r[ror�r�rrr�r�r��	add_watch)rnr�r�Zprocess_openedr0r0r1�
touch_term�s
zTerminal.touch_termcCs|jd|�dS)NrN)r)rnrNr0r0r1r��szTerminal.set_titlecCsP|js|j|krdS||_|r>t�j�|_t�jdgd�nt�j|j�dS)z9
        Ignore SIGINT if this widget has focus.
        NZ	undefinedr))r]r\rZtty_signal_keysZold_tios)rnr\r0r0r1rq�szTerminal.change_focusFcCs<|js6|j|�|\}}|j||�|jdkr6|j�|jS)N)r]rqr�rY�feedr�)rn�sizeZfocusr�r�r0r0r1�render�s

zTerminal.rendercCs$|jdkrdS|jj|j|j�dS)N)rYZ
watch_filerZr�)rnr0r0r1r��s
zTerminal.add_watchcCs |jdkrdS|jj|j�dS)N)rYZremove_watch_filerZ)rnr0r0r1rp�s
zTerminal.remove_watchcCsdS)NTr0)rnr0r0r1�
selectable�szTerminal.selectable��?cCsbxTytj|jggg|�PWqtjk
rP}z|jddkr@�WYdd}~XqXqW|j�dS)Nrr()�selectrZ�error�argsr�)rnZtimeoutrXr0r0r1�
wait_and_feed�szTerminal.wait_and_feedcCs�d}ytj|jd�}WnDtk
rZ}z(|jdkr8d}n|jtjkrHdS�WYdd}~XnX|dkrz|j�|jd�dS|jj	|�|j
�dS)N�ir)rM)rR�readrZr|�errnoZEWOULDBLOCKrnrr�r�r�)rnr�rXr0r0r1r��s

z
Terminal.feedcCs�|jr
|S|dkr*|\}}|j||�dS|j|jkrN||jkrN||_d|_n�|jrp|j|krnd|_||_dSn�|dkr�|jj�||_|j�dS|dkr�|jjdd�||_|j�dS|j|jkr�||jkr�||_|S|j|kr�d|_||_dS|j|dk�s|dk�rd|_n
||_|S||_|jjdd�|j	d	��r�|dj
��rntt|d�td�d
�}ntt|d�td�d
�}n,|j
j�r�|tk�r�tj|�}ntj||�}|j
j�r�|d
k�r�|d7}t�r�|jd�}tj|j|�dS)Nz
window resizeTFzpage upz	page down)rr)r`zctrl r*rPr3r�
r�r�r�r�)r]r�rWrPrVr�r�Z_invalidateZ_command_mapr��islowerr�ordr�rr�KEY_TRANSLATIONS_DECCKMr��KEY_TRANSLATIONSrqrrrRrdrZ)rnr��keyr�r�r0r0r1�keypresssf





zTerminal.keypress)NNN)F)r�)ryrzr{Z_selectable�	frozensetr	Z_sizingZsignalsrorornrrGr�r�rrr�r�rqr�r�rpr�r�r�r�r0r0r0r1rL)s*

6


rL)4Z
__future__rrrRrbr}rr�r�r�rsrlrer_rjr��ImportErrorZurwidrZurwid.escaperrZurwid.canvasrZurwid.widgetrr	Zurwid.display_commonr
rrZurwid.compatr
rrrrrrr�r�r�r�rwr��objectrmr|r4r�r�rLr0r0r0r1�<module>s� 9A

Zerion Mini Shell 1.0