Current Dir: /snap/core22/2437/usr/lib/python3/dist-packages/urwid/__pycache__/

[FILE] canvas.cpython-310.pyc [ edit | delete | rename ]
[FILE] command_map.cpython-310.pyc [ edit | delete | rename ]
[FILE] compat.cpython-310.pyc [ edit | delete | rename ]
[FILE] container.cpython-310.pyc [ edit | delete | rename ]
[FILE] curses_display.cpython-310.pyc [ edit | delete | rename ]
[FILE] decoration.cpython-310.pyc [ edit | delete | rename ]
[FILE] display_common.cpython-310.pyc [ edit | delete | rename ]
[FILE] escape.cpython-310.pyc [ edit | delete | rename ]
[FILE] font.cpython-310.pyc [ edit | delete | rename ]
[FILE] graphics.cpython-310.pyc [ edit | delete | rename ]
[FILE] html_fragment.cpython-310.pyc [ edit | delete | rename ]
[FILE] lcd_display.cpython-310.pyc [ edit | delete | rename ]
[FILE] listbox.cpython-310.pyc [ edit | delete | rename ]
[FILE] main_loop.cpython-310.pyc [ edit | delete | rename ]
[FILE] monitored_list.cpython-310.pyc [ edit | delete | rename ]
[FILE] numedit.cpython-310.pyc [ edit | delete | rename ]
[FILE] old_str_util.cpython-310.pyc [ edit | delete | rename ]
[FILE] raw_display.cpython-310.pyc [ edit | delete | rename ]
[FILE] signals.cpython-310.pyc [ edit | delete | rename ]
[FILE] split_repr.cpython-310.pyc [ edit | delete | rename ]
[FILE] text_layout.cpython-310.pyc [ edit | delete | rename ]
[FILE] treetools.cpython-310.pyc [ edit | delete | rename ]
[FILE] util.cpython-310.pyc [ edit | delete | rename ]
[FILE] version.cpython-310.pyc [ edit | delete | rename ]
[FILE] vterm.cpython-310.pyc [ edit | delete | rename ]
[FILE] web_display.cpython-310.pyc [ edit | delete | rename ]
[FILE] widget.cpython-310.pyc [ edit | delete | rename ]
[FILE] wimp.cpython-310.pyc [ edit | delete | rename ]
[FILE] _async_kw_event_loop.cpython-310.pyc [ edit | delete | rename ]
[FILE] __init__.cpython-310.pyc [ edit | delete | rename ]

Viewing: /snap/core22/2437/usr/lib/python3/dist-packages/urwid/__pycache__/raw_display.cpython-310.pyc

o

��o_��@sddlmZmZ	ddlZddlZddlZddlZddlZzddlZddl	Z	ddl
Z
Wn	ey4Ynwddlm
Z
ddlmZddlmZmZmZmZmZmZddlmZddlmZmZmZddlmZmZGd	d
�d
ee�Zdd�Ze d
kre�dSdS)�)�division�print_functionN)�util)�escape)�
BaseScreen�RealTerminal�UPDATE_PALETTE_ENTRY�AttrSpec�UNPRINTABLE_TRANS_TABLE�INPUT_DESCRIPTORS_CHANGED)�signals)�PYTHON3�bytes�B)�Popen�PIPEcs�eZdZejejf�fdd�	Zdd�Zdd�Z		dTd	d
�Z	dUdd�Z
dUd
d�Zdd�Zdd�Z
dVdd�Zdd�Zdd�Zdd�ZdV�fdd�	Z�fdd�Zd d!�Zd"d#�ZdWd%d&�Zd'd(�Zd)Zd*d+�Zd,d-�ZdZdZd.d/�Zd0d1�ZdVd2d3�Zd4d5�Z d6d7�Z!d8d9�Z"d:d;�Z#d<d=�Z$d>d?�Z%d@dA�Z&dBdC�Z'dDdE�Z(dFdG�Z)dHdI�Z*dJdK�Z+		dXdLdM�Z,dNdO�Z-dPdQ�Z.dRdS�Z/�Z0S)Y�Screencstt|���i|_i|_t�|t|j�d|_	d|_
g|_d|_|�
�d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_tj�dd�|_|j�d�|_|jd	k|_|j�d
�|_ |�!ddd�d|_"t#j#|_$||_%||_&t�'�\|_(|_)t*�*|j(t*j+tj,�dS)z]Initialize a screen that directly prints escape codes to an output
        terminal.
        �TrNF�TERM��xterm�linux�screen�default)-�superr�__init__�_pal_escape�
