%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__/canvas.cpython-36.pyc

3

��dZ
��@s`ddlmZmZddlZddlmZmZmZmZm	Z	m
Z
mZmZddl
mZmZddlmZGdd�de�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�de�Ze�ZGdd�de�ZGdd�de�Zdd�Zdd�Zdd�Zdd�Zd7dd�Z dd �Z!d!d"�Z"d#d$�Z#d%d&�Z$d'd(�Z%d)d*�Z&d+d,�Z'd-d.�Z(d/d0�Z)d1d2�Z*d3d4�Z+d5d6�Z,dS)8�)�division�print_functionN)�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@sxeZdZdZiZiZiZdZdZdZ	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|jstd��|j\}}}�fdd��t|dd�}|dkrVt|d�rV�|�}|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_infocsPg}xF|jD]<\}}}}|jr0|j|jd�qt|d�r|j�|��qW|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.pyrCs
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�store7s"


zCanvasCache.storecCsZ|jd7_|jj|d�}|s$dS|j|||fd�}|s>dS|�}|rV|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�fetchbszCanvasCache.fetchcCs�yFx8|j|j�D]&}y|j|=Wqtk
r6YqXqW|j|=Wntk
rZYnX||jkrjdS|jj|g�}y|j|=Wntk
r�YnXx|D]}|j|�q�WdS)z8
        Remove all canvases cached for widget.
        N)r!�valuesr'�KeyErrorr"r1�
invalidate)r(r*r%Z
dependantsr-rrrr7xs$


zCanvasCache.invalidatecCs�|jd7_|jj|d�}|j|=|s,dS|\}}}}|jj|d�}|sNdSy||||f=Wntk
rrYnX|s�y|j|=|j|=Wntk
r�YnXdS)Nr/)�cleanupsr'r1r!r6r")r(r%r-r*r)r+r,r3rrrr&�s&zCanvasCache.cleanupcCsi|_i|_i|_dS)z"
        Empty the cache.
        N)r!r'r")r(rrr�clear�szCanvasCache.clearN)�__name__�
__module__�__qualname__�__doc__r!r'r"r2r0r8r.�classmethodr4r7r&r9rrrrr s")rc@seZdZdS)�CanvasErrorN)r:r;r<rrrrr?�sr?c@s�eZdZdZdZed�Zed�Zed�Zd$dd�Z	d	d
�Z
dd�Zee�Z
d%d
d�Zdd�Zeee�Zeee�Zeee�Zd&dd�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.NcCs$|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_errorrB)rEr*r+r,rrr�finalize�szCanvas.finalizecCs|jS)N)rB)rErrr�_get_widget_info�szCanvas._get_widget_infocCs
|j�dS)N)�_old_repr_error)rE�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>�sz3Canvas._text_content.<locals>.<listcomp>.<listcomp>)r�join)rM�rowrrrrQ�sz(Canvas._text_content.<locals>.<listcomp>)�content)rErrr�
_text_content�szCanvas._text_contentrcCs
t��dS)N)�NotImplementedError)rE�	trim_left�trim_top�cols�rowsrNrrrrT�szCanvas.contentcCs
t��dS)N)rV)rErrrrY�szCanvas.colscCs
t��dS)N)rV)rErrrrZ�szCanvas.rowscCs
t��dS)N)rV)rErrr�
content_delta�szCanvas.content_deltacCs"|jjdd�}|sdS|dd�S)N�cursor�)rCr1)rErrrr�
get_cursorszCanvas.get_cursorcCsR|jr|jr|j�|dkr@y|jd=Wntk
r:YnXdS|d|jd<dS)Nr\)N)rrrGrCr6)rErrrr�
set_cursorszCanvas.set_cursorcCs|jjdd�}|sdS|S)Nzpop up)rCr1)rErrrr�
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)rrrGrC)rEr-�left�topZ
overlay_widthZoverlay_heightrrr�
set_pop_upszCanvas.set_pop_upcCs<i}x2|jj�D]$\}\}}}|||||f||<qW|S)z4
        Return coords shifted by (dx, dy).
        )rC�items)rE�dx�dy�d�namerr�datarrr�translate_coords/szCanvas.translate_coords)NNN)N)rrNNN)r:r;r<r=rr?rGrArJrFrHrI�propertyrrLrUrPrNrOrTrYrZr[r^r_r\r`rcrjrrrrr@�s2







