2 ****************************************************************************
3 * Copyright (c) 2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************
29 * Author: Thomas E. Dickey
30 * @Id: new_pair.3x,v 1.10 2017/11/18 23:48:44 tom Exp @
32 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
35 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
36 <meta name="generator" content="Manpage converted by man2html - see http://invisible-island.net/scripts/readme.html#others_scripts">
37 <TITLE>new_pair 3x</TITLE>
38 <link rev=made href="mailto:bug-ncurses@gnu.org">
39 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
42 <H1 class="no-header">new_pair 3x</H1>
44 <STRONG><A HREF="new_pair.3x.html">new_pair(3x)</A></STRONG> <STRONG><A HREF="new_pair.3x.html">new_pair(3x)</A></STRONG>
49 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
50 <STRONG>alloc_pair</STRONG>, <STRONG>find_pair</STRONG>, <STRONG>free_pair</STRONG> - new curses color-pair functions
53 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
54 <STRONG>#include</STRONG> <STRONG><curses.h></STRONG>
56 <STRONG>int</STRONG> <STRONG>alloc_pair(int</STRONG> <STRONG>fg,</STRONG> <STRONG>int</STRONG> <STRONG>bg);</STRONG>
57 <STRONG>int</STRONG> <STRONG>find_pair(int</STRONG> <STRONG>fg,</STRONG> <STRONG>int</STRONG> <STRONG>bg);</STRONG>
58 <STRONG>int</STRONG> <STRONG>free_pair(int</STRONG> <STRONG>pair);</STRONG>
61 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
62 These functions are an extension to the curses library. They permit an
63 application to dynamically allocate a color pair using the fore-
64 ground/background colors rather than assign a fixed color pair number,
65 and return an unused pair to the pool.
67 The number of colors may be related to the number of possible color
68 pairs for a given terminal, or it may not:
70 <STRONG>o</STRONG> While almost all terminals allow setting the color <EM>attributes</EM> inde-
71 pendently, it is unlikely that your terminal allows you to modify
72 the attributes of a given character cell without rewriting it.
73 That is, the foreground and background colors are applied as a
76 <STRONG>o</STRONG> Color pairs are the curses library's way of managing a color pal-
77 ette on a terminal. If the library does not keep track of the <EM>com-</EM>
78 <EM>binations</EM> of colors which are displayed, it will be inefficient.
80 <STRONG>o</STRONG> For simple terminal emulators with only a few dozen color combina-
81 tions, it is convenient to use the maximum number of combinations
82 as the limit on color pairs:
84 <STRONG>COLORS</STRONG> <EM>*</EM> <STRONG>COLORS</STRONG>
86 <STRONG>o</STRONG> Terminals which support <EM>default</EM> <EM>colors</EM> distinct from "ANSI colors"
87 add to the possible combinations, producing this total:
89 <EM>(</EM> <STRONG>COLORS</STRONG> <EM>+</EM> <EM>1</EM> <EM>)</EM> <EM>*</EM> <EM>(</EM> <STRONG>COLORS</STRONG> <EM>+</EM> <EM>1</EM> <EM>)</EM>
91 <STRONG>o</STRONG> An application might use up to a few dozen color pairs to implement
92 a predefined color scheme.
94 Beyond that lies in the realm of programs using the foreground and
95 background colors for "ASCII art" (or some other non-textual appli-
98 Also beyond those few dozen pairs, the required size for a table to
99 represent the combinations grows rapidly with an increasing number
102 These functions allow a developer to let the screen library manage
106 </PRE><H3><a name="h3-alloc_pair">alloc_pair</a></H3><PRE>
107 The <STRONG>alloc_pair</STRONG> function accepts parameters for foreground and back-
108 ground color, and checks if that color combination is already associ-
109 ated with a color pair.
111 <STRONG>o</STRONG> If the combination already exists, <STRONG>alloc_pair</STRONG> returns the existing
114 <STRONG>o</STRONG> If the combination does not exist, <STRONG>alloc_pair</STRONG> allocates a new color
115 pair and returns that.
117 <STRONG>o</STRONG> If the table fills up, <STRONG>alloc_pair</STRONG> discards the least-recently allo-
118 cated entry using <STRONG>free_pair</STRONG> and allocates a new color pair.
120 All of the color pairs are allocated from a table of possible color
121 pairs. The size of the table is determined by the terminfo <EM>pairs</EM> capa-
122 bility. The table is shared with <STRONG>init_pair</STRONG>; in fact <STRONG>alloc_pair</STRONG> calls
123 <STRONG>init_pair</STRONG> after updating the ncurses library's fast index to the colors
127 </PRE><H3><a name="h3-find_pair">find_pair</a></H3><PRE>
128 The <STRONG>find_pair</STRONG> function accepts parameters for foreground and background
129 color, and checks if that color combination is already associated with
130 a color pair, returning the pair number if it has been allocated. Oth-
131 erwise it returns -1.
134 </PRE><H3><a name="h3-free_pair">free_pair</a></H3><PRE>
135 Marks the given color pair as unused, i.e., like color pair 0.
138 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
139 The <STRONG>alloc_pair</STRONG> function returns a color pair number in the range 1
140 through <STRONG>COLOR_PAIRS</STRONG>-1, unless it encounters an error updating its fast
141 index to the color pair values, preventing it from allocating a color
142 pair. In that case, it returns -1.
144 The <STRONG>find_pair</STRONG> function returns a color pair number if the given color
145 combination has been associated with a color pair, or -1 if not.
147 Likewise, <STRONG>free_pair</STRONG> returns <STRONG>OK</STRONG> unless it encounters an error updating
148 the fast index or if no such color pair is in use.
151 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
152 These routines are specific to ncurses. They were not supported on
153 Version 7, BSD or System V implementations. It is recommended that any
154 code depending on them be conditioned using NCURSES_VERSION.
157 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
158 <STRONG><A HREF="init_pair.3x.html">init_pair(3x)</A></STRONG>.
161 </PRE><H2><a name="h2-AUTHOR">AUTHOR</a></H2><PRE>
166 <STRONG><A HREF="new_pair.3x.html">new_pair(3x)</A></STRONG>
170 <li><a href="#h2-NAME">NAME</a></li>
171 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
172 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
174 <li><a href="#h3-alloc_pair">alloc_pair</a></li>
175 <li><a href="#h3-find_pair">find_pair</a></li>
176 <li><a href="#h3-free_pair">free_pair</a></li>
179 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
180 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
181 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
182 <li><a href="#h2-AUTHOR">AUTHOR</a></li>