_pal_attrspecr�connect_signalr�_on_update_palette_entry�colors�
has_underline�	_keyqueue�prev_input_resize�set_input_timeouts�
screen_buf�_screen_buf_canvas�_resized�maxrow�gpm_mev�gpm_event_pending�_mouse_tracking_enabled�last_bstate�_setup_G1_done�
_rows_used�_cy�os�environ�get�term�
startswith�fg_bright_is_bold�bg_bright_is_blink�back_color_erase�register_palette_entry�
_next_timeout�signal�signal_handler_setter�_term_output_file�_term_input_file�pipe�_resize_pipe_rd�_resize_pipe_wr�fcntl�F_SETFL�
O_NONBLOCK)�self�input�output��	__class__��3/usr/lib/python3/dist-packages/urwid/raw_display.pyr5sB�zScreen.__init__cCst|jd�r|j��SdS)z�Returns the fileno of the input stream, or None if it doesn't have one.  A stream without a fileno can't participate in whatever.
        �filenoN)�hasattrr=rK�rDrIrIrJ�
_input_fileno^s
zScreen._input_filenocGs8|dddddd�|j}||j|<|�|�|j|<dS)Nr����)rrO�X��)r r�_attrspec_to_escaper)rD�name�	attrspecs�arIrIrJrfs
zScreen._on_update_palette_entryN��?cCs@||_|dur|jdur||_nt|j|j�|_||_||_dS)a�
        Set the get_input timeout values.  All values are in floating
        point numbers of seconds.

        max_wait -- amount of time in seconds to wait for input when
            there is no input pending, wait forever if None
        complete_wait -- amount of time in seconds to wait when
            get_input detects an incomplete escape sequence at the
            end of the available input
        resize_wait -- amount of time in seconds to wait for more input
            after receiving two screen resize requests in a row to
            stop Urwid from consuming 100% cpu during a gradual
            window resize operation
        N)�max_waitr9�min�
complete_wait�resize_wait)rDr[r]r^rIrIrJr$ls

zScreen.set_input_timeoutscCs(|jst�|jtd��d|_d|_dS)�V
        frame -- will always be None when the GLib event loop is being used.
        �RTN)r'r0�writer@rr%�rD�signum�framerIrIrJ�_sigwinch_handler�s
zScreen._sigwinch_handlercCs |��|��|�dd�dS)r_N)�stop�startrerbrIrIrJ�_sigcont_handler�szScreen._sigcont_handlercCs$|�tj|j�|�tj|j�dS)z�
        Called in the startup of run wrapper to set the SIGWINCH
        and SIGCONT signal handlers.

        Override this function to call from main thread in threaded
        applications.
        N)r;r:�SIGWINCHre�SIGCONTrhrMrIrIrJ�signal_init��zScreen.signal_initcCs$|�tjtj�|�tjtj�dS)z�
        Called in the finally block of run wrapper to restore the
        SIGWINCH and SIGCONT signal handlers.

        Override this function to call from main thread in threaded
        applications.
        N)r;r:rj�SIG_DFLrirMrIrIrJ�signal_restore�rlzScreen.signal_restoreTcCs*t|�}||jkrdS|�|�||_dS)z�
        Enable (or disable) mouse tracking.

        After calling this function get_input will include mouse
        click events along with keystrokes.
        N)�boolr+�_mouse_tracking�rD�enablerIrIrJ�set_mouse_tracking�s



zScreen.set_mouse_trackingcCs4|r|�tj�|��dS|�tj�|��dS�N)rar�MOUSE_TRACKING_ON�_start_gpm_tracking�MOUSE_TRACKING_OFF�_stop_gpm_trackingrqrIrIrJrp�s
zScreen._mouse_trackingcCsjtj�d�sdStj�dd����d�sdStsdStgd�ttdd�}t	�	|j
��t	jtj
�||_dS)N�/usr/bin/mevrrr)ryz-e�158T)�stdin�stdout�	close_fds)r0�path�isfiler1r2�lowerr4rrrAr|rKrBrCr))rD�mrIrIrJrv�s�
zScreen._start_gpm_trackingcCs6|jsdSt�|jjtj�t�|jjd�d|_dS�Nr)r)r0�kill�pidr:�SIGINT�waitpidrMrIrIrJrx�s

