"TeddlmZddlmZmZmZmZmZddlm Z ddl m Z m Z er ddl mZmZmZGddeZd d d d d edddfdZy)) itemgetter) TYPE_CHECKINGCallable NamedTupleOptionalSequence)errors) is_renderable rich_cast)ConsoleConsoleOptionsRenderableTypeceZdZUdZeed< eed< edefdZddZdeddfdZ deddfd Z dd e ed e eddfd Z e ddZy ) MeasurementzSStores the minimum and maximum widths (in characters) required to render an object.minimummaximumreturnc4|j|jz S)z+Get difference between maximum and minimum.)rr)selfs ./usr/lib/python3/dist-packages/rich/measure.pyspanzMeasurement.spans||dll**c |\}}ttd||}ttd|tdt||S)zGet measurement that ensures that minimum <= maximum and minimum >= 0 Returns: Measurement: A normalized measurement. r)minmaxr)rrrs r normalizezMeasurement.normalizesA  c!Wow/3q'?C3w3H,IJJrwidthcL|\}}tt||t||S)zGet a RenderableWith where the widths are <= width. Args: width (int): Maximum desired width. Returns: Measurement: New Measurement object. )rrrrrrs r with_maximumzMeasurement.with_maximum"s) 3w.GU0CDDrcd|\}}td|}tt||t||S)zGet a RenderableWith where the widths are >= width. Args: width (int): Minimum desired width. Returns: Measurement: New Measurement object. r)rrr s r with_minimumzMeasurement.with_minimum.s4 Au 3w.GU0CDDrN min_width max_widthcV|}||j|}||j|}|S)aNClamp a measurement within the specified range. Args: min_width (int): Minimum desired width, or ``None`` for no minimum. Defaults to None. max_width (int): Maximum desired width, or ``None`` for no maximum. Defaults to None. Returns: Measurement: New Measurement object. )r#r!)rr$r% measurements rclampzMeasurement.clamp;s;  %229=K  %229=Krc|j}|dkr tddSt|tr|j ||j d}t |}t|rlt|dd}|Q|||jj|}|jdkr tddS|jStd|Stjd|d) aGet a measurement for a renderable. Args: console (~rich.console.Console): Console instance. options (~rich.console.ConsoleOptions): Console options. renderable (RenderableType): An object that may be rendered with Rich. Raises: errors.NotRenderableError: If the object is not renderable. Returns: Measurement: Measurement object containing range of character widths required to render the object. r rF)markup highlight__rich_measure__NzUnable to get render width for zD; a str, Segment, or object with __rich_console__ method is required)r%r isinstancestr render_strr*r r getattrrr!rr NotRenderableError)clsconsoleoptions renderable _max_widthget_console_width render_widths rgetzMeasurement.getNs"&& >q!$ $ j# & ++7>>U,Jz*  $ $6= !,%gw7Y[!\*-  ''!+&q!,,#--//"1j11++1*@UU r)rr)NN)r3r r4rr5rrr)__name__ __module__ __qualname____doc__int__annotations__propertyrrr!r#rr( classmethodr9rrrr s] L5 L5 +c++K E# E- E E# E- EKO!#:B3- &++*:+HX+ ++rrr3r r4r renderablesrrc  |s tddStj}|Dcgc] }||||}}tt|tdjt|tdj }|Scc}w)aGet a measurement that would fit a number of renderables. Args: console (~rich.console.Console): Console instance. options (~rich.console.ConsoleOptions): Console options. renderables (Iterable[RenderableType]): One or more renderable objects. Returns: Measurement: Measurement object containing range of character widths required to contain all given renderables. r)keyr )rr9rrrr)r3r4rCget_measurementr5 measurementsmeasured_widths rmeasure_renderablesrI}s 1a  !ooOHS:D*5L! Ljm,44 Ljm,44N sBN)operatorrtypingrrrrrr protocolr r r3r rrrrIrBrrrNs[JJ.@@o*od  *+ r