%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/urwid/__pycache__/canvas.cpython-35.pyc



5$�V��@s�ddlZddlmZmZmZmZmZmZmZm	Z	ddl
mZmZddl
mZGdd�de�ZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�Ze�ZGdd�de�ZGdd�de�Zdd�Zdd�Zdd�Zdd�Zdddd�Zdd�Zd d!�Zd"d#�Z d$d%�Z!d&d'�Z"d(d)�Z#d*d+�Z$d,d-�Z%d.d/�Z&d0d1�Z'd2d3�Z(d4d5�Z)dS)6�N)�rle_len�rle_append_modify�rle_join_modify�rle_product�
calc_width�
calc_text_pos�apply_target_encoding�trim_text_attr_cs)�	trim_line�
LayoutSegment)�bytesc@s�eZdZdZiZiZiZdZdZdZ	dd�Z
ee
�Z
dd�Zee�Zdd�Z
ee
�Z
d	d
�Zee�Zdd�Zee�Zd
S)�CanvasCachea`
    Cache for rendered canvases.  Automatically populated and
    accessed by Widget render() MetaClass magic, cleared by
    Widget._invalidate().

    Stores weakrefs to the canvas objects, so an external class
    must maintain a reference for this cache to be effective.
    At present the Screen classes store the last topmost canvas
    after redrawing the screen, keeping the canvases from being
    garbage collected.

    _widgets[widget] = {(wcls, size, focus): weakref.ref(canvas), ...}
    _refs[weakref.ref(canvas)] = (widget, wcls, size, focus)
    _deps[widget} = [dependent_widget, ...]
    rc	s*|js
dS|js"td��|j\}}}�fdd��t|dd�}|dkrt|d�r�|�}|r�x!|D]}||jkr�dSq�Wx*|D]"}|jj|g�j|�q�Wt	j
||j�}||||f|j|<||jj|i�|||f<dS)z�
        Store a weakref to canvas in the cache.

        wcls -- widget class that contains render() function
        canvas -- rendered canvas with widget_info (widget, size, focus)
        Nz&Can't store canvas without widget_infocslg}x_|jD]T\}}}}|jrB|j|jd�qt|d�r|j�|��qW|S)za
            Collect all child widgets for determining who we
            depend on.
            r�children)r�widget_info�append�hasattr�extend)�canvZdepends�x�y�c�pos)�walk_depends��./usr/lib/python3/dist-packages/urwid/canvas.pyrAs	z'CanvasCache.store.<locals>.walk_depends�
depends_onr)
�	cacheabler�AssertionError�getattrr�_widgets�_deps�
setdefaultr�weakref�ref�cleanup�_refs)	�cls�wclsZcanvas�widget�size�focusr�wr#r)rr�store5s"	

 zCanvasCache.storecCsu|jd7_|jj|d�}|s.dS|j|||fd�}|sSdS|�}|rq|jd7_|S)z�
        Return the cached canvas or None.

        widget -- widget object requested
        wcls -- widget class that contains render() function
        size, focus -- render() parameters
        �N)�fetchesr�get�hits)r&r(r'r)r*�sizesr#rrrr�fetch`s	zCanvasCache.fetchcCs�yUxDt|j|j��D])}y|j|=Wqtk
rEYqXqW|j|=Wntk
riYnX||jkr}dS|jj|g�}y|j|=Wntk
r�YnXx|D]}|j|�q�WdS)z8
        Remove all canvases cached for widget.
        N)�listr�valuesr%�KeyErrorr r/�
invalidate)r&r(r#Z
dependantsr+rrrr6vs$ 
	


zCanvasCache.invalidatecCs�|jd7_|jj|d�}|j|=|s8dS|\}}}}|jj|d�}|sidSy||||f=Wntk
r�YnX|s�y|j|=|j|=Wntk
r�YnXdS)Nr-)�cleanupsr%r/rr5r )r&r#r+r(r'r)r*r1rrrr$�s&



