def palette(fg, bg=-1):
    if not hasattr(palette, "counter"):
        palette.counter = 1
    if not hasattr(palette, "selections"):
        palette.selections = {}
    selection = "%s%s" % (str(fg), str(bg))
    if not selection in palette.selections:
        palette.selections[selection] = palette.counter
        palette.counter += 1
    colors = [c for c in dir(_curses) if c.startswith('COLOR')]
    if isinstance(fg, str):
        if not "COLOR_"+fg.upper() in colors:
            fg = -1
        else:
            fg = getattr(_curses, "COLOR_"+fg.upper())
    if isinstance(bg, str):
        if not "COLOR_"+bg.upper() in colors:
            bg = -1
        else:
            bg = getattr(_curses, "COLOR_"+bg.upper())
    _curses.init_pair(palette.selections[selection], fg, bg)
    return _curses.color_pair(palette.selections[selection])