2 ****************************************************************************
3 * Copyright 2018-2020,2021 Thomas E. Dickey *
4 * Copyright 2017 Free Software Foundation, Inc. *
6 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * copy of this software and associated documentation files (the *
8 * "Software"), to deal in the Software without restriction, including *
9 * without limitation the rights to use, copy, modify, merge, publish, *
10 * distribute, distribute with modifications, sublicense, and/or sell *
11 * copies of the Software, and to permit persons to whom the Software is *
12 * furnished to do so, subject to the following conditions: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 * Except as contained in this notice, the name(s) of the above copyright *
26 * holders shall not be used in advertising or otherwise to promote the *
27 * sale, use or other dealings in this Software without prior written *
29 ****************************************************************************
30 * Author: Thomas E. Dickey
31 * @Id: new_pair.3x,v 1.16 2021/06/17 21:26:02 tom Exp @
33 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
36 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
37 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
38 <TITLE>new_pair 3X</TITLE>
39 <link rel="author" href="mailto:bug-ncurses@gnu.org">
40 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
43 <H1 class="no-header">new_pair 3X</H1>
45 <B><A HREF="new_pair.3X.html">new_pair(3X)</A></B> <B><A HREF="new_pair.3X.html">new_pair(3X)</A></B>
50 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
51 <B>alloc_pair</B>, <B>find_pair</B>, <B>free_pair</B> - new curses color-pair functions
54 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
55 <B>#include</B> <B><curses.h></B>
57 <B>int</B> <B>alloc_pair(int</B> <I>fg</I><B>,</B> <B>int</B> <I>bg</I><B>);</B>
58 <B>int</B> <B>find_pair(int</B> <I>fg</I><B>,</B> <B>int</B> <I>bg</I><B>);</B>
59 <B>int</B> <B>free_pair(int</B> <I>pair</I><B>);</B>
62 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
63 These functions are an extension to the curses library. They permit an
64 application to dynamically allocate a color pair using the
65 foreground/background colors rather than assign a fixed color pair
66 number, and return an unused pair to the pool.
68 The number of colors may be related to the number of possible color
69 pairs for a given terminal, or it may not:
71 <B>o</B> While almost all terminals allow setting the color <I>attributes</I>
72 independently, it is unlikely that your terminal allows you to
73 modify the attributes of a given character cell without rewriting
74 it. That is, the foreground and background colors are applied as a
77 <B>o</B> Color pairs are the curses library's way of managing a color
78 palette on a terminal. If the library does not keep track of the
79 <I>combinations</I> of colors which are displayed, it will be inefficient.
81 <B>o</B> For simple terminal emulators with only a few dozen color
82 combinations, it is convenient to use the maximum number of
83 combinations as the limit on color pairs:
85 <B>COLORS</B> <I>*</I> <B>COLORS</B>
87 <B>o</B> Terminals which support <I>default</I> <I>colors</I> distinct from "ANSI colors"
88 add to the possible combinations, producing this total:
90 <I>(</I> <B>COLORS</B> <I>+</I> <I>1</I> <I>)</I> <I>*</I> <I>(</I> <B>COLORS</B> <I>+</I> <I>1</I> <I>)</I>
92 <B>o</B> An application might use up to a few dozen color pairs to implement
93 a predefined color scheme.
95 Beyond that lies in the realm of programs using the foreground and
96 background colors for "ASCII art" (or some other non-textual
99 Also beyond those few dozen pairs, the required size for a table to
100 represent the combinations grows rapidly with an increasing number
103 These functions allow a developer to let the screen library manage
107 </PRE><H3><a name="h3-alloc_pair">alloc_pair</a></H3><PRE>
108 The <B>alloc_pair</B> function accepts parameters for foreground and
109 background color, and checks if that color combination is already
110 associated with a color pair.
112 <B>o</B> If the combination already exists, <B>alloc_pair</B> returns the existing
115 <B>o</B> If the combination does not exist, <B>alloc_pair</B> allocates a new color
116 pair and returns that.
118 <B>o</B> If the table fills up, <B>alloc_pair</B> discards the least-recently
119 allocated entry using <B>free_pair</B> and allocates a new color pair.
121 All of the color pairs are allocated from a table of possible color
122 pairs. The size of the table is determined by the terminfo <I>pairs</I>
123 capability. The table is shared with <B>init_pair</B>; in fact <B>alloc_pair</B>
124 calls <B>init_pair</B> after updating the ncurses library's fast index to the
125 colors versus color pairs.
128 </PRE><H3><a name="h3-find_pair">find_pair</a></H3><PRE>
129 The <B>find_pair</B> function accepts parameters for foreground and background
130 color, and checks if that color combination is already associated with
131 a color pair, returning the pair number if it has been allocated.
132 Otherwise it returns -1.
135 </PRE><H3><a name="h3-free_pair">free_pair</a></H3><PRE>
136 Marks the given color pair as unused, i.e., like color pair 0.
139 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
140 The <B>alloc_pair</B> function returns a color pair number in the range 1
141 through <B>COLOR_PAIRS</B>-1, unless it encounters an error updating its fast
142 index to the color pair values, preventing it from allocating a color
143 pair. In that case, it returns -1.
145 The <B>find_pair</B> function returns a color pair number if the given color
146 combination has been associated with a color pair, or -1 if not.
148 Likewise, <B>free_pair</B> returns <B>OK</B> unless it encounters an error updating
149 the fast index or if no such color pair is in use.
152 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
153 These routines are specific to ncurses. They were not supported on
154 Version 7, BSD or System V implementations. It is recommended that any
155 code depending on them be conditioned using NCURSES_VERSION.
158 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
159 <B><A HREF="curs_color.3X.html">curs_color(3X)</A></B>.
162 </PRE><H2><a name="h2-AUTHOR">AUTHOR</a></H2><PRE>
167 <B><A HREF="new_pair.3X.html">new_pair(3X)</A></B>
171 <li><a href="#h2-NAME">NAME</a></li>
172 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
173 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
175 <li><a href="#h3-alloc_pair">alloc_pair</a></li>
176 <li><a href="#h3-find_pair">find_pair</a></li>
177 <li><a href="#h3-free_pair">free_pair</a></li>
180 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
181 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
182 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
183 <li><a href="#h2-AUTHOR">AUTHOR</a></li>