r@c@sDeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
d�Zdd�Z	dS)�
TextCanvasz8
    class for storing rendered text and attributes
    NTc
Cs�tj|�|dkrg}|r^g}x\|D]4}t|�tkrBtdt|���|jt|dt|���q$Wnt|�t	ksnt
�|gt|�}|dkr�|r�t|�}nd}|dkr�dd�tt|��D�}|dkr�dd�tt|��D�}�xtt|��D]�}	||	}
|
|k�r
td|||f��|
|k�r0||	t�j
||
�||	<t||	�t||	�}|dk�rjtd||	||	f��|�r�t||	d|f�t||	�t||	�}|dk�r�td	||	||	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)rMrrrrrQ^sz'TextCanvas.__init__.<locals>.<listcomp>cSsg|]}g�qSrr)rMrrrrrQ`sz8Canvas text is wider than the maxcol specified 
%r
%r
%rz$Attribute extends beyond text 
%r
%rz(Character Set extends beyond text 
%r
%r)r@rF�typerr?�reprrr�len�intr�max�range�rjustrr�_attr�_csr\�_text�_maxcol)
rErPrNrOr\�maxcolZcheck_widthZwidths�t�ir-Za_gapZcs_gaprrrrF>sP







zTextCanvas.__init__cCst|j�}t|t�st�|S)z)Return the number of rows in this canvas.)rorv�
isinstancerpr)rErZrrrrZ{s
zTextCanvas.rowscCs|jS)z.Return the screen column width of this canvas.)rw)rErrrrY�szTextCanvas.colscCs$|jr |j\}}||||fSdS)zb
        Return cursor coords shifted by (dx, dy), or None if there
        is no cursor.
        N)r\)rErerfrrrrr�translated_coords�s
zTextCanvas.translated_coordsrc	cs�|j�|j�}}|s||}|s*||}|dkr:||ks>t�|dkrR|||ksVt�|dkrf||ksjt�|dkr~|||ks�t�|s�||kr�t|j|||�|j|||�|j|||��}nt|j|j|j�}x�|D]�\}	}
}|s�||jk�rt|	|
||||�\}	}
}t	|
|�}d}
g}xR|D]J\\}}}|�rN||k�rN||}|j
|||	|
|
|�f�|
|7}
�q*W|Vq�WdS)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)rYrZr�ziprvrtrurwrrr)rErWrXrYrZ�attr_maprx�maxrowZtext_attr_csrPZa_rowZcs_rowZattr_csrzrS�arO�runrrrrT�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().
        )rYrZrT)rE�otherrrrr[�szTextCanvas.content_delta)NNNNNT)rrNNN)
r:r;r<r=rFrZrYr|rTr[rrrrrl:s
<

,rlc@s8eZdZdZdd�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@rF)rErrrrF�szBlankCanvas.__init__c	csHd}|rd|kr|d}|dt�j|�fg}xt|�D]
}|Vq6WdS)zH
        return (cols, rows) of spaces with default attributes.
        N)rrsrr)	rErWrXrYrZrN�def_attr�linerzrrrrT�szBlankCanvas.contentcCstd��dS)Nz&BlankCanvas doesn't know its own size!)rV)rErrrrY�szBlankCanvas.colscCstd��dS)Nz&BlankCanvas doesn't know its own size!)rV)rErrrrZ�szBlankCanvas.rowscCstd��dS)Nz&BlankCanvas doesn't know its own size!)rV)rErrrr[�szBlankCanvas.content_deltaN)	r:r;r<r=rFrTrYrZr[rrrrr��sr�c@s:eZdZdZdd�Zdd�Zdd�Zdd
d�Zdd
�Zd	S)�SolidCanvasz=
    A canvas filled completely with a single character.
    cCsltj|�t|dt|�d�\}}|dks4td|��t|d|��\|_}|dd|_||f|_d|_	dS)Nrr/zInvalid fill_char: %r)
r@rFr	rorr
rvrur+r\)rEZ	fill_charrYrZ�end�colrOrrrrF�s

