o 7]hy@sddlmZddlmZmZmZmZmZmZm Z m Z e r2ddl m Z m Z mZmZmZmZddlmZddlmZddlmZe dZGd d d ZGd d d Zd S)) zip_longest)IteratorIterableListOptionalUnionoverloadTypeVar TYPE_CHECKING)ConsoleConsoleOptions JustifyMethodOverflowMethod RenderResultRenderableTypeText)cell_len) MeasurementTc@sveZdZdZ ddeedddfddZ   dd dZ   dddZdddZ dedfddZ dS) Renderablesz:A list subclass which renders its contents to the console.N renderablesrreturncCs |dur t||_dSg|_dSN)list _renderables)selfrr=/usr/lib/python3/dist-packages/pip/_vendor/rich/containers.py__init__!szRenderables.__init__consoler optionsr rcc|jEdHdSz,Console render method to insert line-breaks.N)rrr!r"rrr__rich_console__(zRenderables.__rich_console__rcsRfdd|jD}|stddStdd|D}tdd|D}t||S)Ncsg|] }t|qSr)rget).0 renderabler!r"rr 1s z0Renderables.__rich_measure__..r cs|]}|jVqdSr)minimumr) dimensionrrr 7z/Renderables.__rich_measure__..csr-r)maximumr/rrrr18r2)rrmax)rr!r" dimensions_min_maxrr+r__rich_measure__.s   zRenderables.__rich_measure__r*cC|j|dSr)rappend)rr*rrrr:;zRenderables.appendcC t|jSr)iterrrrrr__iter__> zRenderables.__iter__rr!r r"r rr)r!r r"r rr)r*rrN) __name__ __module__ __qualname____doc__rrr r&r8r:r?rrrrrs0    rc @s0eZdZdZd/dedddfddZdefd d Zdedfd d Z e d e ddfddZ e d e dedfddZ d ee e fdededffddZ d e ddddfddZde fddZ      d0ddZd1dd Zdedddfd!d"Zd2d e ddfd$d%Z & 'd3ddd(e d)d*d+d,ddf d-d.ZdS)4Linesz0A list subclass which can render to the console.rlinesrrNcCst||_dSr)r_linesrrGrrrr EzLines.__init__cCsd|jdS)NzLines()rHr>rrr__repr__HrJzLines.__repr__cCr<r)r=rHr>rrrr?Kr@zLines.__iter__indexcCdSrrrrNrrr __getitem__NzLines.__getitem__cCrOrrrPrrrrQRrRcCs |j|SrrLrPrrrrQVr@valuecCs||j|<|SrrL)rrNrSrrr __setitem__Ys zLines.__setitem__cCs |jSr)rH__len__r>rrrrU]r@z Lines.__len__r!r r"r rccr#r$rLr%rrrr&`r'zLines.__rich_console__linecCr9r)rHr:)rrVrrrr:fr;z Lines.appendcCr9r)rHextendrIrrrrWir;z Lines.extendcCs |j|Sr)rHpoprPrrrrYls z Lines.popleftfoldwidthjustifyroverflowrcCs2ddlm}|dkr|jD] }|j||ddq dS|dkrG|jD]#}||j||d||t|jd||t|jq!dS|d krh|jD]}||j||d||t|jqNdS|d krt |jD]\}}|t |jdkrdS| d }t d d |D} t |d} ddt | D} d} | r| | |kr| t | | dd7<| d7} | dt | } | | |ksg} t t||ddD]4\} \}}| || t | kr ||d}||d}||kr|n|j}| |d | | |dq|d| ||<qrdSdS)aJustify and overflow text to a given width. Args: console (Console): Console instance. width (int): Number of characters per line. justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left". overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold". r rrZT)r^padcenter)r^rightfull css|]}t|jVqdSr)rplain)r)wordrrrr1sz Lines.justify..cSsg|]}dqS)r r)r)_rrrr,sz!Lines.justify..rNrX)style)textrrHtruncaterstrippad_leftrre pad_right enumeratelensplitsumrangerr:get_style_at_offsetrhjoin)rr!r\r]r^rrV line_indexwords words_size num_spacesspacesrNtokensrf next_wordrh next_style space_stylerrrr]os^            z Lines.justify)rrA)rVrrN)rX)rZr[)rBrCrDrErr strrMrr?rintrQslicerrrTrUr&r:rWrYr]rrrrrFBsF& rFN) itertoolsrtypingrrrrrrr r r!r r rrrrrjrcellsrmeasurerrrrFrrrrs (    $