def ansi(self, rgb):
        """

        :param rgb:
        :return:
        """
        r, g, b = rgb

        if self.mode in (8, 16):
            colors = COLOR_ANSI[: self.mode]
            matches = [
                (self._distance(c, map(int, rgb)), i) for i, c in enumerate(colors)
            ]
            matches.sort()
            color = matches[0][1]

            return "3%d" % (color,)
        else:
            gray_possible = True
            sep = 2.5

            while gray_possible:
                if r < sep or g < sep or b < sep:
                    gray = r < sep and g < sep and b < sep
                    gray_possible = False

                sep += 42.5

            if gray:
                color = 232 + int(float(sum(rgb) / 33.0))
            else:
                color = sum(
                    [16]
                    + [
                        int(6 * float(val) / 256) * mod
                        for val, mod in zip(rgb, [36, 6, 1])
                    ]
                )

            return "38;5;%d" % (color,)
def ansi ( self , rgb ) : r , g , b = rgb if self . mode in ( 8 , 16 ) : colors = COLOR_ANSI [ : self . mode ] matches = [ ( self . _distance ( c , map ( int , rgb ) ) , i ) for i , c in enumerate ( colors ) ] matches . sort ( ) color = matches [ 0 ] [ 1 ] return "3%d" % ( color , ) else : gray_possible = True sep = 2.5 while gray_possible : if r < sep or g < sep or b < sep : gray = r < sep and g < sep and b < sep gray_possible = False sep += 42.5 if gray : color = 232 + int ( float ( sum ( rgb ) / 33.0 ) ) else : color = sum ( [ 16 ] + [ int ( 6 * float ( val ) / 256 ) * mod for val , mod in zip ( rgb , [ 36 , 6 , 1 ] ) ] ) return "38;5;%d" % ( color , )
:param rgb:
        :return: