o 7]hD @sddlmZddlmZddlmZmZmZddlm Z er$ddl m Z GdddZ e d kredd lZdd lmZdd lmZdd lmZmZddlmZddlmZGdddZeZeed Sd S))sqrt) lru_cache)SequenceTuple TYPE_CHECKING) ColorTripletTablec@sneZdZdZdeeeeeffddZdedefddZ dd d Z e d d deeeefdefddZ dS)PalettezA palette of available colors.colorscCs ||_dSN)_colors)selfr r:/usr/lib/python3/dist-packages/pip/_vendor/rich/palette.py__init__s zPalette.__init__numberreturncCst|j|Sr )rr)rrrrr __getitem__szPalette.__getitem__r c Csddlm}ddlm}ddlm}ddlm}|dddd t|j d d d d }t |j D]\}}| t |t ||d||j|ddq.|S)NrColorStyle)Textr indexRGBrr z colorsTright)titlecaption highlightcaption_justifyz )bgcolor)style)pip._vendor.rich.colorrpip._vendor.rich.stylerpip._vendor.rich.textrpip._vendor.rich.tabler lenr enumerateadd_rowstrreprfrom_rgb)rrrrr tablercolorrrr__rich__s(     zPalette.__rich__i)maxsizer/csN|\t|jjdtdtffdd }ttt|j|d}|S)zFind 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. rrcsj|\}}}|d}|}|}|}d|||d?d||d|||d?S)zGet the distance to a color.iir)rred2green2blue2red_meanredgreenblue_sqrtblue1 get_colorgreen1red1rrget_color_distance:s  z)Palette.match..get_color_distance)key)rrrintfloatminranger()rr/rB min_indexrr<rmatch,s  z Palette.matchN)rr ) __name__ __module__ __qualname____doc__rrrDrrrr0rrIrrrrr s "r __main__N)Iterabler)ConsoleConsoleOptions)Segmentrc@s&eZdZdededeefddZdS)ColorBoxconsoleoptionsrccs|jjd}td|D]X}t|jD]K}||j}||d}t||d\}} } t||d|dd\} } } t|d| d| d}t| d| d| d}tdt ||dVqt Vq dS) Nrrg?r2u▄)r/r") sizeheightrG max_widthcolorsys hls_to_rgbrr-rRrline)rrTrUrYyxhlr1g1b1r2g2b2r"r/rrr__rich_console__Ts     zColorBox.__rich_console__N)rJrKrLrPrQrOrRrhrrrrrSSsrS)mathr functoolsrtypingrrr color_tripletrr'r r rJr[rOr$rpip._vendor.rich.consolerPrQpip._vendor.rich.segmentrRr%rrSrTprintrrrrs$   @