zCanvasCache.cleanupcCsi|_i|_i|_dS)z"
        Empty the cache.
        N)rr%r )r&rrr�clear�s		zCanvasCache.clearN)�__name__�
__module__�__qualname__�__doc__rr%r r0r.r7r,�classmethodr2r6r$r8rrrrr
s")r
c@seZdZdS)�CanvasErrorN)r9r:r;rrrrr>�sr>c@sKeZdZdZdZed�Zed�Zed�Zddddd�Z	d	d
�Z
dd�Zee�Z
dd
d�Zdd�Zeee�Zeee�Zeee�Zddddddd�Zdd�Zdd�Zdd�Zdd�Zdd�Zeee�Zdd�Zd d!�Zd"d#�ZdS)$�Canvasz!
    base class for canvases
    TzdThis canvas has been finalized. Use CompositeCanvas to wrap this canvas if you need to make changes.zcThe old Canvas class is now called TextCanvas. Canvas is now the base class for all canvas classes.z�The internal representation of canvases is no longer stored as .text, .attr, and .cs lists, please see the TextCanvas class for the new representation of canvas content.NcCs4|dk	r|j�d|_i|_i|_dS)z�
        value1, value2, value3 -- if not None, raise a helpful error:
            the old Canvas class is now called TextCanvas.
        N)�_renamed_error�_widget_info�coords�	shortcuts)�selfZvalue1Zvalue2Zvalue3rrr�__init__�s
			zCanvas.__init__cCs(|jr|j�|||f|_dS)a�
        Mark this canvas as finalized (should not be any future
        changes to its content). This is required before caching
        the canvas.  This happens automatically after a widget's
        'render call returns the canvas thanks to some metaclass
        magic.

        widget -- widget that rendered this canvas
        size -- size parameter passed to widget's render method
        focus -- focus parameter passed to widget's render method
        N)r�_finalized_errorrA)rDr(r)r*rrr�finalize�s		zCanvas.finalizecCs|jS)N)rA)rDrrr�_get_widget_info�szCanvas._get_widget_infocCs
|j�dS)N)�_old_repr_error)rD�valrrr�_raise_old_repr_error�szCanvas._raise_old_repr_errorcCsdd�|j�D�S)zg
        Return the text content of the canvas as a list of strings,
        one for each row.
        cSs/g|]%}t�jdd�|D���qS)cSsg|]\}}}|�qSrr)�.0�attr�cs�textrrr�
<listcomp>�s	z3Canvas._text_content.<locals>.<listcomp>.<listcomp>)r�join)rL�rowrrrrP�s	z(Canvas._text_content.<locals>.<listcomp>)�content)rDrrr�
_text_content�s	zCanvas._text_contentrcCs
t��dS)N)�NotImplementedError)rD�	trim_left�trim_top�cols�rowsrMrrrrS�szCanvas.contentcCs
t��dS)N)rU)rDrrrrX�szCanvas.colscCs
t��dS)N)rU)rDrrrrY�szCanvas.rowscCs
t��dS)N)rU)rDrrr�
content_delta�szCanvas.content_deltacCs-|jjdd�}|sdS|dd�S)N�cursor�)rBr/)rDrrrr�
get_cursor�szCanvas.get_cursorcCsc|jr|jr|j�|dkrNy|jd=Wntk
rIYnXdS|d|jd<dS)Nr[)N)rrrFrBr5)rDrrrr�
set_cursors	
zCanvas.set_cursorcCs#|jjdd�}|sdS|S)Nzpop up)rBr/)rDrrrr�
get_pop_upszCanvas.get_pop_upcCs>|jr|jr|j�|||||ff|jd<dS)a�
        This method adds pop-up information to the canvas.  This information
        is intercepted by a PopUpTarget widget higher in the chain to
        display a pop-up at the given (left, top) position relative to the
        current canvas.

        :param w: widget to use for the pop-up
        :type w: widget
        :param left: x position for left edge of pop-up >= 0
        :type left: int
        :param top: y position for top edge of pop-up >= 0
        :type top: int
        :param overlay_width: width of overlay in screen columns > 0
        :type overlay_width: int
        :param overlay_height: height of overlay in screen rows > 0
        :type overlay_height: int
        zpop upN)rrrFrB)rDr+�left�topZ