zScreen._stop_gpm_trackingcs�|r|�tj�d|_nd|_|��}|dur't�|�r't�|�|_	t
�|�|��||_
|j|_|js<|j|d�|_t�|t�|�|j�tt|���S)zp
        Initialize the screen and input mode.

        alternate_buffer -- use alternate screen buffer
        Nr)rK)rar�SWITCH_TO_ALTERNATE_BUFFERr.rNr0�isatty�termios�	tcgetattr�_old_termios_settings�tty�	setcbreakrk�_alternate_bufferr[r9�_signal_keys_set�tty_signal_keys�_old_signal_keysr�emit_signalrrpr+rr�_start)rD�alternate_buffer�fdrGrIrJr��s 
z
Screen._startcs�|��t�|t�|��|��}|dur$t�|�r$t�	|tj
|j�|�d�d}|j
r2tj}n|jdur>t�d|j�}|�|�tdd��tj|tj�|��|jra|j|j|f�tt|���dS)z%
        Restore the screen.
        NFrr)�clearrr�rrnrNr0r�r��	tcsetattr�	TCSADRAINr�rpr�r�RESTORE_NORMAL_BUFFERr(�set_cursor_positionrarVr	�SI�SHOW_CURSOR�flushr�r�rr�_stop)rDr��move_cursorrGrIrJr��s6

�����zScreen._stopcCs|j�|�dS)z�Write some data to the terminal.

        You may wish to override this if you're using something other than
        regular files for input and output.
        N)r<ra)rD�datarIrIrJraszScreen.writecCs|j��dS)z�Flush the output buffer.

        You may wish to override this if you're using something other than
        regular files for input and output.
        N)r<r�rMrIrIrJr� szScreen.flushFcCs�|jsJ�|�|j�|�dd|���\}}|dgkrI|jrI	|�|j�|�dd|���\}}||7}|dgkr:nq|dd�dgkrI|�d�|dgkrRd|_n|jdkr]|s]d|_nd|_|rf||fS|S)axReturn pending input as a list.

        raw_keys -- return raw keycodes as well as translated versions

        This function will immediately return all the input since the
        last time it was called.  If there is no input pending it will
        wait before returning an empty list.  The wait time may be
        configured with the set_input_timeouts function.

        If raw_keys is False (default) this function will return a list
        of keys pressed.  If raw_keys is True this function will return
        a ( keys pressed, raw keycodes ) tuple instead.

        Examples of keys returned:

        * ASCII printable characters:  " ", "a", "0", "A", "-", "/"
        * ASCII control characters:  "tab", "enter"
        * Escape sequences:  "up", "page up", "home", "insert", "f1"
        * Key combinations:  "shift f1", "meta a", "ctrl b"
        * Window events:  "window resize"

        When a narrow encoding is not enabled:

        * "Extended ASCII" characters:  "\xa1", "\xb2", "\xfe"

        When a wide encoding is enabled:

        * Double-byte characters:  "\xa1\xea", "\xb2\xd4"

        When utf8 encoding is enabled:

        * Unicode characters: u"\u00a5", u'\u253c"

        Examples of mouse events returned:

        * Mouse button press: ('mouse press', 1, 15, 13),
                              ('meta mouse press', 2, 17, 23)
        * Mouse drag: ('mouse drag', 1, 16, 13),
                      ('mouse drag', 1, 17, 13),
                      ('ctrl mouse drag', 1, 18, 13)
        * Mouse button release: ('mouse release', 0, 18, 13),
                                ('ctrl mouse release', 0, 17, 23)
        N�
window resizeT���rPrOr)�_started�_wait_for_input_readyr9�parse_input�get_available_raw_inputr#r^�append)rD�raw_keys�keys�raw�raw2rIrIrJ�	get_input(s*
,
�


zScreen.get_inputcCsL|jsgS|jg}|��}|dur|�|�|jdur$|�|jj���|S)aG
        Return a list of integer file descriptors that should be
        polled in external event loops to check for user input.

        Use this method if you are implementing your own event loop.

        This method is only called by `hook_event_loop`, so if you override
        that, you can safely ignore this.
        N)r�r?rNr�r)r|rK)rD�fd_listr�rIrIrJ�get_input_descriptorsss


