]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/new_pair.3x
ncurses 6.0 - patch 20170311
[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.8 2017/03/09 09:59:11 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 \fBfree_pair\fP \- new curses color-pair functions
56 .SH SYNOPSIS
57 \fB#include <curses.h>\fP
58 .sp
59 \fBint alloc_pair(int fg, int bg);\fP
60 .br
61 \fBint free_pair(int pair);\fP
62 .SH DESCRIPTION
63 These functions are an extension to the curses library.
64 They permit an application to dynamically allocate a color pair using
65 the foreground/background colors rather than assign a fixed color pair number,
66 and return an unused pair to the pool.
67 .PP
68 The number of colors may be related to the number of possible color
69 pairs for a given terminal, or it may not:
70 .bP
71 While almost all terminals allow setting the color \fIattributes\fP
72 independently,
73 it is unlikely that your terminal allows you to modify the attributes
74 of a given character cell without rewriting it.
75 That is, the foreground and background colors are applied as a pair.
76 .bP
77 Color pairs are the curses library's way of managing a color palette
78 on a terminal.
79 If the library does not keep track of the \fIcombinations\fP of 
80 colors which are displayed, it will be inefficient.
81 .bP
82 For simple terminal emulators
83 with only a few dozen color combinations,
84 it is convenient to use the maximum number of combinations
85 as the limit on color pairs:
86 .NS
87 \fBCOLORS\fP\fI * \fP\fBCOLORS\fP
88 .NE
89 .bP
90 Terminals which support \fIdefault colors\fP distinct from \*(``ANSI colors\*('' 
91 add to the possible combinations, producing this total:
92 .NS
93 \fI( \fP\fBCOLORS\fP\fI + 1 ) * ( \fP\fBCOLORS\fP\fI + 1 )\fP
94 .NE
95 .bP
96 An application might use up to a few dozen color pairs to
97 implement a predefined color scheme.
98 .IP
99 Beyond that lies in the realm of programs using the foreground
100 and background colors for \*(``ASCII art\*('' 
101 (or some other non-textual application).
102 .IP
103 Also beyond those few dozen pairs, the required size for a table
104 to represent the combinations grows rapidly with an increasing number of colors.
105 .IP
106 These functions allow a developer to let the screen library
107 manage color pairs.
108 .SS alloc_pair
109 The \fBalloc_pair\fP function accepts parameters for
110 foreground and background color, and
111 checks if that color combination is already associated with a color pair.
112 .bP
113 If the combination already exists, \fBalloc_pair\fP returns the existing pair.
114 .bP
115 If the combination does not exist, \fBalloc_pair\fP allocates a new color pair and returns that.
116 .bP
117 If the table fills up, \fBalloc_pair\fP discards the least-recently
118 allocated entry using \fBfree_pair\fP and allocates a new color pair.
119 .PP
120 All of the color pairs are allocated from a table of possible color pairs.
121 The size of the table is determined by the terminfo \fIpairs\fP capability.
122 The table is shared with \fBinit_pair\fP;
123 in fact \fBalloc_pair\fP calls \fBinit_pair\fP after
124 updating the ncurses library's fast index to the colors versus color pairs.
125 .SS find_pair
126 The \fBfind_pair\fP function accepts parameters for
127 foreground and background color, and
128 checks if that color combination is already associated with a color pair,
129 returning the pair number if it has been allocated.
130 Otherwise it returns \-1.
131 .SS free_pair
132 Marks the given color pair as unused,
133 i.e., like color pair 0.
134 .SH RETURN VALUE
135 .PP
136 The \fBalloc_pair\fP function returns a color pair number in the range
137 1 through \fBCOLOR_PAIRS\fP\-1, unless it encounters an error updating
138 its fast index to the color pair values, preventing it from allocating
139 a color pair.  In that case, it returns \-1.
140 .PP
141 The \fBfind_pair\fP function returns a color pair number if the
142 given color combination has been associated with a color pair,
143 or \-1 if not.
144 .PP
145 Likewise, \fBfree_pair\fP returns \fBOK\fP unless it encounters an
146 error updating the fast index or if no such color pair is in use.
147 .SH PORTABILITY
148 These routines are specific to ncurses.  They were not supported on
149 Version 7, BSD or System V implementations.  It is recommended that
150 any code depending on them be conditioned using NCURSES_VERSION.
151 .SH SEE ALSO
152 \fBinit_pair\fR(3X).
153 .SH AUTHOR
154 Thomas Dickey.