o 7]h@sddlmZddlmZmZmZmZmZddlm Z ddl m Z m Z er.ddl mZmZmZGdddeZd d d d d edddfddZdS)) itemgetter)CallableIterable NamedTupleOptional TYPE_CHECKING)errors) is_renderable rich_cast)ConsoleConsoleOptionsRenderableTypec@seZdZUdZeed< eed< edefddZdddZd eddfd d Z d eddfd d Z dde ede eddfddZ e        dddZdS) MeasurementzSStores the minimum and maximum widths (in characters) required to render an object.minimummaximumreturncCs |j|jS)z+Get difference between maximum and minimum.)rr)selfr:/usr/lib/python3/dist-packages/pip/_vendor/rich/measure.pyspans zMeasurement.spancCs4|\}}ttd||}ttd|tdt||S)zGet measurement that ensures that minimum <= maximum and minimum >= 0 Returns: Measurement: A normalized measurement. r)minmaxr)rrrrrr normalizeszMeasurement.normalizewidthcCs|\}}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_widthcCs,|}|dur ||}|dur||}|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.clampconsoler optionsr renderablercCs|j}|dkr tddSt|tr|j||jd}t|}t|rHt|dd}|durC||| |}|j dkr?tddS| Std|St d|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. rr)markup__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_widthrrrgetNs*       zMeasurement.get)rr)NN)r"r r#r r$rrr)__name__ __module__ __qualname____doc__int__annotations__propertyrrrrrr! classmethodr0rrrrr s:     rr"r r#r renderablesrrcsT|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 s z'measure_renderables..)keyr)rr0rrrr)r"r#r9 measurementsmeasured_widthrr;rmeasure_renderables{s rAN)operatorrtypingrrrrrr protocolr r r"r r rrrArrrrs  p