overlay_widthZoverlay_heightrrr�
set_pop_ups	zCanvas.set_pop_upcCsTi}xGt|jj��D]0\}\}}}|||||f||<qW|S)z4
        Return coords shifted by (dx, dy).
        )r3rB�items)rD�dx�dy�d�namerr�datarrr�translate_coords-s+zCanvas.translate_coords)r9r:r;r<rr>rFr@rIrErGrH�propertyrrKrTrOrMrNrSrXrYrZr]r^r[r_rbrirrrrr?�s2
r?c@seZdZdZdddddddd�Zdd�Zdd	�Zd
d�Zdddddd
d�Zdd�Z	dS)�
TextCanvasz8
    class for storing rendered text and attributes
    NTc
Cs�tj|�|dkrg}|r�g}x�|D]L}t|�tkr_tdt|���|jt|dt|���q2Wn+t|�t	ks�t
�|gt|�}|dkr�|r�t|�}nd}|dkrdd�tt|��D�}|dkr-dd�tt|��D�}xAtt|��D]-}	||	}
|
|krutd|||f��|
|kr�||	t�j
||
�||	<t||	�t||	�}|dkr�td||	||	f��|rt||	d|f�t||	�t||	�}|dkrPtd	||	||	f��|r@t||	d|f�q@W||_||_||_||_||_dS)
a[
        text -- list of strings, one for each line
        attr -- list of run length encoded attributes for text
        cs -- list of run length encoded character set for text
        cursor -- (x,y) of cursor or None
        maxcol -- screen columns taken by this canvas
        check_width -- check and fix width of all lines in text
        NzBCanvas text must be plain strings encoded in the screen's encodingrcSsg|]}g�qSrr)rLrrrrrP\s	z'TextCanvas.__init__.<locals>.<listcomp>cSsg|]}g�qSrr)rLrrrrrP^s	z8Canvas text is wider than the maxcol specified 
%r
%r
%rz$Attribute extends beyond text 
%r
%rz(Character Set extends beyond text 
%r
%r)r?rE�typerr>�reprrr�len�intr�max�range�rjustrr�_attr�_csr[�_text�_maxcol)
rDrOrMrNr[�maxcolZcheck_widthZwidths�t�ir+Za_gapZcs_gaprrrrE<sP


&
"				zTextCanvas.__init__cCs(t|j�}t|t�s$t�|S)z)Return the number of rows in this canvas.)rnru�
isinstanceror)rDrYrrrrYyszTextCanvas.rowscCs|jS)z.Return the screen column width of this canvas.)rv)rDrrrrXszTextCanvas.colscCs.|jr*|j\}}||||fSdS)zb
        Return cursor coords shifted by (dx, dy), or None if there
        is no cursor.
        N)r[)rDrdrerrrrr�translated_coords�s	zTextCanvas.translated_coordsrc	cs|j�|j�}}|s)||}|s9||}|dkrQ||ksWt�|dkrs|||ksyt�|dkr�||ks�t�|dkr�|||ks�t�|s�||krtt|j|||�|j|||�|j|||���}n!tt|j|j|j��}x�|D]�\}	}
}|se||jkr�t	|	|
||||�\}	}
}t
|
|�}d}
g}xd|D]\\\}}}|r�||kr�||}|j|||	|
|
|�f�|
|7}
q�W|VqAWdS)z�
        Return the canvas content as a list of rows where each row
        is a list of (attr, cs, text) tuples.

        trim_left, trim_top, cols, rows may be set by
        CompositeCanvas when rendering a partially obscured
        canvas.
        rN)rXrYrr3�ziprursrtrvr	rr)rDrVrWrXrY�attr_maprw�maxrowZtext_attr_csrOZa_rowZcs_rowZattr_csryrR�arN�runrrrrS�s:


