Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python38
/
lib
/
python3.8
/
site-packages
/
pip
/
_vendor
/
rich
/
__pycache__
/
File Content:
palette.cpython-38.pyc
U �ReD � @ s� d dl mZ d dlmZ d dlmZmZmZ ddlm Z erHd dl mZ G dd� d�Ze d kr�d d lZd dlmZ d dlmZ d d lmZmZ d dlmZ d dlmZ G dd� d�Ze� Ze�e� � d S )� )�sqrt)� lru_cache)�Sequence�Tuple� TYPE_CHECKING� )�ColorTriplet��Tablec @ sn e Zd ZdZeeeeef d�dd�Zeed�dd�Z dd �d d�Z edd �eeeef ed�dd��ZdS )�PalettezA palette of available colors.)�colorsc C s || _ d S �N)�_colors)�selfr � r �I/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/rich/palette.py�__init__ s zPalette.__init__)�number�returnc C s t | j| � S r )r r )r r r r r �__getitem__ s zPalette.__getitem__r )r c C s� ddl m} ddlm} ddlm} ddlm} |dddd t| j �� d �ddd �}t | j �D ]2\}}|�t|�t |�|d||j|� d�d�� q\|S )Nr ��Color��Style)�Textr �indexZRGBr r z colorsT�right)�titleZcaptionZ highlightZcaption_justifyz )�bgcolor)Zstyle)�pip._vendor.rich.colorr �pip._vendor.rich.styler Zpip._vendor.rich.textr �pip._vendor.rich.tabler �lenr � enumerateZadd_row�str�repr�from_rgb)r r r r r �tabler �colorr r r �__rich__ s( � �zPalette.__rich__i )�maxsize)r( r c sL |\���t � | jj�ttd�� ����fdd�}ttt| 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 )zGet the distance to a color.� i � � i� r )r Zred2Zgreen2Zblue2Zred_meanZredZgreenZblue�Z_sqrtZblue1Z get_colorZgreen1Zred1r r �get_color_distance: s ���z)Palette.match.<locals>.get_color_distance)�key)r r r �int�float�min�ranger"