def _get_closest_ansi_color(r, g, b, exclude=()):
 assert isinstance(exclude, tuple)
 saturation = ((abs((r - g)) + abs((g - b))) + abs((b - r)))
 if (saturation > 30):
  exclude += (u'ansilightgray', u'ansidarkgray', u'ansiwhite', u'ansiblack')
 distance = ((257 * 257) * 3)
 match = u'ansidefault'
 for (name, (r2, g2, b2)) in ANSI_COLORS_TO_RGB.items():
  if ((name != u'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

def _get_closest_ansi_color ( r , g , b , exclude = ( ) ) : assert isinstance ( exclude , tuple ) saturation = ( ( abs ( ( r - g ) ) + abs ( ( g - b ) ) ) + abs ( ( b - r ) ) ) if ( saturation > 30 ) : exclude += ( u'ansilightgray' , u'ansidarkgray' , u'ansiwhite' , u'ansiblack' ) distance = ( ( 257 * 257 ) * 3 ) match = u'ansidefault' for ( name , ( r2 , g2 , b2 ) ) in ANSI_COLORS_TO_RGB . items ( ) : if ( ( name != u'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
find closest ansi color .