"" !
$zTextCanvas.contentcCs-||kr#|j�g|j�S|j�S)z�
        Return the differences between other and this canvas.

        If other is the same object as self this will return no
        differences, otherwise this is the same as calling
        content().
        )rXrYrS)rD�otherrrrrZ�szTextCanvas.content_delta)
r9r:r;r<rErYrXr{rSrZrrrrrk8s	<
,rkc@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�BlankCanvaszv
    a canvas with nothing on it, only works as part of a composite canvas
    since it doesn't know its own size
    cCstj|d�dS)N)r?rE)rDrrrrE�szBlankCanvas.__init__c	cs`d}|r"d|kr"|d}|dt�j|�fg}xt|�D]}|VqMWdS)zH
        return (cols, rows) of spaces with default attributes.
        N)rrrrq)	rDrVrWrXrYrM�def_attr�lineryrrrrS�s
zBlankCanvas.contentcCstd��dS)Nz&BlankCanvas doesn't know its own size!)rU)rDrrrrX�szBlankCanvas.colscCstd��dS)Nz&BlankCanvas doesn't know its own size!)rU)rDrrrrY�szBlankCanvas.rowscCstd��dS)Nz&BlankCanvas doesn't know its own size!)rU)rDrrrrZ�szBlankCanvas.content_deltaN)	r9r:r;r<rErSrXrYrZrrrrr��sr�c@saeZdZdZdd�Zdd�Zdd�Zddd	d	d	d
d�Zdd
�Zd	S)�SolidCanvasz=
    A canvas filled completely with a single character.
    cCs�tj|�t|dt|�d�\}}|dksJtd|��t|d|��\|_}|dd|_||f|_d|_	dS)Nrr-zInvalid fill_char: %r)
r?rErrnrrrurtr)r[)rDZ	fill_charrXrY�end�colrNrrrrE�s
!zSolidCanvas.__init__cCs|jdS)Nr)r))rDrrrrX�szSolidCanvas.colscCs|jdS)Nr-)r))rDrrrrY�szSolidCanvas.rowsrNc	cs�|dkr|jd}|dkr2|jd}d}|rTd|krT|d}||j|j|fg}xt|�D]}|Vq}WdS)Nrr-)r)rtrurq)	rDrVrWrXrYrMr�r�ryrrrrS�s


zSolidCanvas.contentcCs-||kr#|j�g|j�S|j�S)zG
        Return the differences between other and this canvas.
        )rXrYrS)rDr�rrrrZszSolidCanvas.content_delta)	r9r:r;r<rErXrYrSrZrrrrr��s	
r�c@s�eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zdd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�CompositeCanvasz5
    class for storing a combination of canvases
    NcCs�tj|�|dkr.g|_g|_n�t|d�rL|j|_n9|j�dd|j�|j�d|fgfg|_dd|dfg|_|jj|j�x|j	D]}d|j	|<q�WdS)z�
        canv -- a Canvas object to wrap this CompositeCanvas around.

        if canv is a CompositeCanvas, make a copy of its contents
        N�shardsrZwrap)
r?rEr�rrrYrXrB�updaterC)rDr�shortcutrrrrEs
		zCompositeCanvas.__init__cCs�xT|jD]I\}}yt|t�s.t�Wq
tk
rRt||��Yq
Xq
Wtdd�|jD��}t|t�s�t�|S)NcSsg|]\}}|�qSrr)rL�r�cvrrrrP?s	z(CompositeCanvas.rows.<locals>.<listcomp>)r�rzror�sum)rDr�r�rYrrrrY9s
zCompositeCanvas.rowscCsJ|js
dStdd�|jddD��}t|t�sFt�|S)NrcSsg|]}|d�qS)r\r)rLr�rrrrPFs	z(CompositeCanvas.cols.<locals>.<listcomp>r-)r�r�rzror)rDrXrrrrXCs
	$zCompositeCanvas.colsccsdg}xW|jD]L\}}t||�}xt|�D]}t|�Vq8Wt||�}qWdS)zz
        Return the canvas content as a list of rows where each row
        is a list of (attr, cs, text) tuples.
        N)r��
shard_bodyrq�shard_body_row�shard_body_tail)rD�
shard_tail�num_rows�cviews�sbodyryrrrrSKszCompositeCanvas.contentccs�t|d�s/x|j�D]}|VqWdSg}x�t|j|j�D]�\}}t||�}g}xMt|�D]?}t|�dks�t|d�tkr�t	|�}|VqyWt
||�}qKWdS)zG
        Return the differences between other and this canvas.
        r�Nr-r)rrS�shards_deltar�r�rqrnrlror�r�)rDr�rRr�r�r�r�ryrrrrZ^s	(	zCompositeCanvas.content_deltacCs�|dkstd|��||j�ksJtd||j�f��|jr\|j�|rwt|j|�|_|dkr�g|_n!|dk	r�t|j|�|_|jd|�|_dS)z�Trim lines from the top and/or bottom of canvas.

        top -- number of lines to remove from top
        count -- number of lines to keep, or None for all the rest
        rzinvalid trim amount %d!zcannot trim %d lines from %d!N)	rrYrrF�shards_trim_topr��shards_trim_rowsrirB)rDra�countrrr�trimzs		zCompositeCanvas.trimcCs|dkstd|��||j�ksJtd||j�f��|jr\|j�t|j|j�|�|_dS)ziTrim lines from the bottom of the canvas.

        end -- number of lines to remove from the end
        rzinvalid trim amount %d!zcannot trim %d lines from %d!N)rrYrrFr�r�)rDr�rrr�trim_end�s		zCompositeCanvas.trim_endc
CsO|jr|j�|j}|dks3|dkrstd|�}|j�|td|�}t|||�}|j�}|dks�|dkr-|d\}}|dkr�dd||dtfg|}	n|dd�}	|dkr|	jdd||dtf�||	fg|dd�}|j	|d�|_
||_dS)z�
        Pad or trim this canvas on the left and right

        values > 0 indicate screen columns to pad
        values < 0 indicate screen columns to trim
        rNr-)rrFr�rprX�shards_trim_sidesrY�blank_canvasrrirB)
rDr`�rightr�rVrXrYZtop_rowsZ
top_cviewsZnew_top_cviewsrrr�pad_trim_left_right�s(			
z#CompositeCanvas.pad_trim_left_rightcCs,|jr|j�|j}|dks3|dkrqtd|�}|j�|td|�}|j||�|j�}|dkr�|dd||dtfgfg|j|_|jd|�|_	|dkr(||jkr�|jdd�|_|jj
|dd||dtfgf�dS)z@
        Pad or trim this canvas on the top and bottom.
        rN)rrFr�rprYr�rXr�rirBr)rDra�bottomZorig_shardsrWrYrXrrr�pad_trim_top_bottom�s$			
