U cf@sddlmZddlmZmZmZmZmZddlm Z ddl m Z m Z er\ddl mZmZmZGdddeZd d ed dd d dZdS)) itemgetter) TYPE_CHECKINGCallable NamedTupleOptionalSequence)errors) is_renderable rich_cast)ConsoleConsoleOptionsRenderableTypec@seZdZUdZeed<eed<eedddZddddZedd d d Z edd d d Z de ee eddddZ e dddddddZdS) MeasurementzSStores the minimum and maximum widths (in characters) required to render an object.minimummaximum)returncCs |j|jS)z+Get difference between maximum and minimum.)rr)selfrF/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/measure.pyspanszMeasurement.spancCs4|\}}ttd||}ttd|tdt||S)zGet measurement that ensures that minimum <= maximum and minimum >= 0 Returns: Measurement: A normalized measurement. r)minmaxr)rrrrrr normalizeszMeasurement.normalize)widthrcCs|\}}tt||t||S)zGet a RenderableWith where the widths are <= width. Args: width (int): Maximum desired width. Returns: Measurement: New Measurement object. )rrrrrrrrr with_maximum"s zMeasurement.with_maximumcCs(|\}}td|}tt||t||S)zGet a RenderableWith where the widths are >= width. Args: width (int): Minimum desired width. Returns: Measurement: New Measurement object. r)rrrrrr with_minimum.s  zMeasurement.with_minimumN) min_width max_widthrcCs,|}|dk r||}|dk r(||}|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. N)rr)rrr measurementrrrclamp;s   zMeasurement.clampr r r)consoleoptions renderablercCs|j}|dkrtddSt|tr4|j||jdd}t|}t|rt|dd}|dk r||| |}|j dkrtddS| Std|Snt d|ddS) 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. rrF)markup highlight__rich_measure__NzUnable to get render width for zD; a str, Segment, or object with __rich_console__ method is required)rr isinstancestr render_strr%r r getattrrrrr NotRenderableError)clsr"r#r$ _max_widthget_console_width render_widthrrrgetNs2       zMeasurement.get)NN)__name__ __module__ __qualname____doc__int__annotations__propertyrrrrrr! classmethodr1rrrrr s*    rr r r)r"r# renderablesrcsT|stddStjfdd|D}tt|tddjt|tddj}|S)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. rcsg|]}|qSrr).0r$r"get_measurementr#rr sz'measure_renderables..)keyr)rr1rrrr)r"r#r: measurementsmeasured_widthrr<rmeasure_renderables}s rBN)operatorrtypingrrrrrr protocolr r r"r r rrrBrrrrs  s