zSolidCanvas.__init__cCs
|jdS)Nr)r+)rErrrrY�szSolidCanvas.colscCs
|jdS)Nr/)r+)rErrrrZ�szSolidCanvas.rowsrNc	csl|dkr|jd}|dkr$|jd}d}|r<d|kr<|d}||j|j|fg}xt|�D]
}|VqZWdS)Nrr/)r+rurvrr)	rErWrXrYrZrNr�r�rzrrrrT�s

zSolidCanvas.contentcCs"||kr|j�g|j�S|j�S)zG
        Return the differences between other and this canvas.
        )rYrZrT)rEr�rrrr[
szSolidCanvas.content_delta)rrNNN)	r:r;r<r=rFrYrZrTr[rrrrr��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|_nrt|d�r4|j|_n&|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@rFr�rrrZrYrC�updaterD)rEr�shortcutrrrrFs


zCompositeCanvas.__init__cCslxD|jD]:\}}yt|t�s t�Wqtk
r@t||��YqXqWtdd�|jD��}t|t�sht�|S)NcSsg|]\}}|�qSrr)rM�r�cvrrrrQAsz(CompositeCanvas.rows.<locals>.<listcomp>)r�r{rpr�sum)rEr�r�rZrrrrZ;szCompositeCanvas.rowscCs8|js
dStdd�|jddD��}t|t�s4t�|S)NrcSsg|]}|d�qS)r]r)rMr�rrrrQHsz(CompositeCanvas.cols.<locals>.<listcomp>r/)r�r�r{rpr)rErYrrrrYEs
zCompositeCanvas.colsccsLg}xB|jD]8\}}t||�}xt|�D]}t|�Vq(Wt||�}qWdS)zz
        Return the canvas content as a list of rows where each row
        is a list of (attr, cs, text) tuples.
        N)r��
shard_bodyrr�shard_body_row�shard_body_tail)rE�
shard_tail�num_rows�cviews�sbodyrzrrrrTMs
zCompositeCanvas.contentccs�t|d�s&x|j�D]
}|VqWdSg}xnt|j|j�D]\\}}t||�}g}x:t|�D].}t|�dkszt|d�tkr�t	|�}|VqZWt
||�}q:WdS)zG
        Return the differences between other and this canvas.
        r�Nr/r)rrT�shards_deltar�r�rrrormrpr�r�)rEr�rSr�r�r�r�rzrrrr[`s



zCompositeCanvas.content_deltacCs�|dkstd|��||j�ks4td||j�f��|jr@|j�|rRt|j|�|_|dkrbg|_n|dk	rxt|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)	rrZrrG�shards_trim_topr��shards_trim_rowsrjrC)rErb�countrrr�trim|szCompositeCanvas.trimcCsZ|dkstd|��||j�ks4td||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)rrZrrGr�r�)rEr�rrr�trim_end�szCompositeCanvas.trim_endc
Cs�|jr|j�|j}|dks"|dkrRtd|�}|j�|td|�}t|||�}|j�}|dksj|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/)rrGr�rqrY�shards_trim_sidesrZ�blank_canvasrrjrC)
rEra�rightr�rWrYrZZtop_rowsZ
top_cviewsZnew_top_cviewsrrr�pad_trim_left_right�s(z#CompositeCanvas.pad_trim_left_rightcCs�|jr|j�|j}|dks"|dkrRtd|�}|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)rrGr�rqrZr�rYr�rjrCr)rErb�bottomZorig_shardsrXrZrYrrr�pad_trim_top_bottom�s$

z#CompositeCanvas.pad_trim_top_bottomcCsf|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}
|dkr�t	|
d|�g}|dk�rt	|
t
d||�|�g}
|j��sg}n(|�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)rrGrYrZrrnr�r�r�r�rq�shards_joinrCr�rj)rEr�rarb�widthZheightr�r�r�Z
top_shardsZside_shardsZ
bottom_shardsZleft_shardsZright_shardsZ
middle_shardsrrr�overlay�sB$$





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)rEr�rrr�	fill_attrszCompositeCanvas.fill_attrcs�|jr|j�g}x�|jD]�\}}g}x�|D]�}|ddkr`|j|dd��f|dd��q*t��}|j�fdd�|dj�D��|j|dd�|f|dd��q*W|j||f�qW||_dS)z�
        Apply an attribute-mapping dictionary to the canvas.

        mapping -- dictionary of original-attribute:new-attribute items
        �N�cs g|]\}}|�j||�f�qSr)r1)rM�k�v)�mappingrrrQ&sz3CompositeCanvas.fill_attr_apply.<locals>.<listcomp>)rrGr�r�dictr�rd)rEr�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)rrGr)rEZwidget_listrrr�set_depends,szCompositeCanvas.set_depends)N)N)r:r;r<r=rFrZrYrTr[r�r�r�r�r�r�r�r�rrrrr�s
"

"-r�cCshg}x^|D]V\}}}|r(|jt|��q
|rRt|d�tkrR|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�nextrmrpr)r�rS�	done_rows�content_iter�cviewrrrr�8sr�c	Csdg}d}d}xR|D]J\}}}|dd�\}}||7}||krF||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�rYrZrrrr�Lsr�c	cs�t|�}d}}d}}x�|D]~\}}|dkr:t|�\}}x ||krZ||7}t|�\}}q<W||krx||fV||7}q|t||�fV||7}d}||7}qWdS)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�ccs�t|�}d}d}}x�|D]�}|dkr.t|�}x ||krN||d7}t|�}q0W||krl|V||d7}q|d|dkr�|dd�|dd�kr�|dd�d|dd�Vn|V||d7}d}||d7}qWdS)z
    Nrr]r��)N)r�r�)r�r�Zother_cviews_iterZother_cvrYZ
