grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a BjŒjò¢ã@s`ddlmZmZddlZddlmZmZmZmZm Z m Z m Z m Z ddl mZmZddlmZGdd„deƒZGdd „d eƒZGd d „d eƒ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 e e ƒZ dd„Z e e ƒZ dd„Z e e ƒZ d d „Ze eƒZd d „Ze eƒ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|j\}}}‡fdd„‰t|ddƒ}|durHt|dƒrHˆ|ƒ}|r„|D]}||jvrPdSqP|D]}|j |g¡ |¡qjt  ||j ¡}||||f|j |<||j |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) NcsLg}|jD]<\}}}}|jr.| |jd¡q t|dƒr | ˆ|ƒ¡q |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©ú2/usr/lib64/python3.9/site-packages/urwid/canvas.pyrBs z'CanvasCache.store..walk_dependsÚ depends_onr) Ú cacheablerÚgetattrrÚ_widgetsÚ_depsÚ setdefaultrÚweakrefÚrefÚcleanupÚ_refs) ÚclsÚwclsZcanvasÚwidgetÚsizeÚfocusrÚwr%rrrÚstore6s     zCanvasCache.storecCsZ|jd7_|j |d¡}|s$dS| |||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ÚfetchaszCanvasCache.fetchc Cs¨z@|j| ¡D]$}z |j|=Wqty2Yq0q|j|=WntyRYn0||jvrbdS|j |g¡}z |j|=WntyŽYn0|D]}| |¡q”dS)z8 Remove all canvases cached for widget. N)r!Úvaluesr'ÚKeyErrorr"r1Ú invalidate)r(r*r%Z dependantsr-rrrr7ws$       zCanvasCache.invalidatecCs¢|jd7_|j |d¡}|j|=|s,dS|\}}}}|j |d¡}|sNdSz||||f=WntypYn0|sžz|j|=|j|=WntyœYn0dS©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"r2r0r9r.Ú classmethodr4r7r&r:rrrrrs")rc@s eZdZdS)Ú CanvasErrorN©r;r<r=rrrrr@±sr@c@sÒeZdZdZdZedƒZedƒZedƒZd$dd„Z d d „Z d d „Z e 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$|dur|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_errorrD)rGr*r+r,rrrÚfinalizeÐs zCanvas.finalizecCs|jS©N)rD©rGrrrÚ_get_widget_infoàszCanvas._get_widget_infocCs |j‚dSrK)Ú_old_repr_error)rGÚvalrrrÚ_raise_old_repr_erroräszCanvas._raise_old_repr_errorcCsdd„| ¡DƒS)zg Return the text content of the canvas as a list of strings, one for each row. cSs"g|]}tƒ dd„|Dƒ¡‘qS)cSsg|]\}}}|‘qSrr)Ú.0ÚattrÚcsÚtextrrrÚ ìóz3Canvas._text_content...)rÚjoin)rQÚrowrrrrUìsÿz(Canvas._text_content..)ÚcontentrLrrrÚ _text_contentçsÿzCanvas._text_contentrcCs tƒ‚dSrK©ÚNotImplementedError)rGÚ trim_leftÚtrim_topÚcolsÚrowsrRrrrrYószCanvas.contentcCs tƒ‚dSrKr[rLrrrr_÷sz Canvas.colscCs tƒ‚dSrKr[rLrrrr`úsz Canvas.rowscCs tƒ‚dSrKr[rLrrrÚ content_deltaýszCanvas.content_deltacCs"|j dd¡}|sdS|dd…S)NÚcursoré©rEr1©rGrrrrÚ get_cursorszCanvas.get_cursorcCsP|jr|jr|j‚|dur>z |jd=Wnty8Yn0dS|d|jd<dS)NrbrK)rrrIrEr6rerrrÚ set_cursors   zCanvas.set_cursorcCs|j dd¡}|sdS|S)Núpop uprdrerrrÚ 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 rhN)rrrIrE)rGr-ÚleftÚtopZ overlay_widthZoverlay_heightrrrÚ set_pop_ups  ÿzCanvas.set_pop_upcCs8i}|j ¡D]$\}\}}}|||||f||<q|S)z4 Return coords shifted by (dx, dy). )rEÚitems)rGÚdxÚdyÚdÚnamerrÚdatarrrÚtranslate_coords.szCanvas.translate_coords)NNN)N)rrNNN)r;r<r=r>rr@rIrCrNrHrJrMÚpropertyrrPrZrTrRrSrYr_r`rarfrgrbrirlrsrrrrrB´s4     ÿ  rBc@sDeZdZdZddd„Zdd„Zdd „Zd d „Zdd d„Zdd„Z dS)Ú TextCanvasz8 class for storing rendered text and attributes NTc CsÜt |¡|dkrg}|rZg}|D]4}t|ƒtkr@tdt|ƒƒ‚| t|dt|ƒƒ¡q"n|gt|ƒ}|dur‚|r~t |ƒ}nd}|dkr dd„t t|ƒƒDƒ}|dkr¾dd„t t|ƒƒDƒ}t t|ƒƒD]î} || } | |krðtd|||fƒ‚| |k�r|| tƒ  || ¡|| <t|| ƒt || ƒ} | dk�rPtd|| || fƒ‚| �rht || d| fƒt|| ƒt || ƒ} | dk�r¢td || || fƒ‚| rÊt || d| fƒqÊ||_||_||_||_||_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©rQrrrrrU]rVz'TextCanvas.__init__..cSsg|]}g‘qSrrrvrrrrU_rVz8Canvas text is wider than the maxcol specified %r %r %rz$Attribute extends beyond text %r %rz(Character Set extends beyond text %r %r)rBrHÚtyperr@ÚreprrrÚlenÚmaxÚrangeÚrjustrrÚ_attrÚ_csrbÚ_textÚ_maxcol) rGrTrRrSrbÚmaxcolZ check_widthZwidthsÚtÚir-Za_gapZcs_gaprrrrH=sN      zTextCanvas.__init__cCst|jƒ}|S)z)Return the number of rows in this canvas.)ryr)rGr`rrrr`zs zTextCanvas.rowscCs|jS)z.Return the screen column width of this canvas.)r€rLrrrr_€szTextCanvas.colscCs$|jr |j\}}||||fSdS)zb Return cursor coords shifted by (dx, dy), or None if there is no cursor. N)rb)rGrnrorrrrrÚtranslated_coords„s zTextCanvas.translated_coordsrc cs| ¡| ¡}}|s||}|s*||}|s6||krnt|j|||…|j|||…|j|||…ƒ}nt|j|j|jƒ}|D]”\} } } |sœ||jkr¶t| | | |||ƒ\} } } t| | ƒ} d} g}| D]D\\}}}|rì||vrì||}|  ||| | | |…f¡| |7} qÌ|Vq„dS)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) r_r`Úziprr}r~r€r rr)rGr]r^r_r`Úattr_mapr�ÚmaxrowZ text_attr_csrTZa_rowZcs_rowZattr_csrƒrXÚarSÚrunrrrrYŽs6  ýþ    zTextCanvas.contentcCs"||ur| ¡g| ¡S| ¡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(). ©r_r`rY©rGÚotherrrrra»szTextCanvas.content_delta)NNNNNT)rrNNN) r;r<r=r>rHr`r_r„rYrarrrrru9sÿ = ÿ -ruc@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 cCst |d¡dSrK)rBrHrLrrrrHÎszBlankCanvas.__init__c csDd}|rd|vr|d}|dtƒ |¡fg}t|ƒD] }|Vq4dS)zH return (cols, rows) of spaces with default attributes. N)rr|r{© rGr]r^r_r`rRZdef_attrÚlinerƒrrrrYÑs   zBlankCanvas.contentcCs tdƒ‚dS©Nz&BlankCanvas doesn't know its own size!r[rLrrrr_ÜszBlankCanvas.colscCs tdƒ‚dSr�r[rLrrrr`ßszBlankCanvas.rowscCs tdƒ‚dSr�r[rLrrrraâszBlankCanvas.content_deltaN) r;r<r=r>rHrYr_r`rarrrrr�És  r�c@s:eZdZdZdd„Zdd„Zdd„Zdd d „Zd d „Zd S)Ú SolidCanvasz= A canvas filled completely with a single character. cCsXt |¡t|dt|ƒdƒ\}}t|d|…ƒ\|_}|dd|_||f|_d|_dS©Nrr/) rBrHr ryr rr~r+rb)rGZ fill_charr_r`ÚendÚcolrSrrrrHìs   zSolidCanvas.__init__cCs |jdS)Nr©r+rLrrrr_õszSolidCanvas.colscCs |jdSr8r•rLrrrr`øszSolidCanvas.rowsrNc csh|dur|jd}|dur$|jd}d}|rrHr_r`rYrarrrrr‘ès ÿ r‘c@s|eZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zdd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)ÚCompositeCanvasz5 class for storing a combination of canvases NcCs’t |¡|dur g|_g|_nnt|dƒr4|j|_n&| ¡dd| ¡| ¡d|fgfg|_dd|dfg|_|j |j¡|j D]}d|j |<q~dS)z‘ canv -- a Canvas object to wrap this CompositeCanvas around. if canv is a CompositeCanvas, make a copy of its contents NÚshardsrÚwrap) rBrHr˜rrr`r_rEÚupdaterF)rGrÚshortcutrrrrHs   ÿÿ  zCompositeCanvas.__init__c CsJ|jD]*\}}zWqty.t||ƒ‚Yq0qtdd„|jDƒƒ}|S)NcSsg|] \}}|‘qSrr©rQÚrÚcvrrrrU@rVz(CompositeCanvas.rows..)r˜ÚAssertionErrorÚsum)rGr�ržr`rrrr`:s zCompositeCanvas.rowscCs*|js dStdd„|jddDƒƒ}|S)NrcSsg|] }|d‘qS)rcr)rQržrrrrUGrVz(CompositeCanvas.cols..r/)r˜r )rGr_rrrr_DszCompositeCanvas.colsccsDg}|jD]4\}}t||ƒ}t|ƒD]}t|ƒVq$t||ƒ}q dS)zz Return the canvas content as a list of rows where each row is a list of (attr, cs, text) tuples. N)r˜Ú shard_bodyr{Úshard_body_rowÚshard_body_tail)rGÚ shard_tailÚnum_rowsÚcviewsÚsbodyrƒrrrrYLs    zCompositeCanvas.contentccs’t|dƒs"| ¡D] }|VqdSg}t|j|jƒD]X\}}t||ƒ}g}t|ƒD].}t|ƒdksrt|dƒtkrzt |ƒ}|VqRt ||ƒ}q4dS)r–r˜Nr/r) rrYÚ shards_deltar˜r¡r{ryrwÚintr¢r£)rGrŒrXr¤r¥r¦r§rƒrrrra_s  ÿ   zCompositeCanvas.content_deltacCsX|jr |j‚|rt|j|ƒ|_|dkr.g|_n|durDt|j|ƒ|_| d| ¡|_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 rN)rrIÚshards_trim_topr˜Úshards_trim_rowsrsrE)rGrkÚcountrrrÚtrim{s zCompositeCanvas.trimcCs&|jr |j‚t|j| ¡|ƒ|_dS)ziTrim lines from the bottom of the canvas. end -- number of lines to remove from the end N)rrIr«r˜r`)rGr“rrrÚtrim_end’szCompositeCanvas.trim_endc Csî|jr |j‚|j}|dks"|dkrRtd| ƒ}| ¡|td| ƒ}t|||ƒ}| ¡}|dksj|dkrÖ|d\}}|dkr–dd||dtfg|} n |dd…} |dkrÀ|  dd||dtf¡|| fg|dd…}|  |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/) rrIr˜rzr_Úshards_trim_sidesr`Ú blank_canvasrrsrE) rGrjÚrightr˜r]r_r`Ztop_rowsZ top_cviewsZnew_top_cviewsrrrÚpad_trim_left_right s.   ÿÿ ÿz#CompositeCanvas.pad_trim_left_rightc CsÔ|jr |j‚|j}|dks"|dkrRtd| ƒ}| ¡|td| ƒ}| ||¡| ¡}|dkr�|dd||dtfgfg|j|_| d|¡|_ |dkrÐ||jur²|jdd…|_|j  |dd||dtfgf¡dS)z@ Pad or trim this canvas on the top and bottom. rN) rrIr˜rzr`r­r_r°rsrEr)rGrkÚbottomZ orig_shardsr^r`r_rrrÚpad_trim_top_bottomÂs*  ÿþ ÿz#CompositeCanvas.pad_trim_top_bottomcCs|jr |j‚| ¡}| ¡}| ¡||}| ¡||}|j}g} |j} g} |rht||ƒ} t||ƒ} |r€t| |ƒ} t| |ƒ} g} g} |dkržt| d|ƒg} |dkr¾t| td||ƒ|ƒg} | ¡sÌg}n$|sÔ|rêt | |jg| ƒ}n|j}| || |_|j   |  ||¡¡dS)zOverlay other onto this canvas.rN) rrIr_r`r˜rªr«r¯rzÚ shards_joinrEršrs)rGrŒrjrkÚwidthZheightr±r³r˜Z top_shardsZ side_shardsZ bottom_shardsZ left_shardsZ right_shardsZ middle_shardsrrrÚoverlayÝsF    ÿÿÿzCompositeCanvas.overlaycCs| d|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)rGrˆrrrÚ fill_attr szCompositeCanvas.fill_attrcsÄ|jr |j‚g}|jD]¢\}}g}|D]‚}|ddur\| |dd…ˆf|dd…¡q&tˆƒ}| ‡fdd„|d ¡Dƒ¡| |dd…|f|dd…¡q&| ||f¡q||_dS)z� Apply an attribute-mapping dictionary to the canvas. mapping -- dictionary of original-attribute:new-attribute items éNécs g|]\}}|ˆ ||¡f‘qSr)r1)rQÚkÚv©ÚmappingrrrU$sz3CompositeCanvas.fill_attr_apply..)rrIr˜rÚdictršrm)rGr¿r˜r¥Zoriginal_cviewsÚ new_cviewsržZcombinedrr¾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)rrIr)rGZ widget_listrrrÚ set_depends+szCompositeCanvas.set_depends)N)N)r;r<r=r>rHr`r_rYrar­r®r²r´r·r¹r¸rÂrrrrr—s "  "-r—cCsdg}|D]V\}}}|r&| t|ƒ¡q|rPt|dƒtkrP|d|d|d<q| |d¡q|S)zx Return one row, advancing the iterators in sbody. ** MODIFIES sbody by calling next() on its iterators ** éÿÿÿÿrc)rÚnextrwr©r)r§rXÚ done_rowsÚ content_iterÚcviewrrrr¢7sr¢c Cs`g}d}d}|D]J\}}}|dd…\}}||7}||krD||7}q| ||||f¡d}q|S)z? Return a new shard tail that follows this shard body. rrcrº)r) r¥r§r¤Úcol_gaprÅrÆrÇr_r`rrrr£Ksr£c csœt|ƒ}d}}d}}|D]z\}}|dur8t|ƒ\}}||krV||7}t|ƒ\}}q8||krr||fV||7}q|t||ƒfV||7}d}||7}qdS)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_cviewsZdoneZ other_doner¥r¦rrrr¨]s"   r¨ccsÖt|ƒ}d}d}}|D]¸}|dur,t|ƒ}||krJ||d7}t|ƒ}q,||krf|V||d7}q|d|dur®|dd…|dd…kr®|dd…d|dd…Vn|V||d7}d}||d7}qdS)z Nrrcr»rKé)rÉrÄ)r¦rËZother_cviews_iterZother_cvr_Z other_colsržrrrrÊus&   (  rÊTc Csd}g}t|ƒ}|D]®\}}} } |r²z t|ƒ} WntyFYq²Yn0| dd…\} } }}}}||7}||8}|dkr€tdƒ‚|rœ|rœ| | | |||¡}n|}| d|| f¡q | || | f¡q|D]P} | dd…\} } }}}}|�r|�r| | | |||¡}n|}| d|| f¡qÈ|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. rNrÌz#cviews overflow gaps in shard_tail!)rÉrÄÚ StopIterationr@rYr)r¦r¤Z create_iterZ iter_defaultr”ÚbodyZ cviews_iterrÈrÅrÆZ tail_cviewrÇr]r^r_r`r†rZnew_iterrrrr¡�s@     ÿÿ ÿ  ÿr¡c Csºt|ƒ}g}|D]2\}}||kr$qLt||dƒ}t||ƒ}||8}qtdƒ‚t||dƒ}t||ƒ}g}|D]$\}} } | d| t| ||ƒf¡qj|}||dd„|Dƒfg} |  |¡| S)z. Return shards with top rows removed. Fz%tried to trim shards out of existencercSsg|]\}}}|‘qSrr)rQrÅrÆržrrrrUÛrVz#shards_trim_top..)rÉr¡r£r@rÚcview_trim_topr) r˜rkZ shard_iterr¤r¥r¦r§Z new_sbodyrÅrÆržÚ new_shardsrrrrª¿s,       ÿ ÿ rªcCsšg}d}|D]ˆ\}}||kr q–g}|D]4}|d||krR| t|||ƒ¡q(| |¡q(|||kr~| |||f¡n| ||f¡||7}q |S)z8 Return the topmost keep_rows rows from shards. ré)rÚcview_trim_rows)r˜Z keep_rowsrÐrÅr¥r¦rÁržrrrr«âs" ÿ   r«cCsèg}g}||}|D]Î\}}t||dƒ}t||ƒ}g} d} |D]r\} } } | d}| |}| sl||ksl| |krr|} q>| |krŒt| || ƒ} |} ||kr¢t| || ƒ} |  | ¡|} q>| sÔ|d\}}|||f|d<q| || f¡q|S)zL Return shards with starting from column left and cols total width. FrrcrÃ)r¡r£Úcview_trim_leftÚcview_trim_colsr)r˜rjr_r¤rÐr±r¥r¦r§rÁr”rÅrÆržZcv_colsZnext_colZ prev_num_rowsZ prev_cviewsrrrr¯ýs4     r¯c CsÐdd„|Dƒ}dd„|Dƒ}g}g}tdd„|Dƒƒ}g}|D](\}}|rT| |¡| ||df¡q>|}| ||f¡z8tt|ƒƒD]&} || ddkržqˆt|| ƒ|| <qˆWq tyÈYqÌYq 0q |S)zx Return the result of joining shard lists horizontally. All shards lists must have the same number of rows. cSsg|] }t|ƒ‘qSr)rÉ)rQÚslrrrrU#rVzshards_join..cSsg|] }t|ƒ‘qSr)rÄ)rQrƒrrrrU$rVcSsg|] \}}|‘qSrrrœrrrrU)rVNr)Úminrrr{ryrÄrÍ) Ú shard_listsZ shards_itersZshards_currentrÐrÁr¥Z shards_nextr`r¦rƒrrrrµs(    rµcCs|dd…|f|dd…S)NrÑrºr)ržr`rrrrÒ?srÒcCs0|d||d|d|d|f|dd…S)Nrr/rcrÑrºr©ržr­rrrrÏBsrÏcCs*|d||d|d|f|dd…S)Nrr/rcrÑrrØrrrrÓEsrÓcCs|dd…|f|dd…S)NrcrÑr)ržr_rrrrÔHsrÔc CsÚdd„|Dƒ}tƒ}g}g}d}d}d}|D]r\}} } | r>|}| d||| f¡| |j¡|j | d|¡¡|j ¡D]} | |j| <qz||  ¡7}|d7}q,|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—)rQrÚpÚfrrrrUZrVz!CanvasCombine..rr/N) r—rrr˜rEršrsrFÚkeysr`r) ÚlZclistZcombined_canvasr˜rrXZ focus_indexÚnrrr,r›rrrÚ CanvasCombineNs0     ÿrÞcCsTt|ƒ}| |||¡|||dfdd|dfg|_i|_|j ¡D]}d|j|<q@|S)zE Overlay canvas top_c onto bottom_c at position (left, top). NrZfg)r—r·rrFrÛ)Ztop_cZbottom_crjrkZoverlayed_canvasr›rrrÚ CanvasOverlayvs  ÿ rßcCsPg}d}d}d}|D]N\}}}}| ¡} || ¡} |r<|}| |krH| }| ||| | f¡|d7}qg} g} tƒ} d}|D]”\}}} } t|ƒ}| rž| d| ¡| |kr¶| d|| ¡| j | |d¡¡|j   ¡D]}|| j |<qÔ|  |j ¡|  |d||f¡|| ¡7}qz|�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)r`r_rr—r²r´rEršrsrFrÛr˜rµr)rÜÚl2Z focus_itemr‡rÝrrr,r_r`Z pad_rightr×rZ joined_canvasr”r›rrrÚ CanvasJoin„sH     ÿ rács¬g}g}g}Gdd„dƒ}|‰dˆ_dˆ_‡‡fdd„‰|D�]\}t|ˆd|ƒ}g} g‰g} ‡‡‡fdd„} |D�]} t| ƒ} | jrÆtˆ| j| j…ƒ\}}|  |¡| | j| jt|ƒƒt | |ƒqp| j �rt| j ƒ\}}|  |¡| | j| jt |ƒƒt | |ƒqp| j�r>| j �rr|  t ƒ | j ¡¡| | j| j| j ƒqp|  t ƒ | j ¡¡ˆ d| j f¡|  d| j f¡qp| t ƒ | ¡¡| ˆ¡| | ¡q.AttrWalkNrArrrrÚAttrWalkÂsrârcsô|ˆjkrdˆ_dˆ_g}ˆj|krðtˆƒˆjkrN| d|t|ˆjƒf¡qðˆˆj\}}ˆj||krˆˆjd7_ˆj|7_q|ˆj|kr²| ||t|ˆjƒf¡qð| |ˆj|t|ˆjƒf¡ˆjd7_ˆj|7_q|S)z9Return an attribute list for the range of text specified.rNr/)Úoffr¼ryrrz)Ú start_offsÚend_offsÚoÚatr‰)rRÚawrrÚarangeÈs(   z!apply_text_layout..arangec sÚ||kr*ˆ||ƒ\\}}tˆ||fƒdS|||kr\ˆ||ƒD]\}}tˆ||fƒq@dS|}ˆ||ƒD]j\}}|||kr’tˆ||fƒdSˆ|||…}t|ƒ\}}t|ƒ}tˆ||fƒ||7}||8}qjdS)zi Add attributes based on attributes between start_offs and end_offs. N)rr r) räråZdestwrçr‰ræÚtsegrSZsegw)réÚlinearTrrÚ attrrangeës&   z$apply_text_layout..attrrange)r�)r¼rãr r r“r ZoffsrrrrTryZscrr|rWru)rTrRZlsr�r‚rˆrrâZ line_layoutr�ZlinecrìÚsegÚsrêrSr)rérRrèrërTrÚapply_text_layout½sN  ÿ      rï)TN)-Z __future__rrr$Z urwid.utilrrrrrr r r Zurwid.text_layoutr r Z urwid.compatrÚobjectrÚ Exceptionr@rBrur�r°r‘r—r¢r£r¨rÊr¡rªr«r¯rµrÒrÏrÓrÔrÞrßrárïrrrrÚsD( ,% /#!!(9