The ncurses extended-color extension provides dynamic color-pair management that the standard :mod:curses functions cannot express, and which is currently not wrapped.
alloc_pair(fg, bg) allocates a color pair for the given foreground and background colors and returns its number, reusing an existing pair if the same combination was already allocated. init_pair(pair, fg, bg) instead requires the caller to choose the pair number, with no way to let curses pick a free one.
find_pair(fg, bg) returns the number of an already-allocated pair for the given colors, or -1 if none has been allocated. There is no standard reverse lookup (the inverse of pair_content).
free_pair(pair) releases a pair previously allocated by alloc_pair(); there is no standard equivalent.
reset_color_pairs() discards all color-pair definitions at once; there is no standard bulk reset.
I propose to expose these four functions, available when CPython is built against a wide-character ncurses with extended-color support (the same condition as curses.has_extended_color_support()). The already-wrapped init_color/init_pair/color_content/pair_content already route to the *_extended_* variants internally, so those four extended functions do not need separate names; only the dynamic pair-management functions above add new capability.
Linked PRs
The ncurses extended-color extension provides dynamic color-pair management that the standard :mod:
cursesfunctions cannot express, and which is currently not wrapped.alloc_pair(fg, bg)allocates a color pair for the given foreground and background colors and returns its number, reusing an existing pair if the same combination was already allocated.init_pair(pair, fg, bg)instead requires the caller to choose the pair number, with no way to let curses pick a free one.find_pair(fg, bg)returns the number of an already-allocated pair for the given colors, or -1 if none has been allocated. There is no standard reverse lookup (the inverse ofpair_content).free_pair(pair)releases a pair previously allocated byalloc_pair(); there is no standard equivalent.reset_color_pairs()discards all color-pair definitions at once; there is no standard bulk reset.I propose to expose these four functions, available when CPython is built against a wide-character ncurses with extended-color support (the same condition as
curses.has_extended_color_support()). The already-wrappedinit_color/init_pair/color_content/pair_contentalready route to the*_extended_*variants internally, so those four extended functions do not need separate names; only the dynamic pair-management functions above add new capability.Linked PRs