U
    ;»{jD  ã                   @   sÊ   d dl mZ d dlmZ d dlmZmZmZ ddlm	Z	 erHd dl
mZ G dd„ dƒZed	krÆd d
lZd dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ G dd„ dƒZeƒ Ze eƒ ¡ d
S )é    )Úsqrt)Ú	lru_cache)ÚSequenceÚTupleÚTYPE_CHECKINGé   )ÚColorTriplet©ÚTablec                   @   sn   e Zd ZdZeeeeef  dœdd„Zeedœdd„Z	dd	œd
d„Z
edd�eeeef edœdd„ƒZdS )ÚPalettezA palette of available colors.)Úcolorsc                 C   s
   || _ d S ©N)Ú_colors)Úselfr   © r   ú9/tmp/pip-install-zsn1f9xv/pip/pip/_vendor/rich/palette.pyÚ__init__   s    zPalette.__init__)ÚnumberÚreturnc                 C   s   t | j| Ž S r   )r   r   )r   r   r   r   r   Ú__getitem__   s    zPalette.__getitem__r
   )r   c              
   C   s”   ddl m} ddlm} ddlm} ddlm} |dddd	t| j	ƒ› d
�ddd�}t
| j	ƒD ]2\}}| t|ƒt|ƒ|d||j|Ž d�d�¡ q\|S )Nr   ©ÚColor©ÚStyle)ÚTextr	   ÚindexZRGBr   r   z colorsTÚright)ÚtitleÚcaptionZ	highlightZcaption_justifyz                )Úbgcolor)Ústyle)Úpip._vendor.rich.colorr   Úpip._vendor.rich.styler   Zpip._vendor.rich.textr   Úpip._vendor.rich.tabler
   Úlenr   Ú	enumerateZadd_rowÚstrÚreprÚfrom_rgb)r   r   r   r   r
   Útabler   Úcolorr   r   r   Ú__rich__   s(    ù	ýzPalette.__rich__i   )Úmaxsize)r*   r   c                    sL   |\‰‰‰t ‰ | jj‰ttdœ‡ ‡‡‡‡fdd„}ttt| jƒƒ|d�}|S )zêFind a color from a palette that most closely matches a given color.

        Args:
            color (Tuple[int, int, int]): RGB components in range 0 > 255.

        Returns:
            int: Index of closes matching color.
        )r   r   c                    sj   ˆ| ƒ\}}}ˆ| d }ˆ| }ˆ| }ˆ| }ˆ d| | | d? d| |  d| | | d?  ƒS )zGet the distance to a color.é   i   é   é   iÿ  r   )r   Zred2Zgreen2Zblue2Zred_meanZredZgreenZblue©Ú_sqrtZblue1Z	get_colorZgreen1Zred1r   r   Úget_color_distance:   s    
ÿþÿz)Palette.match.<locals>.get_color_distance)Úkey)r   r   r   ÚintÚfloatÚminÚranger$   )r   r*   r2   Z	min_indexr   r0   r   Úmatch,   s    

zPalette.matchN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r4   r   r   r   r+   r   r8   r   r   r   r   r      s   r   Ú__main__N)ÚIterabler   )ÚConsoleÚConsoleOptions)ÚSegmentr   c                   @   s"   e Zd Zeeee dœdd„ZdS )ÚColorBox)ÚconsoleÚoptionsr   c                 c   sÌ   |j jd }td|ƒD ]°}t|jƒD ]–}||j }||d  }t ||d¡\}}	}
t ||d| d  d¡\}}}t |d |	d |
d ¡}t |d |d |d ¡}tdt	||d�ƒV  q$t 
¡ V  qd S )	Né   r   r   g      ð?r-   éÿ   u   â–„)r*   r   )ÚsizeÚheightr7   Ú	max_widthÚcolorsysZ
hls_to_rgbr   r(   rA   r   Úline)r   rC   rD   rH   ÚyÚxÚhÚlZr1Zg1Zb1Zr2Zg2Zb2r   r*   r   r   r   Ú__rich_console__T   s    
 zColorBox.__rich_console__N)r9   r:   r;   r?   r@   r>   rA   rP   r   r   r   r   rB   S   s    þrB   )Úmathr   Ú	functoolsr   Útypingr   r   r   Zcolor_tripletr   r#   r
   r   r9   rJ   r>   r!   r   Zpip._vendor.rich.consoler?   r@   Zpip._vendor.rich.segmentrA   r"   r   rB   rC   Úprintr   r   r   r   Ú<module>   s    @