class_docstr: Format tokens with ANSI color sequences, for output in a 256-color
  terminal or console.  Like in `TerminalFormatter` color sequences
  are terminated at newlines, so that paging the output works correctly.
  
  The formatter takes colors from a style defined by the `style` option
  and converts them to nearest ANSI 256-color escape sequences. Bold and
  underline attributes from the style are preserved (and displayed).
  
  .. versionadded:: 0.9
  
  .. versionchanged:: 2.2
     If the used style defines foreground colors in the form ``#ansi*``, then
     `Terminal256Formatter` will map these to non extended foreground color.
     See :ref:`AnsiTerminalStyle` for more information.
  
  Options accepted:
  
  `style`
      The style to use, can be a string or a Style subclass (default:
      ``'default'``).
class_docstr_tok: ["Format","tokens","with","ANSI","color","sequences",",","for","output","in","a","256-color","terminal","or","console",".","Like","in","`","TerminalFormatter","`","color","sequences","are","terminated","at","newlines",",","so","that","paging","the","output","works","correctly",".","The","formatter","takes","colors","from","a","style","defined","by","the","`","style","`","option","and","converts","them","to","nearest","ANSI","256-color","escape","sequences",".","Bold","and","underline","attributes","from","the","style","are","preserved","(","and","displayed",")",".","..","versionadded",":",":","0.9","..","versionchanged",":",":","2.2","If","the","used","style","defines","foreground","colors","in","the","form","``","#","ansi","*","``",",","then","`","Terminal256Formatter","`","will","map","these","to","non","extended","foreground","color",".","See",":","ref",":","`","AnsiTerminalStyle","`","for","more","information",".","Options","accepted",":","`","style","`","The","style","to","use",",","can","be","a","string","or","a","Style","subclass","(","default",":","``","'default","'","``",")","."]
code: def _color_index(self, color):
      index = self.best_match.get(color, None)
      if color in ansicolors:
          # strip the `#ansi` part and look up code
          index = color
          self.best_match[color] = index
      if index is None:
          try:
              rgb = int(str(color), 16)
          except ValueError:
              rgb = 0
  
          r = (rgb >> 16) & 0xFF
          g = (rgb >> 8) & 0xFF
          b = rgb & 0xFF
          index = self._closest_color(r, g, b)
          self.best_match[color] = index
      return index
  
imports: import sys
  from pygments.formatter import Formatter
  from pygments.console import codes
  from pygments.style import ansicolors
label_desc: Use image node_id 4 for calling the Terminal256Formatter obj's underlying member method code with example usage: obj._color_index(color) and returns: index