zScreen.get_input_descriptorsrIcCs6|jD]}|�|�q|jr|�|j�d|_dSdS)z<
        Remove any hooks added by hook_event_loop.
        N)�_current_event_loop_handles�remove_watch_file�_input_timeout�remove_alarm)rD�
event_loop�handlerIrIrJ�unhook_event_loop�s

�zScreen.unhook_event_loopcsNt�d�r������n���fdd�����}��fdd�|D�}|�_dS)a)
        Register the given callback with the event loop, to be called with new
        input whenever it's available.  The callback should be passed a list of
        processed keys and a list of unprocessed keycodes.

        Subclasses may wish to use parse_input to wrap the callback.
        �get_input_nonblockingcs��������Srt)r�r�rI)�callbackr�rDrIrJ�<lambda>�s
�z(Screen.hook_event_loop.<locals>.<lambda>csg|]}��|���qSrI)�
watch_file)�.0r�)r��wrapperrIrJ�
<listcomp>�sz*Screen.hook_event_loop.<locals>.<listcomp>N)rL�_make_legacy_input_wrapperr�r�)rDr�r��fds�handlesrI�r�r�rDr�rJ�hook_event_loop�s

zScreen.hook_event_loopcs����fdd���S)zs
        Support old Screen classes that still have a get_input_nonblocking and
        expect it to work.
        csJ�jr���j�d�_���\}}}|dur��|���_�||�dSrt)r�r�r��alarm)�timeoutr�r�r�rIrJr��sz2Screen._make_legacy_input_wrapper.<locals>.wrapperrI)rDr�r�rIr�rJr��s
z!Screen._make_legacy_input_wrappercCsL|��|��}|jr|j|}d|_zt�|jd�qty%Y|Sw)z�
        Return any currently-available input.  Does not block.

        This method is only used by the default `hook_event_loop`
        implementation; you can safely ignore it if you implement your own.
        NTrO)�_get_gpm_codes�_get_keyboard_codes�_partial_codesr0�readr?�OSError)rD�codesrIrIrJr��s
�zScreen.get_available_raw_inputcs��jr�r���j�d�_�}g}z�r$t��|�\}�|�|��sWn.tjySt|�t��}|d|�}	��_����fdd�}
�rQ���j	|
��_Ynw|}	d�_�j
rd|�d�d�_
�rm�||	�dS||	fS)a
        Read any available input from get_available_raw_input, parses it into
        keys, and calls the given callback.

        The current implementation tries to avoid any assumptions about what
        the screen or event loop look like; it only deals with parsing keycodes
        and setting a timeout when an incomplete one is detected.

        `codes` should be a sequence of keycodes, i.e. bytes.  A bytearray is
        appropriate, but beware of using bytes, which only iterates as integers
        on Python 3.
        Ncs"d�_d�_�j���dd�dS)NF)�
wait_for_more)r�r�r�rI�r�r�r�rDrIrJ�_parse_incomplete_input�s

�z3Screen.parse_input.<locals>._parse_incomplete_inputr�F)r�r�r�process_keyqueue�extend�MoreInputRequired�lenr�r�r]r'r�)rDr�r�r�r��original_codes�	processed�run�k�processed_codesr�rIr�rJr��s@
�
�����
zScreen.parse_inputcCs(g}	|��}|dkr	|S|�|�q)NTr)�_getch_nodelayr�)rDr��coderIrIrJr�s
��zScreen._get_keyboard_codesc
Cs�g}z#|jdur|jr#|�|���|jdur |jsW|SW|SW|SW|Sty@}z|jddkr5�WYd}~|Sd}~ww)Nr�)r)r*r��_encode_gpm_event�IOError�args)rDr��erIrIrJr�s&�����
���zScreen._get_gpm_codesc
Cs�d}g}|��}|dur|�|�|jdur|�|jj���	z|dur2t�|g|�\}}}W|St�|g||�\}}}W|Stjyf}z|jddkrP�|jr\g}WYd}~|SWYd}~nd}~wwq )NTrrR)	rNr�r)r|rK�select�errorr�r')rDr��readyr�r��w�errr�rIrIrJr�s>


