def _color_to_code(self, color, bg=False):
        " Return a tuple with the vt100 values  that represent this color. "
        table = BG_ANSI_COLORS if bg else FG_ANSI_COLORS

        # 16 ANSI colors. (Given by name.)
        if color in table:
            result = (table[color], )

        # RGB colors. (Defined as 'ffffff'.)
        else:
            try:
                rgb = self._color_name_to_rgb(color)
            except __HOLE__:
                return ()

            # When only 16 colors are supported, use that.
            if self._supports_only_16_colors():
                if bg:
                    result = (_16_bg_colors[rgb], )
                else:
                    result = (_16_fg_colors[rgb], )

            # True colors. (Only when this feature is enabled.)
            elif self.true_color:
                r, g, b = rgb
                result = (48 if bg else 38, 2, r, g, b)

            # 256 RGB colors.
            else:
                result = (48 if bg else 38, 5, _256_colors[rgb])

        return map(six.text_type, result)
dataset/ETHPy150Open jonathanslenders/python-prompt-toolkit/prompt_toolkit/terminal/vt100_output.py/_EscapeCodeCache._color_to_code