]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/new_pair.3x.html
ncurses 6.4 - patch 20240420
[ncurses.git] / doc / html / man / new_pair.3x.html
1 <!--
2   ****************************************************************************
3   * Copyright 2018-2021,2022 Thomas E. Dickey                                *
4   * Copyright 2017 Free Software Foundation, Inc.                            *
5   *                                                                          *
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:                 *
13   *                                                                          *
14   * The above copyright notice and this permission notice shall be included  *
15   * in all copies or substantial portions of the Software.                   *
16   *                                                                          *
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.                               *
24   *                                                                          *
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       *
28   * authorization.                                                           *
29   ****************************************************************************
30   * Author: Thomas E. Dickey
31   * @Id: new_pair.3x,v 1.19 2022/02/12 20:03:40 tom Exp @
32 -->
33 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
34 <HTML>
35 <HEAD>
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
41 </HEAD>
42 <BODY>
43 <H1 class="no-header">new_pair 3x</H1>
44 <PRE>
45 <STRONG><A HREF="new_pair.3x.html">new_pair(3x)</A></STRONG>                                                      <STRONG><A HREF="new_pair.3x.html">new_pair(3x)</A></STRONG>
46
47
48
49
50 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
51        <STRONG>alloc_pair</STRONG>, <STRONG>find_pair</STRONG>, <STRONG>free_pair</STRONG> - new curses color-pair functions
52
53
54 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
55        <STRONG>#include</STRONG> <STRONG>&lt;curses.h&gt;</STRONG>
56
57        <STRONG>int</STRONG> <STRONG>alloc_pair(int</STRONG> <EM>fg</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>bg</EM><STRONG>);</STRONG>
58        <STRONG>int</STRONG> <STRONG>find_pair(int</STRONG> <EM>fg</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>bg</EM><STRONG>);</STRONG>
59        <STRONG>int</STRONG> <STRONG>free_pair(int</STRONG> <EM>pair</EM><STRONG>);</STRONG>
60
61
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.
67
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
71        <STRONG>o</STRONG>   While  almost  all  terminals  allow  setting  the color <EM>attributes</EM>
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
75            pair.
76
77        <STRONG>o</STRONG>   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            <EM>combinations</EM> of colors which are displayed, it will be inefficient.
80
81        <STRONG>o</STRONG>   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:
84
85                <STRONG>COLORS</STRONG> <EM>*</EM> <STRONG>COLORS</STRONG>
86
87        <STRONG>o</STRONG>   Terminals  which support <EM>default</EM> <EM>colors</EM> distinct from "ANSI colors"
88            add to the possible combinations, producing this total:
89
90                <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
92        <STRONG>o</STRONG>   An application might use up to a few dozen color pairs to implement
93            a predefined color scheme.
94
95            Beyond  that lies in the realm of programs using the foreground and
96            background colors  for  "ASCII  art"  (or  some  other  non-textual
97            application).
98
99            Also beyond those few dozen pairs, the required size for a table to
100            represent the combinations grows rapidly with an increasing  number
101            of colors.
102
103            These  functions allow a developer to let the screen library manage
104            color pairs.
105
106
107 </PRE><H3><a name="h3-alloc_pair">alloc_pair</a></H3><PRE>
108        The  <STRONG>alloc_pair</STRONG>  function  accepts  parameters   for   foreground   and
109        background  color,  and  checks  if  that  color combination is already
110        associated with a color pair.
111
112        <STRONG>o</STRONG>   If the combination already exists, <STRONG>alloc_pair</STRONG> returns the  existing
113            pair.
114
115        <STRONG>o</STRONG>   If the combination does not exist, <STRONG>alloc_pair</STRONG> allocates a new color
116            pair and returns that.
117
118        <STRONG>o</STRONG>   If the table  fills  up,  <STRONG>alloc_pair</STRONG>  discards  the  least-recently
119            allocated entry using <STRONG>free_pair</STRONG> and allocates a new color pair.
120
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  <STRONG>pairs</STRONG>
123        capability.   The  table  is  shared with <STRONG>init_pair</STRONG>; in fact <STRONG>alloc_pair</STRONG>
124        calls <STRONG>init_pair</STRONG> after updating the ncurses library's fast index to  the
125        colors versus color pairs.
126
127
128 </PRE><H3><a name="h3-find_pair">find_pair</a></H3><PRE>
129        The <STRONG>find_pair</STRONG> 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.
133
134
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.
137
138
139 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
140        The <STRONG>alloc_pair</STRONG> function returns a color pair  number  in  the  range  1
141        through  <STRONG>COLOR_PAIRS</STRONG>-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.
144
145        The  <STRONG>find_pair</STRONG>  function returns a color pair number if the given color
146        combination has been associated with a color pair, or -1 if not.
147
148        Likewise, <STRONG>free_pair</STRONG> returns <STRONG>OK</STRONG> unless it encounters an  error  updating
149        the fast index or if no such color pair is in use.
150
151
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.
156
157
158 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
159        <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>.
160
161
162 </PRE><H2><a name="h2-AUTHOR">AUTHOR</a></H2><PRE>
163        Thomas Dickey.
164
165
166
167                                                                   <STRONG><A HREF="new_pair.3x.html">new_pair(3x)</A></STRONG>
168 </PRE>
169 <div class="nav">
170 <ul>
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>
174 <ul>
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>
178 </ul>
179 </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>
184 </ul>
185 </div>
186 </BODY>
187 </HTML>