��
��
����zScreen._wait_for_input_readycCsV|�|�}|jdur|jj��|vrd|_|��}|dur)||vr)tt�|d��SdS)NTrOr�)	r�r)r|rKr*rN�ordr0r�)rDr�r�r�rIrIrJ�_getch4s

z
Screen._getchcsrd|_|jj���d�}|�d��t��dkr#|��t�	|t
�gS|�d�\}��}�}t|�d�dd�}t��d�d��t����d�d	��t��d�d��t|�d�d�
�d�}|j�}g�d	�|d
@rr�dO�|d@rz�d
O�|d@r��dO�����fdd�����fdd�}|dks�|dks�|dkrֈd@r��d
@d	kr��d	�|d
O}�d@rÈd@d	krÈd
�|dO}�d
@rՈd@d	krՈd�|dO}ng|dkr��d@r�d	tj�nW�d@r�d
tj�nK�d
@r��dtj�n?�d@�r�d
@�r�d	tj�|dM}�d@�r(�d@�r(�d
tj�|dM}�d
@�r=�d@�r=�dtj�|dM}|dk�rv�d@�rS�d
@�rS�d	tj��d@�rd�d@�rd�d
tj��d
@�ru�d@�ru�dtj�n>|dk�r��d@�r��d
@�r��d	tjd��d@�r��d@�r��d
tjd��d
@�r��d@�r��dtjd�||_�S)NF�ascii�,��xr�r� rrOrR�
�c	s6|�O}��dtd�td�|d�d�dg�dS)N��[�M� )r�r�)�b)�l�modr��yrIrJ�
append_buttonXs.z/Screen._encode_gpm_event.<locals>.append_buttoncsx�d@r�d@r�d|�|dO}�d@r$�d@r$�d|�|dO}�d@r8�d@r:�d|�|dO}dSdSdS)NrRrOrrPrI)�flag�next)r�r��lastrIrJ�determine_button_release\s�z:Screen._encode_gpm_event.<locals>.determine_button_release��$�4rP�����������()r*r)r|�readline�decode�splitr�rxrr�r�int�lstrip�rstripr,r�MOUSE_DRAG_FLAG�MOUSE_RELEASE_FLAG�MOUSE_MULTIPLE_CLICK_FLAG)rD�s�ev�ignr�r�r�rI)r�r�r�r�r�r�r�rJr�>s�

��
�
zScreen._encode_gpm_eventcCs
|�d�Sr�)r�rMrIrIrJr��s
zScreen._getch_nodelaycCs`d\}}zt|jd�rt�|j��tjd�}t�d|�\}}Wn	t	y(Ynw||_
||fS)z7Return the terminal dimensions (num columns, num rows).)��PrKz    �hh)rLr<rA�ioctlrKr��
TIOCGWINSZ�struct�unpackr�r()rDr�r��bufrIrIrJ�
get_cols_rows�s���zScreen.get_cols_rowscCsD|jrdS	z|�tj�|��Wn
tyYnwqd|_dS)zO
        Initialize the G1 character set to graphics mode if required.
        NT)r-rar�DESIGNATE_G1_SPECIALr�r�rMrIrIrJ�	_setup_G1�s��
zScreen._setup_G1c!
s`|\}}�js	J�||��ksJ��jr|�jurdS����jr$dStj��t	dd��g}�fdd����s>|�
tj��jrE�j}ng}g}�j�d}��fdd�}	��fdd	�}
��fd
d�}dd
�}�fdd�}
�fdd�}d}|�
|	��d�|�
�D�]J}|d7}|r�|t|�kr�|||kr�|�
||�q�|�
|���r�|�jkr�||�r�q�|�_|s���r�|�
|d|��|�d}|�r|d\}}}|dd�td�kr�jr�||�s�d}|dd�|||�td��fg}n||dk�r|dk�r��|�\}}}d}d}}|D]n\}}}t|t��sJ�|dk�r&|�t�}|�s.||k�r7|�
|
|��|}|�s?||k�ru|dv�sJJt|���|dk�rU|�
tj�|du�ra|�
tj�n|dk�rm|�
tj�n|�
tj�|}|�
|�d}�q|�r�|\}}}|
|�}|dv�s�Jt|���|du�r�tj}n|dk�r�tj}ntj}|d|||tj|tjg7}|dk�r�|�
tj�|�r�|�
tj�q�|j du�r�|j \}}||||�tj!g7}|�_�j�r�dSz |D]}t|t��r�t"�r�|�#dd�}��$|��q��%�Wnt&�y'} z| j'ddk�r�WYd} ~ nd} ~ ww|�_|�_dS)z"Paint screen with rendered canvas.Nrcs
�jduSrt)r.rIrMrIrJ�partial_display�s
z+Screen.draw_screen.<locals>.partial_displayr�cs"��s	t�dd�Stjt���Sr�)rr��CURSOR_HOME_COL�move_cursor_uprI��cyrrIrJ�set_cursor_home�s
�z+Screen.draw_screen.<locals>.set_cursor_homecs ��s	t�d|�St�|��Sr�)rr��move_cursor_down)r�rrIrJ�set_cursor_row�sz*Screen.draw_screen.<locals>.set_cursor_rowcs^��s	t�||�S�|krdtjt��|�t�|�Sdtjt�|��t�|�S)N�)rr�rr�move_cursor_rightr)r�r�rrIrJr��s����z/Screen.draw_screen.<locals>.set_cursor_positioncSs(t|�dkrdS|dd��rdSdS)NrOFrrPT)r��strip)�rowrIrIrJ�is_blank_row�s
z(Screen.draw_screen.<locals>.is_blank_rowcs8|�jvr
�j|St|t�r��|�S��tdd��S)Nr)r�
isinstancer	rV�rYrMrIrJ�attr_to_escape�s