other_colsr�rrrr�vs&

( r�TcCs.d}g}t|�}x�|D]�\}}}	}
x�|r�yt|�}Wntk
rPtd��YnX|dd�\}}
}}}}||7}||8}|dkr�td��|r�|r�|j||
|||�}n|}|jd||f�q$W|j||	|
f�qWxV|D]N}|dd�\}}
}}}}|o�|�r|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?rTr)r�r�Zcreate_iterZiter_defaultr�ZbodyZcviews_iterr�r�r�Z
tail_cviewr�rWrXrYrZr~rZnew_iterrrrr��s8

r�cCs�|dkst�t|�}g}x@|D]0\}}||kr0Pt||d�}t||�}||8}qWtd��t||d�}t||�}g}x,|D]$\}}	}
|jd|	t|
||�f�qzW|}||dd�|D�fg}|j|�|S)z.
    Return shards with top rows removed.
    rFz%tried to trim shards out of existencecSsg|]\}}}|�qSrr)rMr�r�r�rrrrQ�sz#shards_trim_top.<locals>.<listcomp>)rr�r�r�r?r�cview_trim_topr)r�rbZ
shard_iterr�r�r�r�Z	new_sbodyr�r�r��
new_shardsrrrr��s*


r�cCs�|dkst|��g}d}x�|D]�\}}||kr0Pg}x<|D]4}|d||krd|jt|||��q:|j|�q:W|||kr�|j|||f�n|j||f�||7}qW|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�cCs|dkr|dkst||f��g}g}||}x�|D]�\}}t||d�}t||�}g}	d}
xz|D]r\}}}
|
d}|
|}|s�||ks�|
|kr�|}
q^|
|kr�t|
||
�}
|}
||kr�t|
||
�}
|	j|
�|}
q^W|	s�|d\}}|||f|d<q2|j||	f�q2W|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�rarYr�r�r�r�r�r�r�r�r�r�r�Zcv_colsZnext_colZ
prev_num_rowsZprev_cviewsrrrr��s6

