]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/new_pair.3x
ncurses 6.0 - patch 20170527
[ncurses.git] / man / new_pair.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 2017 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.9 2017/03/13 21:21:34 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 .IP \(bu 4
39 ..
40 .de NS
41 .ie \n(.sp
42 .el    .sp .5
43 .ie \n(.in +4
44 .el    .in +2
45 .nf
46 .ft C                   \" Courier
47 ..
48 .de NE
49 .fi
50 .ft R
51 .in -4
52 ..
53 .SH NAME
54 \fBalloc_pair\fP,
55 \fBfind_pair\fP,
56 \fBfree_pair\fP \- new curses color-pair functions
57 .SH SYNOPSIS
58 \fB#include <curses.h>\fP
59 .sp
60 \fBint alloc_pair(int fg, int bg);\fP
61 .br
62 \fBint find_pair(int fg, int bg);\fP
63 .br
64 \fBint free_pair(int pair);\fP
65 .SH DESCRIPTION
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.
70 .PP
71 The number of colors may be related to the number of possible color
72 pairs for a given terminal, or it may not:
73 .bP
74 While almost all terminals allow setting the color \fIattributes\fP
75 independently,
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.
79 .bP
80 Color pairs are the curses library's way of managing a color palette
81 on a terminal.
82 If the library does not keep track of the \fIcombinations\fP of 
83 colors which are displayed, it will be inefficient.
84 .bP
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:
89 .NS
90 \fBCOLORS\fP\fI * \fP\fBCOLORS\fP
91 .NE
92 .bP
93 Terminals which support \fIdefault colors\fP distinct from \*(``ANSI colors\*('' 
94 add to the possible combinations, producing this total:
95 .NS
96 \fI( \fP\fBCOLORS\fP\fI + 1 ) * ( \fP\fBCOLORS\fP\fI + 1 )\fP
97 .NE
98 .bP
99 An application might use up to a few dozen color pairs to
100 implement a predefined color scheme.
101 .IP
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).
105 .IP
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.
108 .IP
109 These functions allow a developer to let the screen library
110 manage color pairs.
111 .SS alloc_pair
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.
115 .bP
116 If the combination already exists, \fBalloc_pair\fP returns the existing pair.
117 .bP
118 If the combination does not exist, \fBalloc_pair\fP allocates a new color pair and returns that.
119 .bP
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.
122 .PP
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.
128 .SS find_pair
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.
134 .SS free_pair
135 Marks the given color pair as unused,
136 i.e., like color pair 0.
137 .SH RETURN VALUE
138 .PP
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.
143 .PP
144 The \fBfind_pair\fP function returns a color pair number if the
145 given color combination has been associated with a color pair,
146 or \-1 if not.
147 .PP
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.
150 .SH PORTABILITY
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.
154 .SH SEE ALSO
155 \fBinit_pair\fR(3X).
156 .SH AUTHOR
157 Thomas Dickey.