| Main index | Section 3 | Options |
#include <curses.h>int alloc_pair(int fg, int bg); int find_pair(int fg, int bg); int free_pair(int pair);
The number of colors may be related to the number of possible color pairs for a given terminal, or it may not:
| &#187; | While almost all terminals allow setting the color attributes independently, it is unlikely that your terminal allows you to modify the attributes of a given character cell without rewriting it. That is, the foreground and background colors are applied as a pair. |
| &#187; | Color pairs are the curses library's way of managing a color palette on a terminal. If the library does not keep track of the combinations of colors which are displayed, it will be inefficient. |
| » |
For simple terminal emulators
with only a few dozen color combinations,
it is convenient to use the maximum number of combinations
as the limit on color pairs:
| ||
| » |
Terminals which support default colors distinct
from ANSI colors
add to the possible combinations, producing this total:
| ||
| &#187; | An application might use up to a few dozen color pairs to implement a predefined color scheme. |
| Beyond that lies in the realm of programs using the foreground and background colors for ASCII art (or some other non-textual application). | |
| Also beyond those few dozen pairs, the required size for a table to represent the combinations grows rapidly with an increasing number of colors. | |
| These functions allow a developer to let the screen library manage color pairs. | |
| &#187; | If the combination already exists, alloc_pair returns the existing pair. |
| &#187; | If the combination does not exist, alloc_pair allocates a new color pair and returns that. |
| &#187; | If the table fills up, alloc_pair discards the least-recently allocated entry using free_pair and allocates a new color pair. |
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.
| 2024-03-16 | new_pair (3X) | ncurses 6.5 |
| Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | Computer science would have progressed much further and faster if all of the time and effort that has been spent maintaining and nurturing Unix had been spent on a sounder operating system. | ” |
| — The Unix Haters' handbook | ||