�z*Screen.draw_screen.<locals>.attr_to_escapecs$�j�||�}t|t�o|jp|jSrt)rr2r$r	�standout�	underliner%rMrIrJ�using_standout_or_underlinesz7Screen.draw_screen.<locals>.using_standout_or_underlinerrOFr�T�U)N�0r*rzutf-8�replacerR)(r��rowsr%r&rr'r�HIDE_CURSORrVr	r��CURSOR_HOMEr/�contentr�r.rr7r�	_last_rowr$r�	translater
�repr�	IBMPC_OFFr��IBMPC_ON�SO�	INSERT_ON�
INSERT_OFF�ERASE_IN_LINE_RIGHT�cursorr�r
rrar�r�r�)!rD�maxres�r�maxcolr(�o�osb�sbr�rrr�r#r&r)�insr"�whitespace_at_endrY�csr��back�first�lasta�lastcs�inserta�insertcs�
inserttext�ias�icssr�r�r�rI)rrrDrJ�draw_screen�s�



�$








�
�

����
zScreen.draw_screencCsP|dd�}|d\}}}t�|dt|��}t�|dt|�|d�\}}|dkrd|}	|d=|d\}
}}t�|dt|��}
||
7}t�|dt|�|
d�\}}||d�}|rc|�|
||d|�f�n2||d�}	||}
}t�|d|�}
t�|d||
d�\}}|||�}|r�|�|
||d|�f�|�|||	f�||||
||ffS)aOn the last row we need to slide the bottom right character
        into place. Calculate the new line, attr and an insert sequence
        to do that.

        eg. last row:
        XXXXXXXXXXXXXXXXXXXXYZ

        Y will be drawn after Z, shifting Z into position.
        Nr�rrOr�)r�
calc_widthr��
calc_text_posr�)rDr"�new_row�z_attr�z_cs�	last_text�	last_cols�	last_offs�z_col�z_text�y_attr�y_cs�
nlast_text�
nlast_cols�
nlast_offs�y_col�y_textrIrIrJr1osL���
��
��
�zScreen._last_rowcCsd|_d|_dS)zh
        Force the screen to be completely repainted on the next
        call to draw_screen().
        NT)r%�setup_G1rMrIrIrJr��s
zScreen.clearcCs�|jdkrtjd|jf}tjd|jf}||S|jr)d|��dd�}n2|jr2d|j}n)|jrY|jdkrQ|j	rGd	|jd
d}nd|jd
d
}n
d|jd}nd}d|j
d|jd|jd|j
d|jd|j}|jr�d|��dd�}n2|jr�d|j}n)|jr�|jdkr�|jr�d|jd
d}nd|jd
d}n
d|jd}nd}tjd|||fS)ao
        Convert AttrSpec instance a to an escape sequence for the terminal

        >>> s = Screen()
        >>> s.set_terminal_properties(colors=256)
        >>> a2e = s._attrspec_to_escape
        >>> a2e(s.AttrSpec('brown', 'dark green'))
        '\x1b[0;33;42m'
        >>> a2e(s.AttrSpec('#fea,underline', '#d0d'))
        '\x1b[0;38;5;229;4;48;5;164m'
        �fbtermz[1;%d}z[2;%d}z