z#CompositeCanvas.pad_trim_top_bottomcCs�|jr|j�|j�}|j�}|j�||}|j�||}|dks�tdt|j�|||f���|dks�tdt|j�|||f���|j}g}	|j}
g}|r�t||�}
t||�}	|r t|
|�}t|
|�}
g}g}
|dkrMt	|
d|�g}|dkr{t	|
t
d||�|�g}
|j�s�g}n2|s�|r�t||jg|
�}n	|j}|	|||_|jj
|j||��dS)zOverlay other onto this canvas.rz,top canvas of overlay not the size expected!N)rrFrXrYrrmr�r�r�r�rp�shards_joinrBr�ri)rDr�r`ra�widthZheightr�r�r�Z
top_shardsZside_shardsZ
bottom_shardsZleft_shardsZright_shardsZ
middle_shardsrrr�overlay�sB		44				zCompositeCanvas.overlaycCs|jd|i�dS)z�
        Apply attribute a to all areas of this canvas with default
        attribute currently set to None, leaving other attributes
        intact.N)�fill_attr_apply)rDrrrr�	fill_attr	szCompositeCanvas.fill_attrcs|jr|j�g}x�|jD]�\}}g}x�|D]�}|ddkr�|j|dd��f|dd��q;t��}|j�fdd�t|dj��D��|j|dd�|f|dd��q;W|j||f�q"W||_dS)z�
        Apply an attribute-mapping dictionary to the canvas.

        mapping -- dictionary of original-attribute:new-attribute items
        �N�cs.g|]$\}}|�j||�f�qSr)r/)rL�k�v)�mappingrrrP$s	z3CompositeCanvas.fill_attr_apply.<locals>.<listcomp>)rrFr�r�dictr�r3rc)rDr�r�r�Zoriginal_cviews�
new_cviewsr�Zcombinedr)r�rr�s 		
)**zCompositeCanvas.fill_attr_applycCs|jr|j�||_dS)z�
        Explicitly specify the list of widgets that this canvas
        depends on.  If any of these widgets change this canvas
        will have to be updated.
        N)rrFr)rDZwidget_listrrr�set_depends*s		zCompositeCanvas.set_depends)r9r:r;r<rErYrXrSrZr�r�r�r�r�r�r�r�rrrrr�s"
"-r�cCs�g}xy|D]q\}}}|r8|jt|��q
|rmt|d�tkrm|d|d|d<q
|j|d�q
W|S)zx
    Return one row, advancing the iterators in sbody.

    ** MODIFIES sbody by calling next() on its iterators **
    r-r\���r�r�)r�nextrlror)r�rR�	done_rows�content_iter�cviewrrrr�6sr�c	Cs�g}d}d}xo|D]g\}}}|dd�\}}||7}||kra||7}q|j||||f�d}qW|S)z?
    Return a new shard tail that follows this shard body.
    rr\r�)r)	r�r�r��col_gapr�r�r�rXrYrrrr�Js


r�c	cs�t|�}d}}d}}x�|D]�\}}|dkrQt|�\}}x,||kr||7}t|�\}}qTW||kr�||fV||7}q'|t||�fV||7}d}||7}q'WdS)zX
    Yield shards1 with cviews that are the same as shards2
    having canv = None.
    Nr)�iterr��shard_cviews_delta)	r�Zother_shardsZother_shards_iterZother_num_rows�other_cviews�doneZ
other_doner�r�rrrr�\s"




r�ccst|�}d}d}}x�|D]�}|dkrAt|�}x*||krm||d7}t|�}qDW||kr�|V||d7}q#|d|dkr�|dd�|dd�kr�|dd�d|dd�Vn|V||d7}d}||d7}q#WdS)z
    Nrr\r��)N)r�r�)r�r�Zother_cviews_iterZother_cvrXZ
other_colsr�rrrr�ts&

4$r�TcCs�d}g}t|�}x|D]�\}}}	}
x�|ryt|�}Wntk
rjtd��YnX|dd�\}}
}}}}||7}||8}|dkr�td��|r�|r�|j||
|||�}n|}|jd||f�q4W|j||	|
f�qWxv|D]n}|dd�\}}
}}}}|rv|rv|j||
|||�}n|}|jd||f�q$W|S)a^
    Return a list of (done_rows, content_iter, cview) tuples for
    this shard and shard tail.

    If a canvas in cviews is None (eg. when unchanged from
    shard_cviews_delta()) or if create_iter is False then no
    iterator is created for content_iter.

    iter_default is the value used for content_iter when no iterator
    is created.
    rz&cviews do not fill gaps in shard_tail!Nr�z#cviews overflow gaps in shard_tail!)r�r��
StopIterationr>rSr)r�r�Zcreate_iterZiter_defaultr�ZbodyZcviews_iterr�r�r�Z
tail_cviewr�rVrWrXrYr}rZnew_iterrrrr��s8	
"


"r�cCs|dkst�t|�}g}xX|D]D\}}||krDPt||d�}t||�}||8}q+Wtd��t||d�}t||�}g}x:|D]2\}}	}
|jd|	t|
||�f�q�W|}||dd�|D�fg}|j|�|S)z.
    Return shards with top rows removed.
    rFz%tried to trim shards out of existencecSsg|]\}}}|�qSrr)rLr�r�r�rrrrP�s	z#shards_trim_top.<locals>.<listcomp>)rr�r�r�r>r�cview_trim_topr)r�raZ
shard_iterr�r�r�r�Z	new_sbodyr�r�r��
new_shardsrrrr��s*
r�cCs�|dkst|��g}d}x�|D]�\}}||krDPg}xL|D]D}|d||kr�|jt|||��qQ|j|�qQW|||kr�|j|||f�n|j||f�||7}q+W|S)z8
    Return the topmost keep_rows rows from shards.
    r�)rr�cview_trim_rows)r�Z	keep_rowsr�r�r�r�r�r�rrrr��s"
r�cCst|dkr|dks*t||f��g}g}||}x-|D]%\}}t||d�}t||�}g}	d}
x�|D]�\}}}
|
d}|
|}|s�||ks�|
|kr�|}
q�|
|kr�t|
||
�}
|}
||krt|
||
�}
|	j|
�|}
q�W|	sY|d\}}|||f|d<qG|j||	f�qGW|S)zL
    Return shards with starting from column left and cols total width.
    rFr\r-r�r�)rr�r��cview_trim_left�cview_trim_colsr)r�r`rXr�r�r�r�r�r�r�r�r�r�r�Zcv_colsZnext_colZ