r�c
Cs�dd�|D�}dd�|D�}g}x�g}tdd�|D��}g}x0|D](\}}|rX|j|�|j||df�qBW|}|j||f�y<x6tt|��D]&}	||	ddkr�q�t||	�||	<q�WWq"tk
r�PYq"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�)rMZslrrrrQ%szshards_join.<locals>.<listcomp>cSsg|]}t|��qSr)r�)rMrzrrrrQ&scSsg|]\}}|�qSrr)rMr�r�rrrrQ+sNr)�minrrrrror�r�)
�shard_listsZshards_itersZshards_currentr�r�r�Zshards_nextrZr�rzrrrr� s*
r�cCs|dd�|f|dd�S)Nr�r�r)r�rZrrrr�Asr�cCs0|d||d|d|d|f|dd�S)Nrr/r]r�r�r)r�r�rrrr�Dsr�cCs*|d||d|d|f|dd�S)Nrr/r]r�r)r�r�rrrr�Gsr�cCs|dd�|f|dd�S)Nr]r�r)r�rYrrrr�Jsr�cCs�dd�|D�}t�}g}g}d}d}d}x~|D]v\}}	}
|
r@|}|jd|||	f�|j|j�|jj|jd|��x|jj�D]}|	|j|<q~W||j	�7}|d7}q.W|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�)rMr�p�frrrrQ\sz!CanvasCombine.<locals>.<listcomp>rr/N)r�rrr�rCr�rjrD�keysrZr)�lZclistZcombined_canvasr�rrSZfocus_index�nrrr,r�rrr�
CanvasCombinePs.r�cCsXt|�}|j|||�|||dfdd|dfg|_i|_x|jj�D]}d|j|<qBW|S)zE
    Overlay canvas top_c onto bottom_c at position (left, top).
    NrZfg)r�r�rrDr�)Ztop_cZbottom_crarbZoverlayed_canvasr�rrr�
CanvasOverlayxs
r�cCs\g}d}d}d}xV|D]N\}}}}|j�}	||j�}
|r>|}|	|krJ|	}|j|||
|	f�|d7}qWg}g}t�}
d}x�|D]�\}}}
}	t|�}|
r�|jd|
�|	|kr�|jd||	�|
jj|j|d��x|j	j
�D]}||
j	|<q�W|j|j�|j|d||f�||j�7}q�W|�rH||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)rZrYrr�r�r�rCr�rjrDr�r�r�r)r��l2Z
focus_itemrr�rrr,rYrZZ	pad_rightr�rZ
joined_canvasr�r�rrr�
CanvasJoin�sF
r�cs�g}g}g}Gdd�d�}|�d�_d�_��fdd���xl|D�]b}t|�d|�}g}	g�g}
���fdd�}�x
|D�]}t|�}
|
jr�t�|
j|
j��\}}|	j|�||
j|
jt|��t	|
|�qx|
j
�rt|
j
�\}}|	j|�||
j|
jt|��t	|
|�qx|
j�rF|
j�rz|	jt
�j|
j��||
j|
j|
j�qx|	jt
�j|
j���jd|
jf�|
jd|
jf�qxW|jt
�j|	��|j��|j|
�q@Wt||||d�S)	Nc@seZdZdS)z#apply_text_layout.<locals>.AttrWalkN)r:r;r<rrrr�AttrWalk�sr�rcs�|�jkrd�_d�_g}x؈j|kr�t���jkrP|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_qW|S)z9Return an attribute list for the range of text specified.rNr/)�offr�rorrq)�
start_offs�end_offs�o�atr�)rN�awrr�arange�s(
 z!apply_text_layout.<locals>.arangec	s�||kr*�||�\\}}t�||f�dS|||kr`x$�||�D]\}}t�||f�qBWdS|}xv�||�D]h\}}|||kr�t�||f�dS�|||�}t|�\}}t|�}t�||f�||7}||8}qpWdS)zi
            Add attributes based on attributes between
            start_offs and end_offs.
            N)rr
r)	r�r�Zdestwr�r�r��tsegrOZsegw)r��linearPrr�	attrrange�s&z$apply_text_layout.<locals>.attrrange)rx)r�r�rr
r�r
ZoffsrrrrProZscrrsrRrl)rPrNZlsrxryr�rr�Zline_layoutr�Zlinecr�Zseg�sr�rOr)r�rNr�r�rPr�apply_text_layout�sL


r�)TN)-Z
__future__rrr$Z
urwid.utilrrrrrr	r
rZurwid.text_layoutrr
Zurwid.compatr�objectr�	Exceptionr?r@rlr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>sD(,%
0#!!(9

Zerion Mini Shell 1.0