]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/new_pair.3x
ncurses 6.1 - patch 20181229
[ncurses.git] / man / new_pair.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 2017,2018 Free Software Foundation, Inc.                   *
3 .\"                                                                          *
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:                 *
11 .\"                                                                          *
12 .\" The above copyright notice and this permission notice shall be included  *
13 .\" in all copies or substantial portions of the Software.                   *
14 .\"                                                                          *
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.                               *
22 .\"                                                                          *
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       *
26 .\" authorization.                                                           *
27 .\"***************************************************************************
28 .\"
29 .\" Author: Thomas E. Dickey
30 .\"
31 .\" $Id: new_pair.3x,v 1.13 2018/07/28 22:19:56 tom Exp $
32 .TH new_pair 3X ""
33 .ie \n(.g .ds `` \(lq
34 .el       .ds `` ``
35 .ie \n(.g .ds '' \(rq
36 .el       .ds '' ''
37 .de bP
38 .ie n  .IP \(bu 4
39 .el    .IP \(bu 2
40 ..
41 .de NS
42 .ie n  .sp
43 .el    .sp .5
44 .ie n  .in +4
45 .el    .in +2
46 .nf
47 .ft C                   \" Courier
48 ..
49 .de NE
50 .fi
51 .ft R
52 .ie n  .in -4
53 .el    .in -2
54 ..
55 .SH NAME
56 \fBalloc_pair\fP,
57 \fBfind_pair\fP,
58 \fBfree_pair\fP \- new curses color-pair functions
59 .SH SYNOPSIS
60 \fB#include <curses.h>\fP
61 .sp
62 \fBint alloc_pair(int fg, int bg);\fP
63 .br
64 \fBint find_pair(int fg, int bg);\fP
65 .br
66 \fBint free_pair(int pair);\fP
67 .SH DESCRIPTION
68 These functions are an extension to the curses library.
69 They permit an application to dynamically allocate a color pair using
70 the foreground/background colors rather than assign a fixed color pair number,
71 and return an unused pair to the pool.
72 .PP
73 The number of colors may be related to the number of possible color
74 pairs for a given terminal, or it may not:
75 .bP
76 While almost all terminals allow setting the color \fIattributes\fP
77 independently,
78 it is unlikely that your terminal allows you to modify the attributes
79 of a given character cell without rewriting it.
80 That is, the foreground and background colors are applied as a pair.
81 .bP
82 Color pairs are the curses library's way of managing a color palette
83 on a terminal.
84 If the library does not keep track of the \fIcombinations\fP of 
85 colors which are displayed, it will be inefficient.
86 .bP
87 For simple terminal emulators
88 with only a few dozen color combinations,
89 it is convenient to use the maximum number of combinations
90 as the limit on color pairs:
91 .NS
92 \fBCOLORS\fP\fI * \fP\fBCOLORS\fP
93 .NE
94 .bP
95 Terminals which support \fIdefault colors\fP distinct
96 from \*(``ANSI colors\*('' 
97 add to the possible combinations, producing this total:
98 .NS
99 \fI( \fP\fBCOLORS\fP\fI + 1 ) * ( \fP\fBCOLORS\fP\fI + 1 )\fP
100 .NE
101 .bP
102 An application might use up to a few dozen color pairs to
103 implement a predefined color scheme.
104 .IP
105 Beyond that lies in the realm of programs using the foreground
106 and background colors for \*(``ASCII art\*('' 
107 (or some other non-textual application).
108 .IP
109 Also beyond those few dozen pairs, the required size for a table
110 to represent the combinations grows rapidly with an increasing number of colors.
111 .IP
112 These functions allow a developer to let the screen library
113 manage color pairs.
114 .SS alloc_pair
115 The \fBalloc_pair\fP function accepts parameters for
116 foreground and background color, and
117 checks if that color combination is already associated with a color pair.
118 .bP
119 If the combination already exists,
120 \fBalloc_pair\fP returns the existing pair.
121 .bP
122 If the combination does not exist,
123 \fBalloc_pair\fP allocates a new color pair and returns that.
124 .bP
125 If the table fills up, \fBalloc_pair\fP discards the least-recently
126 allocated entry using \fBfree_pair\fP and allocates a new color pair.
127 .PP
128 All of the color pairs are allocated from a table of possible color pairs.
129 The size of the table is determined by the terminfo \fIpairs\fP capability.
130 The table is shared with \fBinit_pair\fP;
131 in fact \fBalloc_pair\fP calls \fBinit_pair\fP after
132 updating the ncurses library's fast index to the colors versus color pairs.
133 .SS find_pair
134 The \fBfind_pair\fP function accepts parameters for
135 foreground and background color, and
136 checks if that color combination is already associated with a color pair,
137 returning the pair number if it has been allocated.
138 Otherwise it returns \-1.
139 .SS free_pair
140 Marks the given color pair as unused,
141 i.e., like color pair 0.
142 .SH RETURN VALUE
143 .PP
144 The \fBalloc_pair\fP function returns a color pair number in the range
145 1 through \fBCOLOR_PAIRS\fP\-1, unless it encounters an error updating
146 its fast index to the color pair values, preventing it from allocating
147 a color pair.
148 In that case, it returns \-1.
149 .PP
150 The \fBfind_pair\fP function returns a color pair number if the
151 given color combination has been associated with a color pair,
152 or \-1 if not.
153 .PP
154 Likewise, \fBfree_pair\fP returns \fBOK\fP unless it encounters an
155 error updating the fast index or if no such color pair is in use.
156 .SH PORTABILITY
157 These routines are specific to ncurses.
158 They were not supported on
159 Version 7, BSD or System V implementations.
160 It is recommended that
161 any code depending on them be conditioned using NCURSES_VERSION.
162 .SH SEE ALSO
163 \fBcurs_color\fR(3X).
164 .SH AUTHOR
165 Thomas Dickey.