8f^DddlmZddlmZddlmZddlmZddlm Z ddl m Z m Z m Z mZmZmZmZmZmZmZddlmZmZmZmZmZdd lmZmZdd lmZe r dd l m!Z!m"Z"m#Z#ed Z$Gd deZ%eee%ee%ee&e'ffee%e&e&ffZ(eGddeZ)GddZ*GddZ+e,dkr?ddl-m!Z!ddl.m/Z/ddl0m1Z1dZ2e1j3dZ4e!Z e 5de 6de 6de 6e/e2dd e 6e 6d!e7e 8e4Z9e 6e9e 6e 6d"e 6e4e 6d#d$Sd$S)%)IntEnum) lru_cache) filterfalse) getLogger) attrgetter) TYPE_CHECKINGDictIterableList NamedTupleOptionalSequenceTupleTypeUnion)_is_single_cell_widthscached_cell_lencell_lenget_character_cell_size set_cell_size)Result rich_repr)Style)ConsoleConsoleOptions RenderResultrichcReZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdS) ControlTypezDNon-printable control codes which typically translate to ANSI codes.r N)__name__ __module__ __qualname____doc__BELLCARRIAGE_RETURNHOMECLEAR SHOW_CURSOR HIDE_CURSORENABLE_ALT_SCREENDISABLE_ALT_SCREEN CURSOR_UP CURSOR_DOWNCURSOR_FORWARDCURSOR_BACKWARDCURSOR_MOVE_TO_COLUMNCURSOR_MOVE_TO ERASE_IN_LINESET_WINDOW_TITLEx/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/rich/segment.pyr r #sjNN DO D EKKIKNONMrEr cXeZdZUdZeed<dZeeed<dZ ee e ed<e de fdZdefdZdefd Ze defd Zeed d dd e dedfdZd e dedfdZed1dZe d2deddeedeededfdZe d3deddededfdZededdeedfdZe d4dedde deedededeedf dZe d5dedde deedededf dZ ededde fd Z!ed!eeddee e ffd"Z"e d6d!eedd#e d$ee deed%edeedf d&Z#e d3d'e$dd!eedd#e d$e ded%edeedfd(Z%e d3d'e$dd!eedd#e d$e ded%edeedfd)Z&e d3d'e$dd!eedd#e d$e ded%edeedfd*Z'ededdedfd+Z(ededdedfd,Z)ededdedfd-Z*ededdedfd.Z+ededd/ee deedfd0Z,dS)7SegmentaA piece of text with associated style. Segments are produced by the Console render process and are ultimately converted in to strings to be written to the terminal. Args: text (str): A piece of text. style (:class:`~rich.style.Style`, optional): An optional style to apply to the text. control (Tuple[ControlCode], optional): Optional sequence of control codes. Attributes: cell_length (int): The cell length of this Segment. textNstylecontrolreturnc4|\}}}|rdnt|S)zzThe number of terminal cells required to display self.text. Returns: int: A number of cells. r)r)selfrI_stylerKs rF cell_lengthzSegment.cell_lengthQs%!%fg/qq$/rEc#vK|jV|j|j |jVdSdS|jV|jVdSN)rIrKrJrNs rF __rich_repr__zSegment.__rich_repr__[sai < z%j     &%*   ,     rEc*t|jS)z#Check if the segment contains text.)boolrIrSs rF__bool__zSegment.__bool__dsDIrEc|jduS)z,Check if the segment contains control codes.N)rKrSs rF is_controlzSegment.is_controlhs|4''rEi@segmentcut)rHrHc|\}}}t}|j}||kr||d||fSt}t||z t |dz z} |d| } t | } | |kr"|| ||||| d||fS| t |kr|| } | dz } | || z } |d| } | |kr"|| ||||| d||fS| |kr3|| d| dz dz|||d|| dz||fS| t |kt d)Nr zWill never reach here)rHrPrintlenrAssertionError) clsrZr[rIrJrK_SegmentrP cell_sizeposbeforecell_poschars rF _split_cellszSegment._split_cellsms 'eW) +  HHR888 8+ 3$TQ788dsdF## s??00cddUG44 CIIoo9D 1HC  $ 'H$3$ZF3HVUG44HT#$$Z88#~~HVIcAgI.4eWEEHS4:-ug>>CIIoo 4555rEc|\}}}t|rX|t|kr|td||fSt|d|||t||d||fS|||S)a0Split segment in to two segments at the specified column. If the cut point falls in the middle of a 2-cell wide character then it is replaced by two spaces, to preserve the display width of the parent segment. Returns: Tuple[Segment, Segment]: Two segments. r]N)rr`rHri)rNr[rIrJrKs rF split_cellszSegment.split_cellss $eW !$ ' ' c$iiWR8888TcT E733STT E733    s+++rEc|dS)zMake a new line segment. rD)rbs rFlinez Segment.liness4yyrEsegments post_stylecb|}|r|jfd|D}rfd|D}|S)aApply style(s) to an iterable of segments. Returns an iterable of segments where the style is replaced by ``style + segment.style + post_style``. Args: segments (Iterable[Segment]): Segments to process. style (Style, optional): Base style. Defaults to None. post_style (Style, optional): Style to apply on top of segment style. Defaults to None. Returns: Iterable[Segments]: A new iterable of segments (possibly the same iterable). c3TK|]"\}}}||rdn ||V#dSrRrD).0rIrOrKapplyrbs rF z&Segment.apply_style..s\)D&'D'<$$uuV}}gFFrEc3PK|] \}}}||rdn|r|zn|V!dSrRrD)rsrIrOrKrbrps rFruz&Segment.apply_style..sr  *D&'#M5;Kfz11      rE)__add__)rbrorJrpresult_segmentsrts` ` @rF apply_stylezSegment.apply_styles&#  ME-<O       .=   OrEFrYcz|rttd|Sttd|S)a2Filter segments by ``is_control`` attribute. Args: segments (Iterable[Segment]): An iterable of Segment instances. is_control (bool, optional): is_control flag to match in search. Returns: Iterable[Segment]: And iterable of Segment instances. rK)filterrr)rbrorYs rFfilter_controlzSegment.filter_controls=  @*Y//:: :z)44h?? ?rEc#Kg}|j}|D]g}d|jvrQ|jsJ|\}}}|rA|d\}} }|r||||| r |Vg}|j}|A\||h|r|VdSdS)aSplit a sequence of segments in to a list of lines. Args: segments (Iterable[Segment]): Segments potentially containing line feeds. Yields: Iterable[List[Segment]]: Iterable of segment lists, one per line. rmN)appendrIrK partition) rbrornr~rZrIrJ__textnew_lines rF split_lineszSegment.split_liness! Gw|##GO#!(eQ-,0NN4,@,@)E8T2ss5%00111-" !!%-w  JJJJJ  rETlengthpadinclude_new_linesc#Kg}|j}|j}|d} |D]} d| jvr| js{| \} } } | rr| d\}}} |r|||| |r>|||||}|r|| |V|| r|| |r|||||VdSdS)aSplit segments in to lines, and crop lines greater than a given length. Args: segments (Iterable[Segment]): An iterable of segments, probably generated from console.render. length (int): Desired line length. style (Style, optional): Style to use for any padding. pad (bool): Enable padding of lines that are less than `length`. Returns: Iterable[List[Segment]]: An iterable of lines of segments. rm)rJrN)r~adjust_line_lengthrIrKrclear)rbrorrJrrrnr~rnew_line_segmentrZrI segment_stylerrr cropped_lines rFsplit_and_crop_lineszSegment.split_and_crop_linessV*! 33t99  Gw|##GO#)0&mQ %,0NN4,@,@)E8T:ss5-88999%'9'9 &3((( -B(//0@AAA****  %w  I$$T6CHHH H H H H H I IrErncztd|D}||kr$|r||d||z z|gz}n|dd}nw||krgg}|j}d}|D]X}|j} || z|ks|jr|||| z }*|\} } } t | ||z } ||| | n |dd}|S)aAdjust a line to a given width (cropping or padding as required). Args: segments (Iterable[Segment]): A list of segments in a single line. length (int): The desired width of the line. style (Style, optional): The style of padding if used (space on the end). Defaults to None. pad (bool, optional): Pad lines with spaces if they are shorter than `length`. Defaults to True. Returns: List[Segment]: A line of segments with the desired length. c3$K|] }|jV dSrR)rP)rsrZs rFruz-Segment.adjust_line_length..Js%BB''-BBBBBBrEr^Nr)sumr~rPrKr) rbrnrrJr line_lengthrr~rZsegment_lengthrIrrs rFrzSegment.adjust_line_length7s&BBTBBBBB     #33sf{.B'CU#K#K"LL7 6 ! !H_FK  !(!4/&88GO8F7OOO>1KK-4*D-(v /CDDDF33t]33444AAAwHrEcHttfd|DS)zGet the length of list of segments. Args: line (List[Segment]): A line encoded as a list of Segments (assumes no '\\n' characters), Returns: int: The length of the line. c3:K|]\}}}||VdSrRrD)rsrIrJrK _cell_lens rFruz*Segment.get_line_length..os7SS';tUG7S99T??SSSSSSrE)rr)rbrnrs @rFget_line_lengthzSegment.get_line_lengthds- SSSStSSSSSSrElinescr|j|rtfd|Dnd}|t|fS)zGet the shape (enclosing rectangle) of a list of lines. Args: lines (List[List[Segment]]): A list of lines (no '\\n' characters). Returns: Tuple[int, int]: Width and height in characters. c3.K|]}|VdSrRrD)rsrnrs rFruz$Segment.get_shape..|s-@@$--@@@@@@rEr)rmaxr`)rbr max_widthrs @rF get_shapezSegment.get_shapeqsJ-DIPC@@@@%@@@@@@q 3u::&&rEwidthheight new_linesc< |pt|}|r|dzdzgn|dzg}|j |d|} fd|D|dd<t||kr)||g|t|z z|S)aSet the shape of a list of lines (enclosing rectangle). Args: lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style, optional): Style of any padding added. new_lines (bool, optional): Padded lines should include " ". Defaults to False. Returns: List[List[Segment]]: New list of lines. r^rmNc,g|]}|S))rJrD)rsrnrrJrs rF z%Segment.set_shape..s9   =A  tU% 8 8 8   rE)r`rextend) rbrrrrJr_heightblank shaped_linesrs ` ` @rF set_shapezSegment.set_shapes*&CJJ1: XSSut#U + + , ,C%KQV@W@W?X !3XgX       EJ   QQQ |  w & &   7S5F5F+F G H H HrErbc|t|z }|s |ddS|d|}|r|d|zdz|n|d|z|}||gg|zz}|S)aAligns lines to top (adds extra lines to bottom as required). Args: lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style): Style of any padding added. new_lines (bool, optional): Padded lines should include " ". Defaults to False. Returns: List[List[Segment]]: New list of lines. Nr^rmr`rbrrrrJr extra_linesrs rF align_topzSegment.align_tops*s5zz)  8Ogvg2;XC%K$&...S5[RWAXAX% K// rEc|t|z }|s |ddS|d|}|r|d|zdz|n|d|z|}|gg|z|z}|S)aAligns render to bottom (adds extra lines above as required). Args: lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style): Style of any padding added. Defaults to None. new_lines (bool, optional): Padded lines should include " ". Defaults to False. Returns: List[List[Segment]]: New list of lines. Nr^rmrrs rF align_bottomzSegment.align_bottoms*s5zz)  8Ogvg2;XC%K$&...S5[RWAXAX K'%/ rEc|t|z }|s |ddS|d|}|r|d|zdz|n|d|z|}|dz}||z } |gg|z|z|gg| zz}|S)aAligns lines to middle (adds extra lines to above and below as required). Args: lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style): Style of any padding added. new_lines (bool, optional): Padded lines should include " ". Defaults to False. Returns: List[List[Segment]]: New list of lines. Nr^rmr!r) rbrrrrJrrr top_lines bottom_liness rF align_middlezSegment.align_middles*s5zz)  8Ogvg2;XC%K$&...S5[RWAXAX1$ "Y.  I%-% L0HH rEc#Kt|} t|}n#t$rYdSwxYwt}|D]>}|j|jkr&|js||j|jz|j}8|V|}?|VdS)a)Simplify an iterable of segments by combining contiguous segments with the same style. Args: segments (Iterable[Segment]): An iterable of segments. Returns: Iterable[Segment]: A possibly smaller iterable of segments that will render the same way. N)iternext StopIterationrHrJrKrI)rbro iter_segments last_segmentrcrZs rFsimplifyzSegment.simplifysX   ..LL    FF $ ' 'G!W]227?2'x % 4l6H   #"""& s # 11c#K|D]@}|js|j|V|\}}}|||r|dndVAdS)zRemove all links from an iterable of styles. Args: segments (Iterable[Segment]): An iterable segments. Yields: Segment: Segments with link removed. N)rKrJ update_link)rbrorZrIrJ_controls rF strip_linkszSegment.strip_linkss  L LG L'-"7 (/%eXc$5 J 1 1$ 7 7 7dKKKKKK  L LrEc#:K|D]\}}}||d|VdS)zRemove all styles from an iterable of segments. Args: segments (Iterable[Segment]): An iterable segments. Yields: Segment: Segments with styles replace with None NrD)rbrorIrOrKs rF strip_styleszSegment.strip_styles(sE&. + + !D&'#dD'** * * * * + +rEc#Ki}|D]J\}}}|r3||}| |j}|||<||||V;||d|VKdS)zRemove all color from an iterable of segments. Args: segments (Iterable[Segment]): An iterable segments. Yields: Segment: Segments with colorless style. N)get without_color)rbrocacherIrJrKcolorless_styles rF remove_colorzSegment.remove_color5s%'$, / / D% /"'))E"2"2"*&+&9O#2E%Lc$999999c$g...... / /rEcutsc#Kg}|j}t|} t|d}|dkrgS|dkrngV$d}|j}|j} t } |D]} | \} } }| r|r|n || | z}||kr|| |}n||krK|| | V||}t|d}|dkr|r | VdSnm| ||z \}} | \} } }||| V||}t|d}|dkr|r | VdS| | VdS)zDivides an iterable of segments in to portions. Args: cuts (Iterable[int]): Cell positions where to divide. Yields: [Iterable[List[Segment]]]: An iterable of Segments in List. TrN)r~rrrcopyrrk)rbrorsplit_segments add_segment iter_cutsr[resegments_clear segments_copyrrZrIrOrKend_posrfs rFdividezSegment.divideKs+-$+ JJ  y"%%Cbyy axxHHH  '-&+ # # # G$+ !D&'! !(C##cIIdOO.CS==K(((!Cc>>K((('-//)))"N$$$!Cy"--Cbyy)2"/-//111'.&9&9#)&D&DOFG,3)D&'K''''-//)))"N$$$C9b))"99%.+moo---FFC! FmoorE)rLrH)NNF)NTT)NT)NNF)-r0r1r2r3str__annotations__rJr rrKr ControlCodepropertyr_rPrrTrVrWrY classmethodrrrirkrnr ryr|r rrrrrrrrrrrrrrrrDrErFrHrH?s   III!E8E?!!!/3GXh{+ ,333 0S000X0v$(D(((X(Yy#69#63#65AU;V#6#6#6[#6J,s,u-A'B,,,,,["&&* &&9%&&UO & )  &&&[&P?D@@ *@8<@ ) @@@[@$8I#68DO;T[8 "&"& ,I,I9%,I,I ,I  ,I  ,I $y/ ",I,I,I[,I\ "& **9o** *  * i ***[*X T4 ? Ts T T T[ T 'd4 ?3 'c3h ' ' '[ ' !%!% !!DO$!! !  !  ! d9o !!![!F  )_DO$      d9o [8  )_DO$      d9o [8  )_DO$      d9o [< 38K[4L8I#6L8I;NLLL[L  +HY$7 +HY %<<>>D=      } $ $ $ $ $ $ $ $ $rErrrrrrLr) r0r1r2r3r rHrVrrrDrErFrrs~##'!2#t#PT#### %  %+; %  % % % % % %rErcPeZdZd deeededdfdZ dd ZdS) SegmentLinesFrrrLNc<t||_||_dS)a=A simple renderable containing a number of lines of segments. May be used as an intermediate in rendering process. Args: lines (Iterable[List[Segment]]): Lists of segments forming lines. new_lines (bool, optional): Insert new lines after each line. Defaults to False. N)rrr)rNrrs rFrzSegmentLines.__init__s%[[ "rErrrrrc#K|jr1t}|jD]}|Ed{V|VdS|jD] }|Ed{V dSrR)rrHrnr)rNrrrrns rFrzSegmentLines.__rich_console__s > ||~~H          rErr) r0r1r2r r rHrVrrrDrErFrrsx # #htG}5 #$ #SW # # # #     +;         rEr__main__)r)Syntax)Textzfrom rich.console import Console console = Console() text = Text.from_markup("Hello, [bold magenta]World[/]!") console.print(text)zHello, [bold magenta]World[/]!z rich.Segmentz]A Segment is the last step in the Rich render process before generating text with ANSI codes.z Consider the following code: pythonT) line_numberszRWhen you call [b]print()[/b], Rich [i]renders[/i] the object in to the following: zAThe Segments are then processed to produce the following output: zS You will only need to know this if you are implementing your own Rich renderables.N):enumr functoolsr itertoolsrloggingroperatorrtypingrr r r r r rrrrcellsrrrrrreprrrrJrrrrrlogr r_rrrHrrr0pip._vendor.rich.consolepip._vendor.rich.syntaxrpip._vendor.rich.textrcode from_markuprIruleprintrrender fragmentsrDrErFrs!!!!!!                        $#######?>>>>>>>>>>i'* + +uS#X &' +sC  "  N N N N N jN N  N b%%%%%%%%2        2 z000000......****** D 4 < = =DgiiG LL    MMg MM4555 MM&&xd;;;<<< MMOOO MM]W^^D))**I MM) MMOOO MMVWWW MM$ MM^;rE