Debian Codegraph @

doc/html/man/curs_color.3x.html

raw symbols SCIP
1 <!--
2 ****************************************************************************
3 * Copyright 2018-2024,2025 Thomas E. Dickey *
4 * Copyright 1998-2016,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 * @Id: curs_color.3x,v 1.126 2025/08/23 22:39:20 tom Exp @
31 -->
32 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
33 <HTML>
34 <HEAD>
35 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
36 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
37 <TITLE>curs_color 3x 2025-08-23 ncurses 6.6 Library calls</TITLE>
38 <link rel="author" href="mailto:[email protected]">
39
40 </HEAD>
41 <BODY>
42 <H1 class="no-header">curs_color 3x 2025-08-23 ncurses 6.6 Library calls</H1>
43 <PRE>
44 <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG> Library calls <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
45
46
47 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
48 <STRONG>start_color</STRONG>, <STRONG>has_colors</STRONG>, <STRONG>can_change_color</STRONG>, <STRONG>init_pair</STRONG>, <STRONG>init_color</STRONG>,
49 <STRONG>init_extended_pair</STRONG>, <STRONG>init_extended_color</STRONG>, <STRONG>color_content</STRONG>, <STRONG>pair_content</STRONG>,
50 <STRONG>extended_color_content</STRONG>, <STRONG>extended_pair_content</STRONG>, <STRONG>reset_color_pairs</STRONG>,
51 <STRONG>COLOR_PAIR</STRONG>, <STRONG>PAIR_NUMBER</STRONG>, <STRONG>COLORS</STRONG>, <STRONG>COLOR_PAIRS</STRONG>, <STRONG>COLOR_BLACK</STRONG>, <STRONG>COLOR_RED</STRONG>,
52 <STRONG>COLOR_GREEN</STRONG>, <STRONG>COLOR_YELLOW</STRONG>, <STRONG>COLOR_BLUE</STRONG>, <STRONG>COLOR_MAGENTA</STRONG>, <STRONG>COLOR_CYAN</STRONG>,
53 <STRONG>COLOR_WHITE</STRONG>, <STRONG>A_COLOR</STRONG> - manipulate terminal colors with <EM>curses</EM>
54
55
56 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
57 <STRONG>#include</STRONG> <STRONG>&lt;curses.h&gt;</STRONG>
58
59 <EM>/*</EM> <EM>variables</EM> <EM>*/</EM>
60 <STRONG>int</STRONG> <STRONG>COLOR_PAIRS;</STRONG>
61 <STRONG>int</STRONG> <STRONG>COLORS;</STRONG>
62
63 <STRONG>int</STRONG> <STRONG>start_color(void);</STRONG>
64
65 <STRONG>bool</STRONG> <STRONG>has_colors(void);</STRONG>
66 <STRONG>bool</STRONG> <STRONG>can_change_color(void);</STRONG>
67
68 <STRONG>int</STRONG> <STRONG>init_pair(short</STRONG> <EM>pair</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <EM>f</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <EM>b</EM><STRONG>);</STRONG>
69 <STRONG>int</STRONG> <STRONG>init_color(short</STRONG> <EM>color</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <EM>r</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <EM>g</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <EM>b</EM><STRONG>);</STRONG>
70 <EM>/*</EM> <EM>extensions</EM> <EM>*/</EM>
71 <STRONG>int</STRONG> <STRONG>init_extended_pair(int</STRONG> <EM>pair</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>f</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>b</EM><STRONG>);</STRONG>
72 <STRONG>int</STRONG> <STRONG>init_extended_color(int</STRONG> <EM>color</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>r</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>g</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>b</EM><STRONG>);</STRONG>
73
74 <STRONG>int</STRONG> <STRONG>color_content(short</STRONG> <EM>color</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <STRONG>*</STRONG><EM>r</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <STRONG>*</STRONG><EM>g</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <STRONG>*</STRONG><EM>b</EM><STRONG>);</STRONG>
75 <STRONG>int</STRONG> <STRONG>pair_content(short</STRONG> <EM>pair</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <STRONG>*</STRONG><EM>f</EM><STRONG>,</STRONG> <STRONG>short</STRONG> <STRONG>*</STRONG><EM>b</EM><STRONG>);</STRONG>
76 <EM>/*</EM> <EM>extensions</EM> <EM>*/</EM>
77 <STRONG>int</STRONG> <STRONG>extended_color_content(int</STRONG> <EM>color</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <STRONG>*</STRONG><EM>r</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <STRONG>*</STRONG><EM>g</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <STRONG>*</STRONG><EM>b</EM><STRONG>);</STRONG>
78 <STRONG>int</STRONG> <STRONG>extended_pair_content(int</STRONG> <EM>pair</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <STRONG>*</STRONG><EM>f</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <STRONG>*</STRONG><EM>b</EM><STRONG>);</STRONG>
79
80 <EM>/*</EM> <EM>extension</EM> <EM>*/</EM>
81 <STRONG>void</STRONG> <STRONG>reset_color_pairs(void);</STRONG>
82
83 <EM>/*</EM> <EM>macros</EM> <EM>*/</EM>
84 <STRONG>int</STRONG> <STRONG>COLOR_PAIR(int</STRONG> <EM>n</EM><STRONG>);</STRONG>
85 <STRONG>PAIR_NUMBER(int</STRONG> <EM>attr</EM><STRONG>);</STRONG>
86 <STRONG>COLOR_BLACK</STRONG>
87 <STRONG>COLOR_RED</STRONG>
88 <STRONG>COLOR_GREEN</STRONG>
89 <STRONG>COLOR_YELLOW</STRONG>
90 <STRONG>COLOR_BLUE</STRONG>
91 <STRONG>COLOR_MAGENTA</STRONG>
92 <STRONG>COLOR_CYAN</STRONG>
93 <STRONG>COLOR_WHITE</STRONG>
94 <STRONG>A_COLOR</STRONG>
95
96
97 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
98
99 </PRE><H3><a name="h3-Overview">Overview</a></H3><PRE>
100 <EM>curses</EM> supports color attributes on terminals with that capability.
101 Call <STRONG>start_color</STRONG> (typically right after <STRONG><A HREF="curs_initscr.3x.html">initscr(3x)</A></STRONG>) to enable this
102 feature. Colors are always used in pairs. A <EM>color</EM> <EM>pair</EM> couples a
103 foreground color for characters with a background color for the blank
104 field on which characters are rendered. <STRONG>init_pair</STRONG> initializes a color
105 pair. The macro <STRONG>COLOR_PAIR</STRONG>(<EM>n</EM>) can then convert the pair to a video
106 attribute.
107
108 If a terminal has the relevant capability, <STRONG>init_color</STRONG> permits
109 (re)definition of a color. <STRONG>has_colors</STRONG> and <STRONG>can_change_color</STRONG> return <STRONG>TRUE</STRONG>
110 or <STRONG>FALSE</STRONG>, depending on whether the terminal has color capability and
111 whether the programmer can change the colors. <STRONG>color_content</STRONG> permits
112 extraction of the red, green, and blue components of an initialized
113 color. <STRONG>pair_content</STRONG> permits discovery of a color pair's current
114 definition.
115
116
117 </PRE><H3><a name="h3-Rendering">Rendering</a></H3><PRE>
118 <EM>curses</EM> combines the following data to render a character cell. Any of
119 them can include color information.
120
121 <STRONG>o</STRONG> <EM>curses</EM> character attributes, as from <STRONG><A HREF="curs_addch.3x.html">waddch(3x)</A></STRONG> or <STRONG><A HREF="curs_add_wch.3x.html">wadd_wch(3x)</A></STRONG>
122
123 <STRONG>o</STRONG> window attributes, as from <STRONG><A HREF="curs_attr.3x.html">wattrset(3x)</A></STRONG> or <STRONG><A HREF="curs_attr.3x.html">wattr_set(3x)</A></STRONG>
124
125 <STRONG>o</STRONG> window background character attributes, as from <STRONG><A HREF="curs_bkgd.3x.html">wbkgdset(3x)</A></STRONG> or
126 <STRONG><A HREF="curs_bkgrnd.3x.html">wbkgrndset(3x)</A></STRONG>
127
128 Per-character and window attributes are usually set through a function
129 parameter containing attributes including a color pair value. Some
130 functions, such as <STRONG>wattr_set</STRONG>, use a separate color pair number
131 parameter.
132
133 The background character is a special case: it includes a character
134 code, just as if it were passed to <STRONG>waddch</STRONG>.
135
136 The <EM>curses</EM> library does the actual work of combining these color pairs
137 in an internal function called from <STRONG>waddch</STRONG>:
138
139 <STRONG>o</STRONG> If the parameter passed to <STRONG>waddch</STRONG> is <EM>blank</EM>, and it uses the special
140 color pair 0, <EM>curses</EM> next checks the window attribute.
141
142 <STRONG>o</STRONG> If the window attribute does not use color pair 0, <EM>curses</EM> uses
143 the color pair from the window attribute.
144
145 <STRONG>o</STRONG> Otherwise, <EM>curses</EM> uses the background character.
146
147 <STRONG>o</STRONG> If the parameter passed to <STRONG>waddch</STRONG> is <EM>not</EM> <EM>blank</EM>, or it does not use
148 the special color pair 0, <EM>curses</EM> prefers the color pair from the
149 parameter, if it is nonzero. Otherwise, it tries the window
150 attribute next, and finally the background character.
151
152 Some <EM>curses</EM> functions such as <STRONG>wprintw</STRONG> call <STRONG>waddch</STRONG>. Those do not
153 combine its parameter with a color pair. Consequently those calls use
154 only the window attribute or the background character.
155
156
157 </PRE><H2><a name="h2-CONSTANTS">CONSTANTS</a></H2><PRE>
158 ISO 6429 and ECMA-48 define eight standard colors (also known as "ANSI"
159 colors). <EM>curses.h</EM> defines object-like macros <STRONG>COLOR_BLACK</STRONG>, <STRONG>COLOR_RED</STRONG>,
160 <STRONG>COLOR_GREEN</STRONG>, <STRONG>COLOR_YELLOW</STRONG>, <STRONG>COLOR_BLUE</STRONG>, <STRONG>COLOR_MAGENTA</STRONG>, <STRONG>COLOR_CYAN</STRONG>, and
161 <STRONG>COLOR_WHITE</STRONG> accordingly. <EM>curses</EM> assumes that <STRONG>COLOR_BLACK</STRONG> is the
162 default background color for all terminals. <EM>ncurses</EM> offers an
163 extension to override that assumption; see <STRONG><A HREF="default_colors.3x.html">assume_default_colors(3x)</A></STRONG>.
164 Some terminals support additional colors that lack standard names.
165
166 <STRONG>A_COLOR</STRONG> is a bit mask that, when bitwise "and"-ed with a <EM>chtype</EM>,
167 extracts its color pair identifier.
168
169
170 </PRE><H2><a name="h2-VARIABLES">VARIABLES</a></H2><PRE>
171
172 </PRE><H3><a name="h3-COLORS">COLORS</a></H3><PRE>
173 is initialized by <STRONG>start_color</STRONG> to the maximum number of colors the
174 terminal can support.
175
176
177 </PRE><H3><a name="h3-COLOR_PAIRS">COLOR_PAIRS</a></H3><PRE>
178 is initialized by <STRONG>start_color</STRONG> to the maximum number of color pairs the
179 terminal can support. Often, its value is the product <STRONG>COLORS</STRONG> x <STRONG>COLORS</STRONG>,
180 but this is not always true.
181
182 <STRONG>o</STRONG> A few terminals use the HLS color space (see <STRONG>start_color</STRONG> below),
183 ignoring this rule; and
184
185 <STRONG>o</STRONG> terminals supporting a large number of colors are limited to the
186 number of color pairs that a <EM>signed</EM> <EM>short</EM> value can represent.
187
188
189 </PRE><H2><a name="h2-FUNCTIONS">FUNCTIONS</a></H2><PRE>
190
191 </PRE><H3><a name="h3-start_color">start_color</a></H3><PRE>
192 The <STRONG>start_color</STRONG> routine requires no arguments. It must be called if
193 the programmer wants to use colors, and before any other color
194 manipulation routine is called. It is good practice to call this
195 routine right after <STRONG>initscr</STRONG>. <STRONG>start_color</STRONG> does this:
196
197 <STRONG>o</STRONG> It initializes two global variables, <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG>
198 (respectively defining the maximum number of colors and color pairs
199 the terminal can support).
200
201 <STRONG>o</STRONG> It initializes the special color pair <STRONG>0</STRONG> to the default foreground
202 and background colors. No other color pairs are initialized.
203
204 <STRONG>o</STRONG> It restores the colors on the terminal to the values they had when
205 the terminal was just turned on.
206
207 <STRONG>o</STRONG> If the terminal supports the <STRONG>initc</STRONG> (<STRONG>initialize_color</STRONG>) capability,
208 <STRONG>start_color</STRONG> initializes its internal table representing the red,
209 green, and blue components of the color palette.
210
211 The components depend on whether the terminal uses CGA (aka "ANSI")
212 or HLS (i.e., the <STRONG>hls</STRONG> (<STRONG>hue_lightness_saturation</STRONG>) capability is
213 set). The table is initialized first for eight basic colors
214 (black, red, green, yellow, blue, magenta, cyan, and white), using
215 weights that depend upon the CGA/HLS choice. For "ANSI" colors the
216 weights are <STRONG>680</STRONG> or <STRONG>0</STRONG> depending on whether the corresponding red,
217 green, or blue component is used or not. That permits using <STRONG>1000</STRONG>
218 to represent bold/bright colors. After the initial eight colors
219 (if the terminal supports more than eight colors) the components
220 are initialized using the same pattern, but with weights of <STRONG>1000</STRONG>.
221 SVr4 uses a similar scheme, but uses <STRONG>1000</STRONG> for the components of the
222 initial eight colors.
223
224 <STRONG>start_color</STRONG> does not attempt to set the terminal's color palette to
225 match its built-in table. An application may use <STRONG>init_color</STRONG> to
226 alter the internal table along with the terminal's color.
227
228 These limits apply to color values and color pairs. Values outside
229 these limits are not valid, and may result in a runtime error:
230
231 <STRONG>o</STRONG> <STRONG>COLORS</STRONG> corresponds to the terminal database's <STRONG>max_colors</STRONG>
232 capability, (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
233
234 <STRONG>o</STRONG> color values are expected to be in the range <STRONG>0</STRONG> to <STRONG>COLORS-1</STRONG>,
235 inclusive (including <STRONG>0</STRONG> and <STRONG>COLORS-1</STRONG>).
236
237 <STRONG>o</STRONG> a special color value <STRONG>-1</STRONG> is used in certain extended functions to
238 denote the <EM>default</EM> <EM>color</EM> (see <STRONG><A HREF="default_colors.3x.html">use_default_colors(3x)</A></STRONG>).
239
240 <STRONG>o</STRONG> <STRONG>COLOR_PAIRS</STRONG> corresponds to the terminal database's <STRONG>max_pairs</STRONG>
241 capability, (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
242
243 <STRONG>o</STRONG> valid color pair values are in the range <STRONG>1</STRONG> to <STRONG>COLOR_PAIRS-1</STRONG>,
244 inclusive.
245
246 <STRONG>o</STRONG> color pair <STRONG>0</STRONG> is special; it denotes "no color".
247
248 Color pair <STRONG>0</STRONG> is assumed to be white on black, but is actually
249 whatever the terminal implements before color is initialized. It
250 cannot be modified by the application.
251
252
253 </PRE><H3><a name="h3-has_colors">has_colors</a></H3><PRE>
254 <STRONG>has_colors</STRONG> returns <STRONG>TRUE</STRONG> if the terminal supports colors and <STRONG>FALSE</STRONG> if it
255 does not. <STRONG><A HREF="curs_initscr.3x.html">initscr(3x)</A></STRONG> or <STRONG><A HREF="curs_initscr.3x.html">newterm(3x)</A></STRONG> must be called first, but
256 <STRONG>start_color</STRONG> need not be. An application might call <STRONG>has_colors</STRONG> to
257 decide whether to use color or a video attribute like <STRONG>A_BOLD</STRONG> to render
258 text.
259
260 Color support in <EM>curses</EM> requires that the terminal type description
261 support the capabilities <STRONG>max_colors</STRONG> (<STRONG>colors</STRONG>), <STRONG>max_pairs</STRONG> (<STRONG>pairs</STRONG>), and
262 any of
263
264 <STRONG>o</STRONG> <STRONG>set_foreground</STRONG> (<STRONG>setf</STRONG>) and <STRONG>set_background</STRONG> (<STRONG>setb</STRONG>);
265
266 <STRONG>o</STRONG> <STRONG>set_a_foreground</STRONG> (<STRONG>setaf</STRONG>) and <STRONG>set_a_background</STRONG> (<STRONG>setab</STRONG>); or
267
268 <STRONG>o</STRONG> <STRONG>set_color_pair</STRONG> (<STRONG>scp</STRONG>).
269
270
271 </PRE><H3><a name="h3-can_change_color">can_change_color</a></H3><PRE>
272 The <STRONG>can_change_color</STRONG> routine requires no arguments. It returns <STRONG>TRUE</STRONG> if
273 the terminal supports colors and can change their definitions; other,
274 it returns <STRONG>FALSE</STRONG>. This routine facilitates writing terminal-
275 independent programs.
276
277
278 </PRE><H3><a name="h3-init_pair">init_pair</a></H3><PRE>
279 The <STRONG>init_pair</STRONG> routine changes the definition of a color pair. It takes
280 three arguments: the number of the color pair to be changed, the
281 foreground color number, and the background color number. For portable
282 applications:
283
284 <STRONG>o</STRONG> The first argument must be a valid color pair value. If default
285 colors are used (see <STRONG><A HREF="default_colors.3x.html">use_default_colors(3x)</A></STRONG>) the upper limit is
286 adjusted to allow for extra pairs which use a default color in
287 foreground and/or background.
288
289 <STRONG>o</STRONG> The second and third arguments must be valid color values.
290
291 If the color pair was previously initialized, the screen is refreshed
292 and all occurrences of that color pair are changed to the new
293 definition.
294
295 As an extension, <EM>ncurses</EM> allows you to set color pair <STRONG>0</STRONG> via the
296 <STRONG><A HREF="default_colors.3x.html">assume_default_colors(3x)</A></STRONG> routine, or to specify the use of default
297 colors (color number <STRONG>-1</STRONG>) if you first invoke the <STRONG><A HREF="default_colors.3x.html">use_default_colors(3x)</A></STRONG>
298 routine.
299
300
301 </PRE><H3><a name="h3-init_extended_pair">init_extended_pair</a></H3><PRE>
302 Because <STRONG>init_pair</STRONG> uses signed <STRONG>short</STRONG>s for its parameters, that limits
303 color pairs and color-values to 32767 on modern hardware. The
304 extension <STRONG>init_extended_pair</STRONG> uses <STRONG>int</STRONG>s for the color pair and color-
305 value, allowing a larger number of colors to be supported.
306
307
308 </PRE><H3><a name="h3-init_color">init_color</a></H3><PRE>
309 The <STRONG>init_color</STRONG> routine changes the definition of a color. It takes
310 four arguments: the number of the color to be changed followed by three
311 RGB values (for the amounts of red, green, and blue components).
312
313 <STRONG>o</STRONG> The first argument must be a valid color value; default colors are
314 not allowed here. (See the section <STRONG>Colors</STRONG> for the default color
315 index.)
316
317 <STRONG>o</STRONG> Each of the last three arguments must be a value in the range <STRONG>0</STRONG>
318 through <STRONG>1000</STRONG>.
319
320 When <STRONG>init_color</STRONG> is used, all occurrences of that color on the screen
321 immediately change to the new definition.
322
323
324 </PRE><H3><a name="h3-init_extended_color">init_extended_color</a></H3><PRE>
325 Because <STRONG>init_color</STRONG> uses signed <STRONG>short</STRONG>s for its parameters, that limits
326 color-values and their red, green, and blue components to 32767 on
327 modern hardware. The extension <STRONG>init_extended_color</STRONG> uses <STRONG>int</STRONG>s for the
328 color value and for setting the red, green, and blue components,
329 allowing a larger number of colors to be supported.
330
331
332 </PRE><H3><a name="h3-color_content">color_content</a></H3><PRE>
333 The <STRONG>color_content</STRONG> routine gives programmers a way to find the intensity
334 of the red, green, and blue (RGB) components in a color. It requires
335 four arguments: the color number, and three addresses of <STRONG>short</STRONG>s for
336 storing the information about the amounts of red, green, and blue
337 components in the given color.
338
339 <STRONG>o</STRONG> The first argument must be a valid color value, i.e., <STRONG>0</STRONG> through
340 <STRONG>COLORS-1</STRONG>, inclusive.
341
342 <STRONG>o</STRONG> The values that are stored at the addresses pointed to by the last
343 three arguments are in the range <STRONG>0</STRONG> (no component) through <STRONG>1000</STRONG>
344 (maximum amount of component), inclusive.
345
346
347 </PRE><H3><a name="h3-extended_color_content">extended_color_content</a></H3><PRE>
348 Because <STRONG>color_content</STRONG> uses signed <STRONG>short</STRONG>s for its parameters, that
349 limits color-values and their red, green, and blue components to 32767
350 on modern hardware. The extension <STRONG>extended_color_content</STRONG> uses <STRONG>int</STRONG>s for
351 the color value and for returning the red, green, and blue components,
352 allowing a larger number of colors to be supported.
353
354
355 </PRE><H3><a name="h3-pair_content">pair_content</a></H3><PRE>
356 The <STRONG>pair_content</STRONG> routine allows programmers to find out what colors a
357 given color pair consists of. It requires three arguments: the color
358 pair number, and two addresses of <STRONG>short</STRONG>s for storing the foreground and
359 the background color numbers.
360
361 <STRONG>o</STRONG> The first argument must be a valid color value, i.e., in the range
362 <STRONG>1</STRONG> through <STRONG>COLOR_PAIRS-1</STRONG>, inclusive.
363
364 <STRONG>o</STRONG> The values that are stored at the addresses pointed to by the
365 second and third arguments are in the range <STRONG>0</STRONG> through <STRONG>COLORS</STRONG>,
366 inclusive.
367
368
369 </PRE><H3><a name="h3-extended_pair_content">extended_pair_content</a></H3><PRE>
370 Because <STRONG>pair_content</STRONG> uses signed <STRONG>short</STRONG>s for its parameters, that limits
371 color pair and color-values to 32767 on modern hardware. The extension
372 <STRONG>extended_pair_content</STRONG> uses <STRONG>int</STRONG>s for the color pair and for returning
373 the foreground and background colors, allowing a larger number of
374 colors to be supported.
375
376
377 </PRE><H3><a name="h3-reset_color_pairs">reset_color_pairs</a></H3><PRE>
378 The extension <STRONG>reset_color_pairs</STRONG> tells <EM>ncurses</EM> to discard all of the
379 color pair information which was set with <STRONG>init_pair</STRONG>. It also touches
380 the current- and standard-screens, allowing an application to switch
381 color palettes rapidly.
382
383
384 </PRE><H3><a name="h3-COLOR_PAIR">COLOR_PAIR</a></H3><PRE>
385 <STRONG>COLOR_PAIR(</STRONG><EM>n</EM><STRONG>)</STRONG> converts a color pair number to an attribute. Attributes
386 can hold color pairs in the range 0 to 255. If you need a color pair
387 larger than that, you must use functions such as <STRONG>attr_set</STRONG> (which pass
388 the color pair as a separate parameter) rather than the legacy
389 functions such as <STRONG>attrset</STRONG>.
390
391
392 </PRE><H3><a name="h3-PAIR_NUMBER">PAIR_NUMBER</a></H3><PRE>
393 <STRONG>PAIR_NUMBER(</STRONG><EM>attr</EM>) extracts the color information from its <EM>attr</EM>
394 parameter and returns it as a color pair number; it is the inverse
395 operation of <STRONG>COLOR_PAIR</STRONG>.
396
397
398 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
399 <STRONG>can_change_color</STRONG> and <STRONG>has_colors</STRONG> return <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>. The other
400 functions return <STRONG>OK</STRONG> on success and <STRONG>ERR</STRONG> on failure.
401
402 In <EM>ncurses</EM>, functions returning an <EM>int</EM> recognize several error
403 conditions.
404
405 <STRONG>o</STRONG> All return <STRONG>ERR</STRONG> if the screen has not been initialized; see
406 <STRONG><A HREF="curs_initscr.3x.html">initscr(3x)</A></STRONG> or <STRONG><A HREF="curs_initscr.3x.html">newterm(3x)</A></STRONG>.
407
408 <STRONG>o</STRONG> All except <STRONG>start_color</STRONG> return <STRONG>ERR</STRONG> if <STRONG>start_color</STRONG> has not been
409 called, or itself returned <STRONG>ERR</STRONG>.
410
411 <STRONG>o</STRONG> <STRONG>start_color</STRONG> returns <STRONG>ERR</STRONG> if it cannot allocate memory for its color
412 pair table.
413
414 <STRONG>o</STRONG> <STRONG>init_color</STRONG> returns <STRONG>ERR</STRONG> if the terminal type does not support
415 assignable color values; that is, if the <STRONG>initialize_color</STRONG> (<STRONG>initc</STRONG>)
416 capability is absent from its description.
417
418 <STRONG>o</STRONG> <STRONG>init_color</STRONG> returns <STRONG>ERR</STRONG> if any of its <EM>r</EM>, <EM>g</EM>, <EM>b</EM> arguments is outside
419 the range 0-1000 inclusive.
420
421 <STRONG>o</STRONG> <STRONG>init_pair</STRONG>, <STRONG>init_color</STRONG>, <STRONG>init_extended_pair</STRONG>, <STRONG>init_extended_color</STRONG>,
422 <STRONG>color_content</STRONG>, <STRONG>pair_content</STRONG>, <STRONG>extended_color_content</STRONG>, and
423 <STRONG>extended_pair_content</STRONG> return <STRONG>ERR</STRONG> on attempts to use
424
425 <STRONG>o</STRONG> color identifiers outside the range 0-<STRONG>COLORS</STRONG>-1 inclusive, the
426 default colors extension notwithstanding, or
427
428 <STRONG>o</STRONG> color pair identifiers outside the range 0-<STRONG>COLOR_PAIRS</STRONG>-1
429 inclusive.
430
431
432 </PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE>
433 In <EM>ncurses</EM>, <STRONG>init_pair</STRONG> accepts negative foreground and background color
434 arguments to support its <STRONG><A HREF="default_colors.3x.html">use_default_colors(3x)</A></STRONG> extension, but only
435 after the latter function has been called.
436
437 The assumption that <STRONG>COLOR_BLACK</STRONG> is the terminal's default background
438 color can be overridden using <EM>ncurses</EM>'s <STRONG><A HREF="default_colors.3x.html">assume_default_colors(3x)</A></STRONG>
439 extension.
440
441 In <EM>ncurses</EM>, each pointer passed to <STRONG>color_content</STRONG> and <STRONG>pair_content</STRONG> can
442 be null, in which case the library ignores it, permitting the
443 application to disregard unnecessary information.
444
445 In <EM>ncurses</EM>, each screen has a color activation flag, color palette,
446 color pair table, and associated <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG> values;
447 <STRONG>start_color</STRONG> affects only the current screen. The SVr4 and X/Open
448 Curses interface was not really designed with this in mind; historical
449 implementations may use a single shared color palette.
450
451 Setting an implicit background color via a color pair affects only
452 character cells that a character write operation explicitly touches.
453 To change the background color used when parts of a window are blanked
454 by erasing or scrolling operations, see <STRONG><A HREF="curs_bkgd.3x.html">curs_bkgd(3x)</A></STRONG>.
455
456 Several caveats apply to IBM PC-compatible machines of the 80486 era
457 and earlier with CGA/EGA/VGA video.
458
459 <STRONG>o</STRONG> <STRONG>COLOR_YELLOW</STRONG> was frequently converted, in the analog domain, to a
460 shade of brown if the intensity bit was not set. To get yellow on
461 such devices, one would combine <STRONG>COLOR_YELLOW</STRONG> with the <STRONG>A_BOLD</STRONG>
462 attribute.
463
464 <STRONG>o</STRONG> The <STRONG>A_BLINK</STRONG> attribute should in theory make the background bright.
465 This often fails to work, and even VGA controllers for which it
466 mostly works, such as those from Paradise and compatibles, do the
467 wrong thing when you try to set a bright "yellow" background -- you
468 get a blinking yellow foreground instead.
469
470 <STRONG>o</STRONG> Color RGB values are not configurable on these devices (in text
471 mode).
472
473
474 </PRE><H2><a name="h2-EXTENSIONS">EXTENSIONS</a></H2><PRE>
475 The functions marked as extensions originated in <EM>ncurses</EM>, and are not
476 found in SVr4 <EM>curses</EM>, 4.4BSD <EM>curses</EM>, or any other previous <EM>curses</EM>
477 implementation.
478
479
480 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
481 Applications employing <EM>ncurses</EM> extensions should condition their use on
482 the visibility of the <STRONG>NCURSES_VERSION</STRONG> preprocessor macro.
483
484 X/Open Curses Issue 4 describes these functions. It specifies no error
485 conditions for them.
486
487 <EM>ncurses</EM> satisfies X/Open Curses's minimum maximums for <EM>COLORS</EM> and
488 <EM>COLOR</EM><STRONG>_</STRONG><EM>PAIRS</EM>.
489
490 X/Open Curses does not specify a limit for the number of colors and
491 color pairs which a terminal can support. However, in its use of <EM>short</EM>
492 for the parameters, it carries over SVr4's implementation detail for
493 the compiled <EM>terminfo</EM> database, which uses signed 16-bit numbers.
494 <EM>ncurses</EM> provides extended versions of the functions using <EM>short</EM>
495 parameters, allowing applications to use larger color and pair
496 identifiers.
497
498 SVr4 <EM>curses</EM> returns <EM>ERR</EM> from <EM>pair</EM><STRONG>_</STRONG><EM>content</EM> if its <EM>pair</EM> argument was not
499 initialized using <EM>init</EM><STRONG>_</STRONG><EM>pairs</EM>, and from <EM>color</EM><STRONG>_</STRONG><EM>content</EM> if the terminal
500 does not support changing colors. <EM>ncurses</EM> does neither.
501
502
503 </PRE><H2><a name="h2-HISTORY">HISTORY</a></H2><PRE>
504 SVr3.2 (1987) introduced color support to <EM>curses</EM> with all of the
505 symbols in the synopsis above except those marked as extensions. It
506 reserved color pair 0 as the terminal's initial, "uncolored" state, and
507 limited the number of possible color pairs to 64, because the color
508 pair datum was encoded in six bits of a <EM>chtype</EM>.
509
510 SVr4 made only internal changes, such as moving the storage of color
511 state from the <EM>SCREEN</EM> structure (pointed to by <EM>SP</EM>) to the <EM>TERMINAL</EM>
512 structure (pointed to by <EM>cur</EM><STRONG>_</STRONG><EM>term</EM>).
513
514 Other <EM>curses</EM> implementations impose different limits on the number of
515 colors and color pairs.
516
517 <STRONG>o</STRONG> <EM>PCCurses</EM> (1987-1990) provided for only 8 colors (and therefore
518 required at most 8x8 = 64 color pairs).
519
520 <STRONG>o</STRONG> <EM>PDCurses</EM> (1992-present) inherited the 8-color limitation from
521 <EM>PCCurses</EM>, but changed this to 256 in version 2.5 (2001), and
522 widened its <EM>chtype</EM> from 16 to 32 bits.
523
524 <STRONG>o</STRONG> X/Open Curses (1992-present) specified a new structure type,
525 <EM>cchar</EM><STRONG>_</STRONG><EM>t</EM>, to store the character code, attribute flags, and color
526 pair identifier, allowing an increased range of color pairs. It
527 specifies a <EM>short</EM> as storing identifiers for colors and color
528 pairs, limiting portable values to 15 bits; negative values are
529 invalid in System V.
530
531 <STRONG>o</STRONG> <EM>ncurses</EM> (1992-present), in its non-wide-character configuration,
532 uses 8 bits of <EM>chtype</EM> for the color pair identifier.
533
534 Version 5.3 (2002) offered a wide-character interface, but encoded
535 the color pair identifier with attributes in the character type.
536
537 Since version 6 (2015), <EM>ncurses</EM> uses a separate <EM>int</EM> for the color
538 pair identifier in a <EM>cchar</EM><STRONG>_</STRONG><EM>t</EM>, introducing extension functions to
539 manage the wider type. When a color pair value fits in 8 bits,
540 <EM>ncurses</EM> permits color pair data to be manipulated via the functions
541 taking <EM>chtype</EM> arguments, even when a <EM>curses</EM> window uses wide-
542 character cells.
543
544 <STRONG>o</STRONG> NetBSD <EM>curses</EM> used 6 bits for the color pair identifier from 2000
545 (when it first added color support) until 2004. At that point,
546 NetBSD widened the color pair identifier to use 9 bits. As of
547 2025, that size is unchanged. Like <EM>ncurses</EM> before version 6, the
548 NetBSD color pair datum is stored in the attributes field of
549 <EM>cchar</EM><STRONG>_</STRONG><EM>t</EM>, limiting the number of color pairs.
550
551
552 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
553 <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_attr.3x.html">curs_attr(3x)</A></STRONG>, <STRONG><A HREF="curs_initscr.3x.html">curs_initscr(3x)</A></STRONG>, <STRONG><A HREF="curs_variables.3x.html">curs_variables(3x)</A></STRONG>,
554 <STRONG><A HREF="default_colors.3x.html">default_colors(3x)</A></STRONG>
555
556 ncurses 6.6 2025-08-23 <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
557 </PRE>
558 <div class="nav">
559 <ul>
560 <li><a href="#h2-NAME">NAME</a></li>
561 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
562 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
563 <ul>
564 <li><a href="#h3-Overview">Overview</a></li>
565 <li><a href="#h3-Rendering">Rendering</a></li>
566 </ul>
567 </li>
568 <li><a href="#h2-CONSTANTS">CONSTANTS</a></li>
569 <li><a href="#h2-VARIABLES">VARIABLES</a>
570 <ul>
571 <li><a href="#h3-COLORS">COLORS</a></li>
572 <li><a href="#h3-COLOR_PAIRS">COLOR_PAIRS</a></li>
573 </ul>
574 </li>
575 <li><a href="#h2-FUNCTIONS">FUNCTIONS</a>
576 <ul>
577 <li><a href="#h3-start_color">start_color</a></li>
578 <li><a href="#h3-has_colors">has_colors</a></li>
579 <li><a href="#h3-can_change_color">can_change_color</a></li>
580 <li><a href="#h3-init_pair">init_pair</a></li>
581 <li><a href="#h3-init_extended_pair">init_extended_pair</a></li>
582 <li><a href="#h3-init_color">init_color</a></li>
583 <li><a href="#h3-init_extended_color">init_extended_color</a></li>
584 <li><a href="#h3-color_content">color_content</a></li>
585 <li><a href="#h3-extended_color_content">extended_color_content</a></li>
586 <li><a href="#h3-pair_content">pair_content</a></li>
587 <li><a href="#h3-extended_pair_content">extended_pair_content</a></li>
588 <li><a href="#h3-reset_color_pairs">reset_color_pairs</a></li>
589 <li><a href="#h3-COLOR_PAIR">COLOR_PAIR</a></li>
590 <li><a href="#h3-PAIR_NUMBER">PAIR_NUMBER</a></li>
591 </ul>
592 </li>
593 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
594 <li><a href="#h2-NOTES">NOTES</a></li>
595 <li><a href="#h2-EXTENSIONS">EXTENSIONS</a></li>
596 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
597 <li><a href="#h2-HISTORY">HISTORY</a></li>
598 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
599 </ul>
600 </div>
601 </BODY>
602 </HTML>