code: def _get_closest_ansi_color(r, g, b, exclude=()):
      
      assert isinstance(exclude, tuple)
  
      # When we have a bit of saturation, avoid the gray-like colors, otherwise,
      # too often the distance to the gray color is less.
      saturation = abs(r - g) + abs(g - b) + abs(b - r)  # Between 0..510
  
      if saturation > 30:
          exclude += ('ansilightgray', 'ansidarkgray', 'ansiwhite', 'ansiblack')
  
      # Take the closest color.
      # (Thanks to Pygments for this part.)
      distance = 257*257*3  # "infinity" (>distance from #000000 to #ffffff)
      match = 'ansidefault'
  
      for name, (r2, g2, b2) in ANSI_COLORS_TO_RGB.items():
          if name != 'ansidefault' and name not in exclude:
              d = (r - r2) ** 2 + (g - g2) ** 2 + (b - b2) ** 2
  
              if d < distance:
                  match = name
                  distance = d
  
      return match
docs: Find closest ANSI color. Return it by name.
  
      :param r: Red (Between 0 and 255.)
      :param g: Green (Between 0 and 255.)
      :param b: Blue (Between 0 and 255.)
      :param exclude: A tuple of color names to exclude. (E.g. ``('ansired', )``.)