o
    MEg                     @   s   d dl mZ d dlmZmZmZmZmZ ddlm	Z	 ddl
mZ er,ddlmZmZmZ G dd deZd	d
ddded ddfddZdS )    )
itemgetter)CallableIterable
NamedTupleOptionalTYPE_CHECKING   )errors)is_renderable)ConsoleConsoleOptionsRenderableTypec                   @   s   e Zd ZU dZeed< 	 eed< 	 edefddZdddZd	edd fd
dZ	d	edd fddZ
	ddee dee dd fddZe								 dddZdS )MeasurementzSStores the minimum and maximum widths (in characters) required to render an object.minimummaximumreturnc                 C   s   | j | j S )z+Get difference between maximum and minimum.)r   r   )self r   f/var/www/eduai.edurigo.com/doc_train/edurigo_ai/Puru/venv/lib/python3.10/site-packages/rich/measure.pyspan   s   zMeasurement.spanc                 C   s4   | \}}t td||}ttd|tdt||S )zGet measurement that ensures that minimum <= maximum and minimum >= 0

        Returns:
            Measurement: A normalized measurement.
        r   )minmaxr   )r   r   r   r   r   r   	normalize   s   zMeasurement.normalizewidthc                 C   s   | \}}t t||t||S )zGet a RenderableWith where the widths are <= width.

        Args:
            width (int): Maximum desired width.

        Returns:
            Measurement: New Measurement object.
        )r   r   r   r   r   r   r   r   r   with_maximum"   s   	zMeasurement.with_maximumc                 C   s(   | \}}t d|}tt ||t ||S )zGet a RenderableWith where the widths are >= width.

        Args:
            width (int): Minimum desired width.

        Returns:
            Measurement: New Measurement object.
        r   )r   r   r   r   r   r   with_minimum.   s   	
zMeasurement.with_minimumN	min_width	max_widthc                 C   s,   | }|dur| |}|dur||}|S )aN  Clamp 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)r   r   )r   r   r   measurementr   r   r   clamp;   s   

zMeasurement.clampconsoler   optionsr   
renderabler   c                 C   s   |j }|dk rtddS t|tr|j||jd}t|dr"| }t|rMt	|dd}|durH|||
 |}|jdk rDtddS |
 S td|S td|d)	a  Get 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   r   )markup__rich____rich_measure__NzUnable to get render width for zD; a str, Segment, or object with __rich_console__ method is required)r   r   
isinstancestr
render_strr$   hasattrr%   r
   getattrr   r   r   r	   NotRenderableError)clsr!   r"   r#   
_max_widthget_console_widthrender_widthr   r   r   getN   s,   







zMeasurement.get)r   r   )NN)r!   r   r"   r   r#   r   r   r   )__name__
__module____qualname____doc__int__annotations__propertyr   r   r   r   r   r    classmethodr1   r   r   r   r   r      s:   
 


r   r!   r   r"   r   renderablesr   r   c                    sT   |st ddS t j fdd|D }t t|tddjt|tddj}|S )a  Get a measurement that would fit a number of renderables.

    Args:
        console (~rich.console.Console): Console instance.
        renderables (Iterable[RenderableType]): One or more renderable objects.
        max_width (int): The maximum width available.

    Returns:
        Measurement: Measurement object containing range of character widths required to
        contain all given renderables.
    r   c                    s   g | ]} |qS r   r   ).0r#   r!   get_measurementr"   r   r   
<listcomp>   s    z'measure_renderables.<locals>.<listcomp>)keyr   )r   r1   r   r   r   r   )r!   r"   r:   measurementsmeasured_widthr   r<   r   measure_renderables|   s   
rB   N)operatorr   typingr   r   r   r   r    r	   protocolr
   r!   r   r   r   r   rB   r   r   r   r   <module>   s     q