class_docstr: Cache which maps (r, g, b) tuples to 16 ansi colors.
  
  :param bg: Cache for background colors, instead of foreground.
class_docstr_tok: ["Cache","which","maps","(","r",",","g",",","b",")","tuples","to","16","ansi","colors",".",":","param","bg",":","Cache","for","background","colors",",","instead","of","foreground","."]
code: def __init__(self, bg: bool = False) -> None:
      self.bg = bg
      self._cache: dict[Hashable, _ColorCodeAndName] = {}
  
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 1 to create a new _16ColorCache object  with example: obj = _16ColorCache(bg)