Find the closest xterm-256 approximation to the given RGB value.
    @param r,g,b: each is a number between 0-255 for the Red, Green, and Blue values
    @returns: integer between 0 and 255, compatible with xterm.
    >>> rgb2short(18, 52, 86)
    23
    >>> rgb2short(255, 255, 255)
    231
    >>> rgb2short(13, 173, 214) # vimeo logo
    38

def rgb2short(r, g, b):
    """ Find the closest xterm-256 approximation to the given RGB value.
    @param r,g,b: each is a number between 0-255 for the Red, Green, and Blue values
    @returns: integer between 0 and 255, compatible with xterm.
    >>> rgb2short(18, 52, 86)
    23
    >>> rgb2short(255, 255, 255)
    231
    >>> rgb2short(13, 173, 214) # vimeo logo
    38
    """
    incs = (0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff)
    # Break 6-char RGB code into 3 integer vals.
    parts = [ r, g, b] 
    res = []
    for part in parts:
        i = 0
        while i < len(incs)-1:
            s, b = incs[i], incs[i+1]  # smaller, bigger
            if s <= part <= b:
                s1 = abs(s - part)
                b1 = abs(b - part)
                if s1 < b1: closest = s
                else: closest = b
                res.append(closest)
                break
            i += 1
    #print '***', res
    return RGB2SHORT_DICT[tuple(res)]