class_docstr: Cache for VT100 escape codes. It maps
  (fgcolor, bgcolor, bold, underline, strike, reverse) tuples to VT100
  escape sequences.
  
  :param true_color: When True, use 24bit colors instead of 256 colors.
class_docstr_tok: ["Cache","for","VT100","escape","codes",".","It","maps","(","fgcolor",",","bgcolor",",","bold",",","underline",",","strike",",","reverse",")","tuples","to","VT100","escape","sequences",".",":","param","true_color",":","When","True",",","use","24bit","colors","instead","of","256","colors","."]
docstr: Return a tuple with the vt100 values  that represent this color.
docstr_tok: ["Return","a","tuple","with","the","vt100","values","that","represent","this","color","."]
code: def _colors_to_code(
      self, fg_color: str, bg_color: str
  ) -> Iterable[str]:
      """
      Return a tuple with the vt100 values  that represent this color.
      """
      # When requesting ANSI colors only, and both fg/bg color were converted
      # to ANSI, ensure that the foreground and background color are not the
      # same. (Unless they were explicitly defined to be the same color.)
      fg_ansi = ""
  
      def get(color: str, bg: bool) -> list[int]:
          nonlocal fg_ansi
  
          table = BG_ANSI_COLORS if bg else FG_ANSI_COLORS
  
          if not color or self.color_depth == ColorDepth.DEPTH_1_BIT:
              return []
  
          # 16 ANSI colors. (Given by name.)
          elif color in table:
              return [table[color]]
  
          # RGB colors. (Defined as 'ffffff'.)
          else:
              try:
                  rgb = self._color_name_to_rgb(color)
              except ValueError:
                  return []
  
              # When only 16 colors are supported, use that.
              if self.color_depth == ColorDepth.DEPTH_4_BIT:
                  if bg:  # Background.
                      if fg_color != bg_color:
                          exclude = [fg_ansi]
                      else:
                          exclude = []
                      code, name = _16_bg_colors.get_code(
                          rgb, exclude=exclude
                      )
                      return [code]
                  else:  # Foreground.
                      code, name = _16_fg_colors.get_code(rgb)
                      fg_ansi = name
                      return [code]
  
              # True colors. (Only when this feature is enabled.)
              elif self.color_depth == ColorDepth.DEPTH_24_BIT:
                  r, g, b = rgb
                  return [(48 if bg else 38), 2, r, g, b]
  
              # 256 RGB colors.
              else:
                  return [(48 if bg else 38), 5, _256_colors[rgb]]
  
      result: list[int] = []
      result.extend(get(fg_color, False))
      result.extend(get(bg_color, True))
  
      return map(str, result)
  
imports: from __future__ import annotations
  import io
  import os
  import sys
  from typing import Callable, Dict, Hashable, Iterable, Sequence, TextIO, Tuple
  from prompt_toolkit.cursor_shapes import CursorShape
  from prompt_toolkit.data_structures import Size
  from prompt_toolkit.output import Output
  from prompt_toolkit.styles import ANSI_COLOR_NAMES, Attrs
  from prompt_toolkit.utils import is_dumb_terminal
  from .color_depth import ColorDepth
  from .flush_stdout import flush_stdout
label_desc: Use image node_id 4 for calling the _EscapeCodeCache obj's underlying member method code with example usage: obj._colors_to_code(fg_color, bg_color) and returns: map, list, list, list, list, list, list, list