2 ****************************************************************************
3 * Copyright (c) 1998-2010,2015 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************
29 * @Id: curs_color.3x,v 1.40 2015/12/05 20:09:42 tom Exp @
31 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
34 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
35 <meta name="generator" content="Manpage converted by man2html - see http://invisible-island.net/scripts/readme.html#others_scripts">
36 <TITLE>curs_color 3x</TITLE>
37 <link rev=made href="mailto:bug-ncurses@gnu.org">
38 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
41 <H1 class="no-header">curs_color 3x</H1>
43 <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG> <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
49 <H2><a name="h2-NAME">NAME</a></H2><PRE>
50 <STRONG>start_color</STRONG>, <STRONG>init_pair</STRONG>, <STRONG>init_color</STRONG>, <STRONG>has_colors</STRONG>,
51 <STRONG>can_change_color</STRONG>, <STRONG>color_content</STRONG>, <STRONG>pair_content</STRONG>, <STRONG>COLOR_PAIR</STRONG>
52 - <STRONG>curses</STRONG> color manipulation routines
56 <H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
57 <STRONG>#</STRONG> <STRONG>include</STRONG> <STRONG><curses.h></STRONG>
59 <STRONG>int</STRONG> <STRONG>start_color(void);</STRONG>
60 <STRONG>int</STRONG> <STRONG>init_pair(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>f,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
61 <STRONG>int</STRONG> <STRONG>init_color(short</STRONG> <STRONG>color,</STRONG> <STRONG>short</STRONG> <STRONG>r,</STRONG> <STRONG>short</STRONG> <STRONG>g,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
62 <STRONG>bool</STRONG> <STRONG>has_colors(void);</STRONG>
63 <STRONG>bool</STRONG> <STRONG>can_change_color(void);</STRONG>
64 <STRONG>int</STRONG> <STRONG>color_content(short</STRONG> <STRONG>color,</STRONG> <STRONG>short</STRONG> <STRONG>*r,</STRONG> <STRONG>short</STRONG> <STRONG>*g,</STRONG> <STRONG>short</STRONG>
66 <STRONG>int</STRONG> <STRONG>pair_content(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>*f,</STRONG> <STRONG>short</STRONG> <STRONG>*b);</STRONG>
67 <STRONG>int</STRONG> <STRONG>COLOR_PAIR(int</STRONG> <STRONG>n);</STRONG>
71 <H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
74 <H3><a name="h3-Overview">Overview</a></H3><PRE>
75 <STRONG>curses</STRONG> supports color attributes on terminals with that
76 capability. To use these routines <STRONG>start_color</STRONG> must be
77 called, usually right after <STRONG>initscr</STRONG>. Colors are always
78 used in pairs (referred to as color-pairs). A color-pair
79 consists of a foreground color (for characters) and a
80 background color (for the blank field on which the charac-
81 ters are displayed). A programmer initializes a color-
82 pair with the routine <STRONG>init_pair</STRONG>. After it has been ini-
83 tialized, <STRONG>COLOR_PAIR</STRONG>(<EM>n</EM>), a macro defined in <STRONG><curses.h></STRONG>,
84 can be used as a new video attribute.
86 If a terminal is capable of redefining colors, the pro-
87 grammer can use the routine <STRONG>init_color</STRONG> to change the defi-
88 nition of a color. The routines <STRONG>has_colors</STRONG> and
89 <STRONG>can_change_color</STRONG> return <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>, depending on
90 whether the terminal has color capabilities and whether
91 the programmer can change the colors. The routine <STRONG>col-</STRONG>
92 <STRONG>or_content</STRONG> allows a programmer to extract the amounts of
93 red, green, and blue components in an initialized color.
94 The routine <STRONG>pair_content</STRONG> allows a programmer to find out
95 how a given color-pair is currently defined.
99 <H3><a name="h3-Color-Rendering">Color Rendering</a></H3><PRE>
100 The <STRONG>curses</STRONG> library combines these inputs to produce the
101 actual foreground and background colors shown on the
104 <STRONG>o</STRONG> per-character video attributes (e.g., via <STRONG>waddch</STRONG>),
106 <STRONG>o</STRONG> the window attribute (e.g., by <STRONG>wattrset</STRONG>), and
108 <STRONG>o</STRONG> the background character (e.g., <STRONG>wbkgdset</STRONG>).
110 Per-character and window attributes are usually set by a
111 parameter containing video attributes including a <STRONG>COL-</STRONG>
112 <STRONG>OR_PAIR</STRONG> value. Some functions such as <STRONG>wattr_set</STRONG> use a
113 separate parameter which is the color pair number.
115 The background character is a special case: it includes a
116 character value, just as if it were passed to <STRONG>waddch</STRONG>.
118 The <STRONG>curses</STRONG> library does the actual work of combining these
119 color pairs in an internal function called from <STRONG>waddch</STRONG>:
121 <STRONG>o</STRONG> If the parameter passed to <STRONG>waddch</STRONG> is <EM>blank</EM>, and it us-
122 es the special color pair 0,
124 <STRONG>o</STRONG> <STRONG>curses</STRONG> next checks the window attribute.
126 <STRONG>o</STRONG> If the window attribute does not use color pair 0,
127 <STRONG>curses</STRONG> uses the color pair from the window at-
130 <STRONG>o</STRONG> Otherwise, <STRONG>curses</STRONG> uses the background character.
132 <STRONG>o</STRONG> If the parameter passed to <STRONG>waddch</STRONG> is <EM>not</EM> <EM>blank</EM>, or it
133 does not use the special color pair 0, <STRONG>curses</STRONG> prefers
134 the color pair from the parameter, if it is nonzero.
135 Otherwise, it tries the window attribute next, and fi-
136 nally the background character.
138 Some <STRONG>curses</STRONG> functions such as <STRONG>wprintw</STRONG> call <STRONG>waddch</STRONG>. Those
139 do not combine its parameter with a color pair. Conse-
140 quently those calls use only the window attribute or the
141 background character.
145 <H3><a name="h3-Routine-Descriptions">Routine Descriptions</a></H3><PRE>
146 The <STRONG>start_color</STRONG> routine requires no arguments. It must be
147 called if the programmer wants to use colors, and before
148 any other color manipulation routine is called. It is
149 good practice to call this routine right after <STRONG>initscr</STRONG>.
150 <STRONG>start_color</STRONG> does this:
152 <STRONG>o</STRONG> It initializes two global variables, <STRONG>COLORS</STRONG> and <STRONG>COL-</STRONG>
153 <STRONG>OR_PAIRS</STRONG> (respectively defining the maximum number of
154 colors and color-pairs the terminal can support).
156 <STRONG>o</STRONG> It initializes the special color pair <STRONG>0</STRONG> to the default
157 foreground and background colors. No other color
158 pairs are initialized.
160 <STRONG>o</STRONG> It restores the colors on the terminal to the values
161 they had when the terminal was just turned on.
163 <STRONG>o</STRONG> If the terminal supports the <STRONG>initc</STRONG> (<STRONG>initialize_color</STRONG>)
164 capability, <STRONG>start_color</STRONG> initializes its internal table
165 representing the red, green and blue components of the
168 The components depend on whether the terminal uses CGA
169 (aka "ANSI") or HLS (i.e., the <STRONG>hls</STRONG> (<STRONG>hue_lightness_sat-</STRONG>
170 <STRONG>uration</STRONG>) capability is set). The table is initialized
171 first for eight basic colors (black, red, green, yel-
172 low, blue, magenta, cyan, and white), and after that
173 (if the terminal supports more than eight colors) the
174 components are initialized to <STRONG>1000</STRONG>.
176 <STRONG>start_color</STRONG> does not attempt to set the terminal's
177 color palette to match its built-in table. An appli-
178 cation may use <STRONG>init_color</STRONG> to alter the internal table
179 along with the terminal's color.
181 These limits apply to color values and color pairs. Val-
182 ues outside these limits are not legal, and may result in
185 <STRONG>o</STRONG> <STRONG>COLORS</STRONG> corresponds to the terminal database's <STRONG>max_col-</STRONG>
186 <STRONG>ors</STRONG> capability, which is typically a signed 16-bit in-
187 teger (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
189 <STRONG>o</STRONG> color values are expected to be in the range <STRONG>0</STRONG> to <STRONG>COL-</STRONG>
190 <STRONG>ORS-1</STRONG>, inclusive (including <STRONG>0</STRONG> and <STRONG>COLORS-1</STRONG>).
192 <STRONG>o</STRONG> a special color value <STRONG>-1</STRONG> is used in certain extended
193 functions to denote the <EM>default</EM> <EM>color</EM> (see <STRONG>use_de-</STRONG>
194 <STRONG>fault_colors</STRONG>).
196 <STRONG>o</STRONG> <STRONG>COLOR_PAIRS</STRONG> corresponds to the terminal database's
197 <STRONG>max_pairs</STRONG> capability, which is typically a signed
198 16-bit integer (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
200 <STRONG>o</STRONG> legal color pair values are in the range <STRONG>1</STRONG> to <STRONG>COL-</STRONG>
201 <STRONG>OR_PAIRS-1</STRONG>, inclusive.
203 <STRONG>o</STRONG> color pair <STRONG>0</STRONG> is special; it denotes "no color".
205 Color pair <STRONG>0</STRONG> is assumed to be white on black, but is
206 actually whatever the terminal implements before color
207 is initialized. It cannot be modified by the applica-
210 The <STRONG>init_pair</STRONG> routine changes the definition of a color-
211 pair. It takes three arguments: the number of the color-
212 pair to be changed, the foreground color number, and the
213 background color number. For portable applications:
215 <STRONG>o</STRONG> The first argument must be a legal color pair value.
216 If default colors are used (see <STRONG>use_default_colors</STRONG>)
217 the upper limit is adjusted to allow for extra pairs
218 which use a default color in foreground and/or back-
221 <STRONG>o</STRONG> The second and third arguments must be legal color
224 If the color-pair was previously initialized, the screen
225 is refreshed and all occurrences of that color-pair are
226 changed to the new definition.
228 As an extension, ncurses allows you to set color pair <STRONG>0</STRONG>
229 via the <STRONG>assume_default_colors</STRONG> routine, or to specify the
230 use of default colors (color number <STRONG>-1</STRONG>) if you first in-
231 voke the <STRONG>use_default_colors</STRONG> routine.
233 The <STRONG>init_color</STRONG> routine changes the definition of a color.
234 It takes four arguments: the number of the color to be
235 changed followed by three RGB values (for the amounts of
236 red, green, and blue components). The first argument must
237 be a legal color value; default colors are not allowed
238 here. (See the section <STRONG>Colors</STRONG> for the default color in-
239 dex.) Each of the last three arguments must be a value in
240 the range <STRONG>0</STRONG> through <STRONG>1000</STRONG>. When <STRONG>init_color</STRONG> is used, all
241 occurrences of that color on the screen immediately change
242 to the new definition.
244 The <STRONG>has_colors</STRONG> routine requires no arguments. It returns
245 <STRONG>TRUE</STRONG> if the terminal can manipulate colors; otherwise, it
246 returns <STRONG>FALSE</STRONG>. This routine facilitates writing terminal-
247 independent programs. For example, a programmer can use
248 it to decide whether to use color or some other video at-
251 The <STRONG>can_change_color</STRONG> routine requires no arguments. It
252 returns <STRONG>TRUE</STRONG> if the terminal supports colors and can
253 change their definitions; other, it returns <STRONG>FALSE</STRONG>. This
254 routine facilitates writing terminal-independent programs.
256 The <STRONG>color_content</STRONG> routine gives programmers a way to find
257 the intensity of the red, green, and blue (RGB) components
258 in a color. It requires four arguments: the color number,
259 and three addresses of <STRONG>short</STRONG>s for storing the information
260 about the amounts of red, green, and blue components in
261 the given color. The first argument must be a legal color
262 value, i.e., <STRONG>0</STRONG> through <STRONG>COLORS-1</STRONG>, inclusive. The values
263 that are stored at the addresses pointed to by the last
264 three arguments are in the range <STRONG>0</STRONG> (no component) through
265 <STRONG>1000</STRONG> (maximum amount of component), inclusive.
267 The <STRONG>pair_content</STRONG> routine allows programmers to find out
268 what colors a given color-pair consists of. It requires
269 three arguments: the color-pair number, and two addresses
270 of <STRONG>short</STRONG>s for storing the foreground and the background
271 color numbers. The first argument must be a legal color
272 value, i.e., in the range <STRONG>1</STRONG> through <STRONG>COLOR_PAIRS-1</STRONG>, inclu-
273 sive. The values that are stored at the addresses pointed
274 to by the second and third arguments are in the range <STRONG>0</STRONG>
275 through <STRONG>COLORS</STRONG>, inclusive.
279 <H3><a name="h3-Colors">Colors</a></H3><PRE>
280 In <STRONG><curses.h></STRONG> the following macros are defined. These are
281 the standard colors (ISO-6429). <STRONG>curses</STRONG> also assumes that
282 <STRONG>COLOR_BLACK</STRONG> is the default background color for all termi-
285 <STRONG>COLOR_BLACK</STRONG>
286 <STRONG>COLOR_RED</STRONG>
287 <STRONG>COLOR_GREEN</STRONG>
288 <STRONG>COLOR_YELLOW</STRONG>
289 <STRONG>COLOR_BLUE</STRONG>
290 <STRONG>COLOR_MAGENTA</STRONG>
291 <STRONG>COLOR_CYAN</STRONG>
292 <STRONG>COLOR_WHITE</STRONG>
296 <H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
297 The routines <STRONG>can_change_color()</STRONG> and <STRONG>has_colors()</STRONG> return
298 <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>.
300 All other routines return the integer <STRONG>ERR</STRONG> upon failure and
301 an <STRONG>OK</STRONG> (SVr4 specifies only "an integer value other than
302 <STRONG>ERR</STRONG>") upon successful completion.
304 X/Open defines no error conditions. This implementation
305 will return <STRONG>ERR</STRONG> on attempts to use color values outside
306 the range <STRONG>0</STRONG> to COLORS-1 (except for the default colors ex-
307 tension), or use color pairs outside the range <STRONG>0</STRONG> to <STRONG>COL-</STRONG>
308 <STRONG>OR_PAIRS-1</STRONG>. Color values used in <STRONG>init_color</STRONG> must be in
309 the range <STRONG>0</STRONG> to <STRONG>1000</STRONG>. An error is returned from all func-
310 tions if the terminal has not been initialized. An error
311 is returned from secondary functions such as <STRONG>init_pair</STRONG> if
312 <STRONG>start_color</STRONG> was not called.
314 <STRONG>init_color</STRONG>
315 returns an error if the terminal does not support
316 this feature, e.g., if the <EM>initialize</EM><STRONG>_</STRONG><EM>color</EM> capa-
317 bility is absent from the terminal description.
319 <STRONG>start_color</STRONG>
320 returns an error if the color table cannot be al-
325 <H2><a name="h2-NOTES">NOTES</a></H2><PRE>
326 In the <EM>ncurses</EM> implementation, there is a separate color
327 activation flag, color palette, color pairs table, and as-
328 sociated COLORS and COLOR_PAIRS counts for each screen;
329 the <STRONG>start_color</STRONG> function only affects the current screen.
330 The SVr4/XSI interface is not really designed with this in
331 mind, and historical implementations may use a single
332 shared color palette.
334 Note that setting an implicit background color via a color
335 pair affects only character cells that a character write
336 operation explicitly touches. To change the background
337 color used when parts of a window are blanked by erasing
338 or scrolling operations, see <STRONG><A HREF="curs_bkgd.3x.html">curs_bkgd(3x)</A></STRONG>.
340 Several caveats apply on 386 and 486 machines with VGA-
343 <STRONG>o</STRONG> COLOR_YELLOW is actually brown. To get yellow, use
344 COLOR_YELLOW combined with the <STRONG>A_BOLD</STRONG> attribute.
346 <STRONG>o</STRONG> The A_BLINK attribute should in theory cause the back-
347 ground to go bright. This often fails to work, and
348 even some cards for which it mostly works (such as the
349 Paradise and compatibles) do the wrong thing when you
350 try to set a bright "yellow" background (you get a
351 blinking yellow foreground instead).
353 <STRONG>o</STRONG> Color RGB values are not settable.
357 <H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
358 This implementation satisfies XSI Curses's minimum maxi-
359 mums for <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG>.
361 The <STRONG>init_pair</STRONG> routine accepts negative values of fore-
362 ground and background color to support the <STRONG>use_de-</STRONG>
363 <STRONG>fault_colors</STRONG> extension, but only if that routine has been
366 The assumption that <STRONG>COLOR_BLACK</STRONG> is the default background
367 color for all terminals can be modified using the <STRONG>as-</STRONG>
368 <STRONG>sume_default_colors</STRONG> extension.
370 This implementation checks the pointers, e.g., for the
371 values returned by <STRONG>color_content</STRONG> and <STRONG>pair_content</STRONG>, and
372 will treat those as optional parameters when null.
376 <H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
377 <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_initscr.3x.html">curs_initscr(3x)</A></STRONG>, <STRONG><A HREF="curs_attr.3x.html">curs_attr(3x)</A></STRONG>, <STRONG>curs_vari-</STRONG>
378 <STRONG><A HREF="curs_variables.3x.html">ables(3x)</A></STRONG>, <STRONG><A HREF="default_colors.3x.html">default_colors(3x)</A></STRONG>
382 <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
386 <li><a href="#h2-NAME">NAME</a></li>
387 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
388 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
390 <li><a href="#h3-Overview">Overview</a></li>
391 <li><a href="#h3-Color-Rendering">Color Rendering</a></li>
392 <li><a href="#h3-Routine-Descriptions">Routine Descriptions</a></li>
393 <li><a href="#h3-Colors">Colors</a></li>
396 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
397 <li><a href="#h2-NOTES">NOTES</a></li>
398 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
399 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>