prev_num_rowsZprev_cviewsrrrr��s6*




r�c
Csdd�|D�}dd�|D�}g}x�g}tdd�|D��}g}x>|D]6\}}|rz|j|�|j||df�q[W|}|j||f�yLxEtt|��D]1}	||	ddkr�q�t||	�||	<q�WWq/tk
rPYq/Xq/W|S)zx
    Return the result of joining shard lists horizontally.
    All shards lists must have the same number of rows.
    cSsg|]}t|��qSr)r�)rLZslrrrrP#s	zshards_join.<locals>.<listcomp>cSsg|]}t|��qSr)r�)rLryrrrrP$s	cSsg|]\}}|�qSrr)rLr�r�rrrrP)s	Nr)�minrrrqrnr�r�)
�shard_listsZshards_itersZshards_currentr�r�r�Zshards_nextrYr�ryrrrr�s*


r�cCs#|dd�|f|dd�S)Nr�r�r)r�rYrrrr�?sr�cCs6|d||d|d|d|f|dd�S)Nrr-r\r�r�r)r�r�rrrr�Bsr�cCs/|d||d|d|f|dd�S)Nrr-r\r�r)r�r�rrrr�Esr�cCs#|dd�|f|dd�S)Nr\r�r)r�rXrrrr�Hsr�cCs5dd�|D�}t�}g}g}d}d}d}x�|D]�\}}	}
|
r\|}|jd|||	f�|j|j�|jj|jd|��x*t|jj	��D]}|	|j|<q�W||j
�7}|d7}qAW|r||g|d|�||dd�}||_||_|S)a|Stack canvases in l vertically and return resulting canvas.

    :param l: list of (canvas, position, focus) tuples:

              position
                a value that widget.set_focus will accept or None if not
                allowed
              focus
                True if this canvas is the one that would be in focus
                if the whole widget is in focus
    cSs.g|]$\}}}t|�||f�qSr)r�)rLr�p�frrrrPZs	z!CanvasCombine.<locals>.<listcomp>rr-N)r�rrr�rBr�rir3rC�keysrYr)�lZclistZcombined_canvasr�rrRZfocus_index�nrrr*r�rrr�
