1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
3 ****************************************************************************
4 * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. *
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: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
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. *
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 *
29 ****************************************************************************
30 * @Id: curs_color.3x,v 1.19 2002/02/16 22:38:32 tom Exp @
34 <TITLE>curs_color 3x</TITLE>
35 <link rev=made href="mailto:bug-ncurses@gnu.org">
36 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
39 <H1>curs_color 3x</H1>
42 <!-- Manpage converted by man2html 3.0.1 -->
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>
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>SYNOPSIS</H2><PRE>
57 <STRONG>#</STRONG> <STRONG>include</STRONG> <STRONG><curses.h></STRONG>
58 <STRONG>int</STRONG> <STRONG>start_color(void);</STRONG>
59 <STRONG>int</STRONG> <STRONG>init_pair(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>f,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
60 <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>
61 <STRONG>bool</STRONG> <STRONG>has_colors(void);</STRONG>
62 <STRONG>bool</STRONG> <STRONG>can_change_color(void);</STRONG>
63 <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>
65 <STRONG>int</STRONG> <STRONG>pair_content(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>*f,</STRONG> <STRONG>short</STRONG> <STRONG>*b);</STRONG>
69 <H2>DESCRIPTION</H2><PRE>
70 <STRONG>Overview</STRONG>
71 <STRONG>curses</STRONG> support 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
88 <STRONG>color_content</STRONG> allows a programmer to extract the amounts
89 of red, green, and blue components in an initialized
90 color. The routine <STRONG>pair_content</STRONG> allows a programmer to
91 find out how a given color-pair is currently defined.
93 <STRONG>Routine</STRONG> <STRONG>Descriptions</STRONG>
94 The <STRONG>start_color</STRONG> routine requires no arguments. It must be
95 called if the programmer wants to use colors, and before
96 any other color manipulation routine is called. It is
97 good practice to call this routine right after <STRONG>initscr</STRONG>.
98 <STRONG>start_color</STRONG> initializes eight basic colors (black, red,
99 green, yellow, blue, magenta, cyan, and white), and two
100 global variables, <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG> (respectively
101 defining the maximum number of colors and color-pairs the
102 terminal can support). It also restores the colors on the
103 terminal to the values they had when the terminal was just
106 The <STRONG>init_pair</STRONG> routine changes the definition of a color-
107 pair. It takes three arguments: the number of the color-
108 pair to be changed, the foreground color number, and the
109 background color number. For portable applications:
111 - The value of the first argument must be between <STRONG>1</STRONG> and
112 <STRONG>COLOR_PAIRS-1</STRONG>.
114 - The value of the second and third arguments must be
115 between 0 and <STRONG>COLORS</STRONG> (the 0 color pair is wired to
116 white on black and cannot be changed).
118 If the color-pair was previously initialized, the screen
119 is refreshed and all occurrences of that color-pair are
120 changed to the new definition.
122 As an extension, ncurses allows you to set color pair 0
123 via the <STRONG>assume_default_colors</STRONG> routine, or to specify the
124 use of default colors (color number <STRONG>-1</STRONG>) if you first
125 invoke the <STRONG>use_default_colors</STRONG> routine.
127 The <STRONG>init_color</STRONG> routine changes the definition of a color.
128 It takes four arguments: the number of the color to be
129 changed followed by three RGB values (for the amounts of
130 red, green, and blue components). The value of the first
131 argument must be between <STRONG>0</STRONG> and <STRONG>COLORS</STRONG>. (See the section
132 <STRONG>Colors</STRONG> for the default color index.) Each of the last
133 three arguments must be a value between 0 and 1000. When
134 <STRONG>init_color</STRONG> is used, all occurrences of that color on the
135 screen immediately change to the new definition.
137 The <STRONG>has_colors</STRONG> routine requires no arguments. It returns
138 <STRONG>TRUE</STRONG> if the terminal can manipulate colors; otherwise, it
139 returns <STRONG>FALSE</STRONG>. This routine facilitates writing terminal-
140 independent programs. For example, a programmer can use
141 it to decide whether to use color or some other video
144 The <STRONG>can_change_color</STRONG> routine requires no arguments. It
145 returns <STRONG>TRUE</STRONG> if the terminal supports colors and can
146 change their definitions; other, it returns <STRONG>FALSE</STRONG>. This
147 routine facilitates writing terminal-independent programs.
149 The <STRONG>color_content</STRONG> routine gives programmers a way to find
150 the intensity of the red, green, and blue (RGB) components
151 in a color. It requires four arguments: the color number,
152 and three addresses of <STRONG>short</STRONG>s for storing the information
153 about the amounts of red, green, and blue components in
154 the given color. The value of the first argument must be
155 between 0 and <STRONG>COLORS</STRONG>. The values that are stored at the
156 addresses pointed to by the last three arguments are
157 between 0 (no component) and 1000 (maximum amount of com-
160 The <STRONG>pair_content</STRONG> routine allows programmers to find out
161 what colors a given color-pair consists of. It requires
162 three arguments: the color-pair number, and two addresses
163 of <STRONG>short</STRONG>s for storing the foreground and the background
164 color numbers. The value of the first argument must be
165 between 1 and <STRONG>COLOR_PAIRS-1</STRONG>. The values that are stored
166 at the addresses pointed to by the second and third argu-
167 ments are between 0 and <STRONG>COLORS</STRONG>.
169 <STRONG>Colors</STRONG>
170 In <STRONG><curses.h></STRONG> the following macros are defined. These are
171 the default colors. <STRONG>curses</STRONG> also assumes that <STRONG>COLOR_BLACK</STRONG>
172 is the default background color for all terminals.
174 <STRONG>COLOR_BLACK</STRONG>
175 <STRONG>COLOR_RED</STRONG>
176 <STRONG>COLOR_GREEN</STRONG>
177 <STRONG>COLOR_YELLOW</STRONG>
178 <STRONG>COLOR_BLUE</STRONG>
179 <STRONG>COLOR_MAGENTA</STRONG>
180 <STRONG>COLOR_CYAN</STRONG>
181 <STRONG>COLOR_WHITE</STRONG>
185 <H2>RETURN VALUE</H2><PRE>
186 The routines <STRONG>can_change_color()</STRONG> and <STRONG>has_colors()</STRONG> return
187 <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>.
189 All other routines return the integer <STRONG>ERR</STRONG> upon failure and
190 an <STRONG>OK</STRONG> (SVr4 specifies only "an integer value other than
191 <STRONG>ERR</STRONG>") upon successful completion.
196 In the <EM>ncurses</EM> implementation, there is a separate color
197 activation flag, color palette, color pairs table, and
198 associated COLORS and COLOR_PAIRS counts for each screen;
199 the <STRONG>start_color</STRONG> function only affects the current screen.
200 The SVr4/XSI interface is not really designed with this in
201 mind, and historical implementations may use a single
202 shared color palette.
204 Note that setting an implicit background color via a color
205 pair affects only character cells that a character write
206 operation explicitly touches. To change the background
207 color used when parts of a window are blanked by erasing
208 or scrolling operations, see <STRONG><A HREF="curs_bkgd.3x.html">curs_bkgd(3x)</A></STRONG>.
210 Several caveats apply on 386 and 486 machines with VGA-
213 - COLOR_YELLOW is actually brown. To get yellow, use
214 COLOR_YELLOW combined with the <STRONG>A_BOLD</STRONG> attribute.
216 - The A_BLINK attribute should in theory cause the
217 background to go bright. This often fails to work,
218 and even some cards for which it mostly works (such
219 as the Paradise and compatibles) do the wrong thing
220 when you try to set a bright "yellow" background (you
221 get a blinking yellow foreground instead).
223 - Color RGB values are not settable.
227 <H2>PORTABILITY</H2><PRE>
228 This implementation satisfies XSI Curses's minimum maxi-
229 mums for <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG>.
231 The <STRONG>init_pair</STRONG> routine accepts negative values of fore-
232 ground and background color to support the
233 <STRONG>use_default_colors</STRONG> extension, but only if that routine has
236 The assumption that <STRONG>COLOR_BLACK</STRONG> is the default background
237 color for all terminals can be modified using the
238 <STRONG>assume_default_colors</STRONG> extension,
243 <H2>SEE ALSO</H2><PRE>
244 <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>default_col-</STRONG>
245 <STRONG><A HREF="default_colors.3x.html">ors(3x)</A></STRONG>
249 <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
253 Man(1) output converted with
254 <a href="http://www.oac.uci.edu/indiv/ehood/man2html.html">man2html</a>