관리-도구
편집 파일: palette.cpython-38.pyc
U &?�fD � @ 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 �F/opt/hc_python/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 �index�RGBr r z colorsT�right)�title�caption� highlight�caption_justifyz )�bgcolor)�style)�pip._vendor.rich.colorr �pip._vendor.rich.styler �pip._vendor.rich.textr �pip._vendor.rich.tabler �lenr � enumerate�add_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 �red2�green2�blue2�red_mean�red�green�blue��_sqrt�blue1� get_color�green1�red1r r �get_color_distance: s ���z)Palette.match.<locals>.get_color_distance)�key)r r r �int�float�min�ranger( )r r/ rB � min_indexr r<