1 .\"***************************************************************************
2 .\" Copyright (c) 2017 Free Software Foundation, Inc. *
4 .\" Permission is hereby granted, free of charge, to any person obtaining a *
5 .\" copy of this software and associated documentation files (the *
6 .\" "Software"), to deal in the Software without restriction, including *
7 .\" without limitation the rights to use, copy, modify, merge, publish, *
8 .\" distribute, distribute with modifications, sublicense, and/or sell *
9 .\" copies of the Software, and to permit persons to whom the Software is *
10 .\" furnished to do so, subject to the following conditions: *
12 .\" The above copyright notice and this permission notice shall be included *
13 .\" in all copies or substantial portions of the Software. *
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 .\" Except as contained in this notice, the name(s) of the above copyright *
24 .\" holders shall not be used in advertising or otherwise to promote the *
25 .\" sale, use or other dealings in this Software without prior written *
27 .\"***************************************************************************
29 .\" Author: Thomas E. Dickey
31 .\" $Id: new_pair.3x,v 1.9 2017/03/13 21:21:34 tom Exp $
56 \fBfree_pair\fP \- new curses color-pair functions
58 \fB#include <curses.h>\fP
60 \fBint alloc_pair(int fg, int bg);\fP
62 \fBint find_pair(int fg, int bg);\fP
64 \fBint free_pair(int pair);\fP
66 These functions are an extension to the curses library.
67 They permit an application to dynamically allocate a color pair using
68 the foreground/background colors rather than assign a fixed color pair number,
69 and return an unused pair to the pool.
71 The number of colors may be related to the number of possible color
72 pairs for a given terminal, or it may not:
74 While almost all terminals allow setting the color \fIattributes\fP
76 it is unlikely that your terminal allows you to modify the attributes
77 of a given character cell without rewriting it.
78 That is, the foreground and background colors are applied as a pair.
80 Color pairs are the curses library's way of managing a color palette
82 If the library does not keep track of the \fIcombinations\fP of
83 colors which are displayed, it will be inefficient.
85 For simple terminal emulators
86 with only a few dozen color combinations,
87 it is convenient to use the maximum number of combinations
88 as the limit on color pairs:
90 \fBCOLORS\fP\fI * \fP\fBCOLORS\fP
93 Terminals which support \fIdefault colors\fP distinct from \*(``ANSI colors\*(''
94 add to the possible combinations, producing this total:
96 \fI( \fP\fBCOLORS\fP\fI + 1 ) * ( \fP\fBCOLORS\fP\fI + 1 )\fP
99 An application might use up to a few dozen color pairs to
100 implement a predefined color scheme.
102 Beyond that lies in the realm of programs using the foreground
103 and background colors for \*(``ASCII art\*(''
104 (or some other non-textual application).
106 Also beyond those few dozen pairs, the required size for a table
107 to represent the combinations grows rapidly with an increasing number of colors.
109 These functions allow a developer to let the screen library
112 The \fBalloc_pair\fP function accepts parameters for
113 foreground and background color, and
114 checks if that color combination is already associated with a color pair.
116 If the combination already exists, \fBalloc_pair\fP returns the existing pair.
118 If the combination does not exist, \fBalloc_pair\fP allocates a new color pair and returns that.
120 If the table fills up, \fBalloc_pair\fP discards the least-recently
121 allocated entry using \fBfree_pair\fP and allocates a new color pair.
123 All of the color pairs are allocated from a table of possible color pairs.
124 The size of the table is determined by the terminfo \fIpairs\fP capability.
125 The table is shared with \fBinit_pair\fP;
126 in fact \fBalloc_pair\fP calls \fBinit_pair\fP after
127 updating the ncurses library's fast index to the colors versus color pairs.
129 The \fBfind_pair\fP function accepts parameters for
130 foreground and background color, and
131 checks if that color combination is already associated with a color pair,
132 returning the pair number if it has been allocated.
133 Otherwise it returns \-1.
135 Marks the given color pair as unused,
136 i.e., like color pair 0.
139 The \fBalloc_pair\fP function returns a color pair number in the range
140 1 through \fBCOLOR_PAIRS\fP\-1, unless it encounters an error updating
141 its fast index to the color pair values, preventing it from allocating
142 a color pair. In that case, it returns \-1.
144 The \fBfind_pair\fP function returns a color pair number if the
145 given color combination has been associated with a color pair,
148 Likewise, \fBfree_pair\fP returns \fBOK\fP unless it encounters an
149 error updating the fast index or if no such color pair is in use.
151 These routines are specific to ncurses. They were not supported on
152 Version 7, BSD or System V implementations. It is recommended that
153 any code depending on them be conditioned using NCURSES_VERSION.