CanvasCombineNs.			r�cCs�t|�}|j|||�|||dfdd|dfg|_i|_x*t|jj��D]}d|j|<qeW|S)zE
    Overlay canvas top_c onto bottom_c at position (left, top).
    NrZfg)r�r�rrCr3r�)Ztop_cZbottom_cr`raZoverlayed_canvasr�rrr�
CanvasOverlayvs	r�cCs�g}d}d}d}xw|D]o\}}}}|j�}	||j�}
|rY|}|	|krk|	}|j|||
|	f�|d7}qWg}g}t�}
d}x�|D]�\}}}
}	t|�}|
r�|jd|
�|	|kr|jd||	�|
jj|j|d��x*t	|j
j��D]}||
j
|<q:W|j|j�|j|d||f�||j�7}q�W|r�||g|d|�||dd�}t
|�|
_||
_|
S)aG
    Join canvases in l horizontally. Return result.

    :param l: list of (canvas, position, focus, cols) tuples:

              position
                value that widget.set_focus will accept or None if not allowed
              focus
                True if this canvas is the one that would be in focus if
                the whole widget is in focus
              cols
                is the number of screen columns that this widget will require,
                if larger than the actual canvas.cols() value then this widget
                will be padded on the right.
    rr-N)rYrXrr�r�r�rBr�rir3rCr�r�r�r)r��l2Z
focus_itemr~r�rrr*rXrYZ	pad_rightr�rZ
joined_canvasr�r�rrr�
CanvasJoin�sF		r�csUg}g}g}Gdd�d�}|�d�_d�_��fdd��x�|D]�}t|�d|�}g}	g�g}
���fdd�}xg|D]_}t|�}
|
jrt�|
j|
j��\}}|	j|�||
j|
jt|��t	|
|�q�|
j
rrt|
j
�\}}|	j|�||
j|
jt|��t	|
|�q�|
jr�|
jr|	jt
�j|
j��||
j|
j|
j�q�|	jt
�j|
j���jd|
jf�|
jd|
jf�q�W|jt
�j|	��|j��|j|
�qYWt|||d|�S)	Nc@seZdZdS)z#apply_text_layout.<locals>.AttrWalkN)r9r:r;rrrr�AttrWalk�sr�rcs@|�jkr!d�_d�_g}x�j|kr;t���jkrr|jd|t|�j�f�P��j\}}�j||kr��jd7_�j|7_q*|�j|kr�|j||t|�j�f�P|j|�j|t|�j�f��jd7_�j|7_q*W|S)z9Return an attribute list for the range of text specified.rNr-)�offr�rnrrp)�
start_offs�end_offs�o�atr�)rM�awrr�arange�s(		##*z!apply_text_layout.<locals>.arangec	s,||kr;�||�\\}}t�||f�dS|||kr�x0�||�D]\}}t�||f�q[WdS|}x��||�D]�\}}|||kr�t�||f�dS�|||�}t|�\}}t|�}t�||f�||7}||8}q�WdS)zi
            Add attributes based on attributes between
            start_offs and end_offs.
            N)rrr)	r�r�Zdestwr�r�r��tsegrNZsegw)r��linearOrr�	attrrange�s&
z$apply_text_layout.<locals>.attrrangerw)r�r�r
rr�rZoffsrrrrOrnZscrrrrQrk)rOrMZlsrwrxrrr�Zline_layoutr�Zlinecr�Zseg�sr�rNr)r�rMr�r�rOr�apply_text_layout�sL		

	
	
		
r�)*r"Z
urwid.utilrrrrrrrr	Zurwid.text_layoutr
rZurwid.compatr�objectr
�	Exceptionr>r?rkr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>s::���	,�$0#!!(9

Zerion Mini Shell 1.0