Beispiel #1
0
def get(fg, bg="black"):
    global PAIR_INDEX

    fg_rgb = coerce_to_rgb(fg) # allow RGB or name
    bg_rgb = coerce_to_rgb(bg) # coerce to RGB

    key = (fg_rgb, bg_rgb)

    if key in FG_BG_TO_PAIR_INDEX:
        return FG_BG_TO_PAIR_INDEX[key]
    else:
        # create new color pair
        fg_i = iterm_color_table.lookup(fg_rgb)
        bg_i = iterm_color_table.lookup(bg_rgb)

        curses.init_pair(PAIR_INDEX, fg_i, bg_i)
        out = curses.color_pair(PAIR_INDEX)
        FG_BG_TO_PAIR_INDEX[key] = out
        PAIR_INDEX_TO_FG_BG[out] = key
        PAIR_INDEX += 1
        return out
Beispiel #2
0
def scale_index(index, factor):
    return iterm_color_table.lookup(scale_rgb(iterm_color_table.reverse_lookup(index), factor))