new_pair(3NCURSES) | new_pair(3NCURSES) |
alloc_pair, find_pair, free_pair - new curses color-pair functions
#include <curses.h>
int alloc_pair(int fg, int bg);
int find_pair(int fg, int bg);
int free_pair(int pair);
These functions are an extension to the curses library. They permit an application to dynamically allocate a color pair using the foreground/background colors rather than assign a fixed color pair number, and return an unused pair to the pool.
The number of colors may be related to the number of possible color pairs for a given terminal, or it may not:
COLORS * COLORS
( COLORS + 1 ) * ( COLORS + 1 )
The alloc_pair function accepts parameters for foreground and background color, and checks if that color combination is already associated with a color pair.
All of the color pairs are allocated from a table of possible color pairs. The size of the table is determined by the terminfo pairs capability. The table is shared with init_pair; in fact alloc_pair calls init_pair after updating the ncurses library's fast index to the colors versus color pairs.
The find_pair function accepts parameters for foreground and background color, and checks if that color combination is already associated with a color pair, returning the pair number if it has been allocated. Otherwise it returns -1.
Marks the given color pair as unused, i.e., like color pair 0.
The alloc_pair function returns a color pair number in the range 1 through COLOR_PAIRS-1, unless it encounters an error updating its fast index to the color pair values, preventing it from allocating a color pair. In that case, it returns -1.
The find_pair function returns a color pair number if the given color combination has been associated with a color pair, or -1 if not.
Likewise, free_pair returns OK unless it encounters an error updating the fast index or if no such color pair is in use.
These routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations. It is recommended that any code depending on them be conditioned using NCURSES_VERSION.
Thomas Dickey.