38;2;%d;%d;%drrQz38;5;%d�z1;%dr��z%d�Z�39z1;z3;z4;z5;z7;z9;z
48;2;%d;%d;%dr�z48;5;%dz5;%dr��d�49z[0;%s;%s%sm)r3r�ESC�foreground_number�background_number�foreground_true�get_rgb_values�foreground_high�foreground_basicr5�bold�italicsr(�blinkr'�
strikethrough�background_true�background_high�background_basicr6)rDrY�fg�bg�strIrIrJrV�sH

����
zScreen._attrspec_to_escapecCs�|dur|j}|dur|j}|dur|j}||jkr&||jkr&||jkr&dS||_||_||_|��i|_|j��D]
\}}|j|g|�R�q;dS)a
        colors -- number of colors terminal supports (1, 16, 88, 256, or 2**24)
            or None to leave unchanged
        bright_is_bold -- set to True if this terminal uses the bold
            setting to create bright colors (numbers 8-15), set to False
            if this Terminal can create bright colors without bold or
            None to leave unchanged
        has_underline -- set to True if this terminal can use the
            underline setting, False if it cannot or None to leave
            unchanged
        N)r r5r!r�r�_palette�itemsr)rDr �bright_is_boldr!�p�vrIrIrJ�set_terminal_properties�s"

�zScreen.set_terminal_propertiescsZ|jdkrdS|jdkrd�n|j��fdd���fdd�tt�d��D�}|�|�dS)	z�
        Attempt to set the terminal palette to default values as taken
        from xterm.  Uses number of colors from current
        set_terminal_properties() screen setting.
        rONrUrTcs:�dkr
td|dd�}ntd|d��}|��dd�S)Nrzh%drrTrQ)r	rk)�n�aspec)r rIrJ�
rgb_valuessz9Screen.reset_default_terminal_palette.<locals>.rgb_valuescsg|]	}|f�|��qSrIrI)r�r~)r�rIrJr�sz9Screen.reset_default_terminal_palette.<locals>.<listcomp>)r �ranger\�modify_terminal_palette)rD�entriesrI)r r�rJ�reset_default_terminal_palette�s

z%Screen.reset_default_terminal_palettecCsd|jdkrdd�|D�}|�dd�|�d�ndd�|D�}|�dd�|�d	�|��d
S)a�
        entries - list of (index, red, green, blue) tuples.

        Attempt to set part of the terminal palette (this does not work
        on all terminals.)  The changes are sent as a single escape
        sequence so they should all take effect at the same time.

        0 <= index < 256 (some terminals will only have 16 or 88 colors)
        0 <= red, green, blue < 256
        r`cS�$g|]\}}}}d||||f�qS)z%d;%d;%d;%drI�r��index�red�green�bluerIrIrJr�#�
�z2Screen.modify_terminal_palette.<locals>.<listcomp>z[3;�;�}cSr�)z%d;rgb:%02x/%02x/%02xrIr�rIrIrJr�'r�z]4;z\N)r3ra�joinr�)rDr��modifyrIrIrJr�s
��zScreen.modify_terminal_palettecCst|||j�Srt)r	r )rDrurvrIrIrJr�/szScreen.<lambda>)NrZrZrt)T)F)NNN)1�__name__�
__module__�__qualname__�sysr{r|rrNrr$rerhrkrnrsrprvrxr�r�rar�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrMr1r�rVr}r�r�r	�
__classcell__rIrIrGrJr4s`)
�


	
#
K
8	

V9/	4
�#rcCsddl}|��dSr�)�doctest�testmod)r�rIrIrJ�_test2sr��__main__)!�
__future__rrr0r�rr�r:rAr�r��ImportError�urwidrr�urwid.display_commonrrrr	r
rr�urwid.compatr
rr�
subprocessrrrr�r�rIrIrIrJ�<module>sB� 
�
Upload File: