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>
48 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
49 <STRONG>start_color</STRONG>, <STRONG>init_pair</STRONG>, <STRONG>init_color</STRONG>, <STRONG>has_colors</STRONG>,
50 <STRONG>can_change_color</STRONG>, <STRONG>color_content</STRONG>, <STRONG>pair_content</STRONG>, <STRONG>COLOR_PAIR</STRONG>
51 - <STRONG>curses</STRONG> color manipulation routines
54 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
55 <STRONG>#</STRONG> <STRONG>include</STRONG> <STRONG><curses.h></STRONG>
57 <STRONG>int</STRONG> <STRONG>start_color(void);</STRONG>
58 <STRONG>int</STRONG> <STRONG>init_pair(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>f,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
59 <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>
60 <STRONG>bool</STRONG> <STRONG>has_colors(void);</STRONG>
61 <STRONG>bool</STRONG> <STRONG>can_change_color(void);</STRONG>
62 <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>
64 <STRONG>int</STRONG> <STRONG>pair_content(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>*f,</STRONG> <STRONG>short</STRONG> <STRONG>*b);</STRONG>
65 <STRONG>int</STRONG> <STRONG>COLOR_PAIR(int</STRONG> <STRONG>n);</STRONG>
68 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
70 </PRE><H3><a name="h3-Overview">Overview</a></H3><PRE>
71 <STRONG>curses</STRONG> supports color attributes on terminals with that
72 capability. To use these routines <STRONG>start_color</STRONG> must be
73 called, usually right after <STRONG>initscr</STRONG>. Colors are always
74 used in pairs (referred to as color-pairs). A color-pair
75 consists of a foreground color (for characters) and a
76 background color (for the blank field on which the charac-
77 ters are displayed). A programmer initializes a color-
78 pair with the routine <STRONG>init_pair</STRONG>. After it has been ini-
79 tialized, <STRONG>COLOR_PAIR</STRONG>(<EM>n</EM>), a macro defined in <STRONG><curses.h></STRONG>,
80 can be used as a new video attribute.
82 If a terminal is capable of redefining colors, the pro-
83 grammer can use the routine <STRONG>init_color</STRONG> to change the defi-
84 nition of a color. The routines <STRONG>has_colors</STRONG> and
85 <STRONG>can_change_color</STRONG> return <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>, depending on
86 whether the terminal has color capabilities and whether
87 the programmer can change the colors. The routine <STRONG>col-</STRONG>
88 <STRONG>or_content</STRONG> allows a programmer to extract the amounts of
89 red, green, and blue components in an initialized color.
90 The routine <STRONG>pair_content</STRONG> allows a programmer to find out
91 how a given color-pair is currently defined.
94 </PRE><H3><a name="h3-Color-Rendering">Color Rendering</a></H3><PRE>
95 The <STRONG>curses</STRONG> library combines these inputs to produce the
96 actual foreground and background colors shown on the
99 <STRONG>o</STRONG> per-character video attributes (e.g., via <STRONG>waddch</STRONG>),
101 <STRONG>o</STRONG> the window attribute (e.g., by <STRONG>wattrset</STRONG>), and
103 <STRONG>o</STRONG> the background character (e.g., <STRONG>wbkgdset</STRONG>).
105 Per-character and window attributes are usually set by a
106 parameter containing video attributes including a <STRONG>COL-</STRONG>
107 <STRONG>OR_PAIR</STRONG> value. Some functions such as <STRONG>wattr_set</STRONG> use a
108 separate parameter which is the color pair number.
110 The background character is a special case: it includes a
111 character value, just as if it were passed to <STRONG>waddch</STRONG>.
113 The <STRONG>curses</STRONG> library does the actual work of combining these
114 color pairs in an internal function called from <STRONG>waddch</STRONG>:
116 <STRONG>o</STRONG> If the parameter passed to <STRONG>waddch</STRONG> is <EM>blank</EM>, and it us-
117 es the special color pair 0,
119 <STRONG>o</STRONG> <STRONG>curses</STRONG> next checks the window attribute.
121 <STRONG>o</STRONG> If the window attribute does not use color pair 0,
122 <STRONG>curses</STRONG> uses the color pair from the window at-
125 <STRONG>o</STRONG> Otherwise, <STRONG>curses</STRONG> uses the background character.
127 <STRONG>o</STRONG> If the parameter passed to <STRONG>waddch</STRONG> is <EM>not</EM> <EM>blank</EM>, or it
128 does not use the special color pair 0, <STRONG>curses</STRONG> prefers
129 the color pair from the parameter, if it is nonzero.
130 Otherwise, it tries the window attribute next, and fi-
131 nally the background character.
133 Some <STRONG>curses</STRONG> functions such as <STRONG>wprintw</STRONG> call <STRONG>waddch</STRONG>. Those
134 do not combine its parameter with a color pair. Conse-
135 quently those calls use only the window attribute or the
136 background character.
139 </PRE><H3><a name="h3-Routine-Descriptions">Routine Descriptions</a></H3><PRE>
140 The <STRONG>start_color</STRONG> routine requires no arguments. It must be
141 called if the programmer wants to use colors, and before
142 any other color manipulation routine is called. It is
143 good practice to call this routine right after <STRONG>initscr</STRONG>.
144 <STRONG>start_color</STRONG> does this:
146 <STRONG>o</STRONG> It initializes two global variables, <STRONG>COLORS</STRONG> and <STRONG>COL-</STRONG>
147 <STRONG>OR_PAIRS</STRONG> (respectively defining the maximum number of
148 colors and color-pairs the terminal can support).
150 <STRONG>o</STRONG> It initializes the special color pair <STRONG>0</STRONG> to the default
151 foreground and background colors. No other color
152 pairs are initialized.
154 <STRONG>o</STRONG> It restores the colors on the terminal to the values
155 they had when the terminal was just turned on.
157 <STRONG>o</STRONG> If the terminal supports the <STRONG>initc</STRONG> (<STRONG>initialize_color</STRONG>)
158 capability, <STRONG>start_color</STRONG> initializes its internal table
159 representing the red, green and blue components of the
162 The components depend on whether the terminal uses CGA
163 (aka "ANSI") or HLS (i.e., the <STRONG>hls</STRONG> (<STRONG>hue_lightness_sat-</STRONG>
164 <STRONG>uration</STRONG>) capability is set). The table is initialized
165 first for eight basic colors (black, red, green, yel-
166 low, blue, magenta, cyan, and white), and after that
167 (if the terminal supports more than eight colors) the
168 components are initialized to <STRONG>1000</STRONG>.
170 <STRONG>start_color</STRONG> does not attempt to set the terminal's
171 color palette to match its built-in table. An appli-
172 cation may use <STRONG>init_color</STRONG> to alter the internal table
173 along with the terminal's color.
175 These limits apply to color values and color pairs. Val-
176 ues outside these limits are not legal, and may result in
179 <STRONG>o</STRONG> <STRONG>COLORS</STRONG> corresponds to the terminal database's <STRONG>max_col-</STRONG>
180 <STRONG>ors</STRONG> capability, which is typically a signed 16-bit in-
181 teger (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
183 <STRONG>o</STRONG> color values are expected to be in the range <STRONG>0</STRONG> to <STRONG>COL-</STRONG>
184 <STRONG>ORS-1</STRONG>, inclusive (including <STRONG>0</STRONG> and <STRONG>COLORS-1</STRONG>).
186 <STRONG>o</STRONG> a special color value <STRONG>-1</STRONG> is used in certain extended
187 functions to denote the <EM>default</EM> <EM>color</EM> (see <STRONG>use_de-</STRONG>
188 <STRONG>fault_colors</STRONG>).
190 <STRONG>o</STRONG> <STRONG>COLOR_PAIRS</STRONG> corresponds to the terminal database's
191 <STRONG>max_pairs</STRONG> capability, which is typically a signed
192 16-bit integer (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
194 <STRONG>o</STRONG> legal color pair values are in the range <STRONG>1</STRONG> to <STRONG>COL-</STRONG>
195 <STRONG>OR_PAIRS-1</STRONG>, inclusive.
197 <STRONG>o</STRONG> color pair <STRONG>0</STRONG> is special; it denotes "no color".
199 Color pair <STRONG>0</STRONG> is assumed to be white on black, but is
200 actually whatever the terminal implements before color
201 is initialized. It cannot be modified by the applica-
204 The <STRONG>init_pair</STRONG> routine changes the definition of a color-
205 pair. It takes three arguments: the number of the color-
206 pair to be changed, the foreground color number, and the
207 background color number. For portable applications:
209 <STRONG>o</STRONG> The first argument must be a legal color pair value.
210 If default colors are used (see <STRONG>use_default_colors</STRONG>)
211 the upper limit is adjusted to allow for extra pairs
212 which use a default color in foreground and/or back-
215 <STRONG>o</STRONG> The second and third arguments must be legal color
218 If the color-pair was previously initialized, the screen
219 is refreshed and all occurrences of that color-pair are
220 changed to the new definition.
222 As an extension, ncurses allows you to set color pair <STRONG>0</STRONG>
223 via the <STRONG>assume_default_colors</STRONG> routine, or to specify the
224 use of default colors (color number <STRONG>-1</STRONG>) if you first in-
225 voke the <STRONG>use_default_colors</STRONG> routine.
227 The <STRONG>init_color</STRONG> routine changes the definition of a color.
228 It takes four arguments: the number of the color to be
229 changed followed by three RGB values (for the amounts of
230 red, green, and blue components). The first argument must
231 be a legal color value; default colors are not allowed
232 here. (See the section <STRONG>Colors</STRONG> for the default color in-
233 dex.) Each of the last three arguments must be a value in
234 the range <STRONG>0</STRONG> through <STRONG>1000</STRONG>. When <STRONG>init_color</STRONG> is used, all
235 occurrences of that color on the screen immediately change
236 to the new definition.
238 The <STRONG>has_colors</STRONG> routine requires no arguments. It returns
239 <STRONG>TRUE</STRONG> if the terminal can manipulate colors; otherwise, it
240 returns <STRONG>FALSE</STRONG>. This routine facilitates writing terminal-
241 independent programs. For example, a programmer can use
242 it to decide whether to use color or some other video at-
245 The <STRONG>can_change_color</STRONG> routine requires no arguments. It
246 returns <STRONG>TRUE</STRONG> if the terminal supports colors and can
247 change their definitions; other, it returns <STRONG>FALSE</STRONG>. This
248 routine facilitates writing terminal-independent programs.
250 The <STRONG>color_content</STRONG> routine gives programmers a way to find
251 the intensity of the red, green, and blue (RGB) components
252 in a color. It requires four arguments: the color number,
253 and three addresses of <STRONG>short</STRONG>s for storing the information
254 about the amounts of red, green, and blue components in
255 the given color. The first argument must be a legal color
256 value, i.e., <STRONG>0</STRONG> through <STRONG>COLORS-1</STRONG>, inclusive. The values
257 that are stored at the addresses pointed to by the last
258 three arguments are in the range <STRONG>0</STRONG> (no component) through
259 <STRONG>1000</STRONG> (maximum amount of component), inclusive.
261 The <STRONG>pair_content</STRONG> routine allows programmers to find out
262 what colors a given color-pair consists of. It requires
263 three arguments: the color-pair number, and two addresses
264 of <STRONG>short</STRONG>s for storing the foreground and the background
265 color numbers. The first argument must be a legal color
266 value, i.e., in the range <STRONG>1</STRONG> through <STRONG>COLOR_PAIRS-1</STRONG>, inclu-
267 sive. The values that are stored at the addresses pointed
268 to by the second and third arguments are in the range <STRONG>0</STRONG>
269 through <STRONG>COLORS</STRONG>, inclusive.
272 </PRE><H3><a name="h3-Colors">Colors</a></H3><PRE>
273 In <STRONG><curses.h></STRONG> the following macros are defined. These are
274 the standard colors (ISO-6429). <STRONG>curses</STRONG> also assumes that
275 <STRONG>COLOR_BLACK</STRONG> is the default background color for all termi-
278 <STRONG>COLOR_BLACK</STRONG>
279 <STRONG>COLOR_RED</STRONG>
280 <STRONG>COLOR_GREEN</STRONG>
281 <STRONG>COLOR_YELLOW</STRONG>
282 <STRONG>COLOR_BLUE</STRONG>
283 <STRONG>COLOR_MAGENTA</STRONG>
284 <STRONG>COLOR_CYAN</STRONG>
285 <STRONG>COLOR_WHITE</STRONG>
288 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
289 The routines <STRONG>can_change_color()</STRONG> and <STRONG>has_colors()</STRONG> return
290 <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>.
292 All other routines return the integer <STRONG>ERR</STRONG> upon failure and
293 an <STRONG>OK</STRONG> (SVr4 specifies only "an integer value other than
294 <STRONG>ERR</STRONG>") upon successful completion.
296 X/Open defines no error conditions. This implementation
297 will return <STRONG>ERR</STRONG> on attempts to use color values outside
298 the range <STRONG>0</STRONG> to COLORS-1 (except for the default colors ex-
299 tension), or use color pairs outside the range <STRONG>0</STRONG> to <STRONG>COL-</STRONG>
300 <STRONG>OR_PAIRS-1</STRONG>. Color values used in <STRONG>init_color</STRONG> must be in
301 the range <STRONG>0</STRONG> to <STRONG>1000</STRONG>. An error is returned from all func-
302 tions if the terminal has not been initialized. An error
303 is returned from secondary functions such as <STRONG>init_pair</STRONG> if
304 <STRONG>start_color</STRONG> was not called.
306 <STRONG>init_color</STRONG>
307 returns an error if the terminal does not support
308 this feature, e.g., if the <EM>initialize</EM><STRONG>_</STRONG><EM>color</EM> capa-
309 bility is absent from the terminal description.
311 <STRONG>start_color</STRONG>
312 returns an error if the color table cannot be al-
316 </PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE>
317 In the <EM>ncurses</EM> implementation, there is a separate color
318 activation flag, color palette, color pairs table, and as-
319 sociated COLORS and COLOR_PAIRS counts for each screen;
320 the <STRONG>start_color</STRONG> function only affects the current screen.
321 The SVr4/XSI interface is not really designed with this in
322 mind, and historical implementations may use a single
323 shared color palette.
325 Note that setting an implicit background color via a color
326 pair affects only character cells that a character write
327 operation explicitly touches. To change the background
328 color used when parts of a window are blanked by erasing
329 or scrolling operations, see <STRONG><A HREF="curs_bkgd.3x.html">curs_bkgd(3x)</A></STRONG>.
331 Several caveats apply on 386 and 486 machines with VGA-
334 <STRONG>o</STRONG> COLOR_YELLOW is actually brown. To get yellow, use
335 COLOR_YELLOW combined with the <STRONG>A_BOLD</STRONG> attribute.
337 <STRONG>o</STRONG> The A_BLINK attribute should in theory cause the back-
338 ground to go bright. This often fails to work, and
339 even some cards for which it mostly works (such as the
340 Paradise and compatibles) do the wrong thing when you
341 try to set a bright "yellow" background (you get a
342 blinking yellow foreground instead).
344 <STRONG>o</STRONG> Color RGB values are not settable.
347 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
348 This implementation satisfies XSI Curses's minimum maxi-
349 mums for <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG>.
351 The <STRONG>init_pair</STRONG> routine accepts negative values of fore-
352 ground and background color to support the <STRONG>use_de-</STRONG>
353 <STRONG>fault_colors</STRONG> extension, but only if that routine has been
356 The assumption that <STRONG>COLOR_BLACK</STRONG> is the default background
357 color for all terminals can be modified using the <STRONG>as-</STRONG>
358 <STRONG>sume_default_colors</STRONG> extension.
360 This implementation checks the pointers, e.g., for the
361 values returned by <STRONG>color_content</STRONG> and <STRONG>pair_content</STRONG>, and
362 will treat those as optional parameters when null.
365 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
366 <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>
367 <STRONG><A HREF="curs_variables.3x.html">ables(3x)</A></STRONG>, <STRONG><A HREF="default_colors.3x.html">default_colors(3x)</A></STRONG>
371 <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
375 <li><a href="#h2-NAME">NAME</a></li>
376 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
377 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
379 <li><a href="#h3-Overview">Overview</a></li>
380 <li><a href="#h3-Color-Rendering">Color Rendering</a></li>
381 <li><a href="#h3-Routine-Descriptions">Routine Descriptions</a></li>
382 <li><a href="#h3-Colors">Colors</a></li>
385 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
386 <li><a href="#h2-NOTES">NOTES</a></li>
387 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
388 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>