"Te ddlmZddlmZddlmZmZmZddlm Z erddl m Z GddZ e d k(rLdd lZdd lmZdd lmZdd lmZmZddlmZddlmZGddZeZej7ey y ))sqrt) lru_cache)SequenceTuple TYPE_CHECKING) ColorTripletTableczeZdZdZdeeeeeffdZdedefdZ d dZ e d d eeeefdefd Z y )PalettezA palette of available colors.colorsc||_yN)_colors)selfrs ./usr/lib/python3/dist-packages/rich/palette.py__init__zPalette.__init__s  numberreturnc,t|j|Sr)r r)rrs r __getitem__zPalette.__getitem__sT\\&122rc <ddlm}ddlm}ddlm}ddlm}|dddd t|jd d d }t|jD]F\}}|jt|t||d||j|H|S)NrColorStyle)Textr indexRGBrr z colorsTright)titlecaption highlightcaption_justifyz )bgcolor)style) rich.colorr rich.styler rich.textr rich.tabler lenr enumerateadd_rowstrreprfrom_rgb)rrrrr tabler colors r__rich__zPalette.__rich__s$$"$   4<<()1# &dll3 LE5 MME U XU>5>>53I%JK    ri)maxsizer4c|\t|jjdtdtffd }t t t|j|}|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. r rc |\}}} |zdz} |z } |z } |z }d|z|z|zdz d|z|zzd|z |z|zdz zS)zGet the distance to a color.ii) r red2green2blue2red_meanredgreenblue_sqrtblue1 get_colorgreen1red1s rget_color_distancez)Palette.match..get_color_distance:s"+E"2 D&%t )H+CVOE5=D>S(3.14e)e#$8^t+d2q8: r)key)rrrintfloatminranger-) rr4rI min_indexrDrErFrGrHs @@@@@rmatchz Palette.match,s`$feLL,,  c e  c$,,/06HI rN)rr ) __name__ __module__ __qualname____doc__rrrKrr rr5rrPr<rrr r sk(xc3m(<=3#3,30t5c3/Crr __main__N)Iterabler)ConsoleConsoleOptions)Segmentrc&eZdZdededeefdZy)ColorBoxconsoleoptionsrc #K|jjdz }td|D]}t|jD]}||jz }||dzz }t j ||d\}} } t j ||d|z dz zd\} } } t j|dz| dz| dz}t j| dz| dz| dz}tdt||tjyw) Nrrg?r9u▄)r4r') sizeheightrN max_widthcolorsys hls_to_rgbrr2rYrline)rr\r]rbyxhlr1g1b1r2g2b2r'r4s r__rich_console__zColorBox.__rich_console__Ts \\((1,F1f% %w001NAG---AVaZ(A!)!4!4Q3!?JBB!)!4!4QQZ!^8Lc!RJBB#nnR#XrCxcJG!NN28R#XrCxHE!%UG)LMMNlln$ %sD D N)rQrRrSrWrXrVrYrqr<rrr[r[Ss$ %" %-; % g  %rr[)mathr functoolsrtypingrrr color_tripletr r,r r rQrdrVr)r rich.consolerWrX rich.segmentrYr*rr[r\printr<rrrysg11' ==@ z 4$ %% iG MM(*3r