]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_color.3x
ncurses 6.0 - patch 20160319
[ncurses.git] / man / curs_color.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2010,2015 Free Software Foundation, Inc.              *
3 .\"                                                                          *
4 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
5 .\" copy of this software and associated documentation files (the            *
6 .\" "Software"), to deal in the Software without restriction, including      *
7 .\" without limitation the rights to use, copy, modify, merge, publish,      *
8 .\" distribute, distribute with modifications, sublicense, and/or sell       *
9 .\" copies of the Software, and to permit persons to whom the Software is    *
10 .\" furnished to do so, subject to the following conditions:                 *
11 .\"                                                                          *
12 .\" The above copyright notice and this permission notice shall be included  *
13 .\" in all copies or substantial portions of the Software.                   *
14 .\"                                                                          *
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 .\"                                                                          *
23 .\" Except as contained in this notice, the name(s) of the above copyright   *
24 .\" holders shall not be used in advertising or otherwise to promote the     *
25 .\" sale, use or other dealings in this Software without prior written       *
26 .\" authorization.                                                           *
27 .\"***************************************************************************
28 .\"
29 .\" $Id: curs_color.3x,v 1.40 2015/12/05 20:09:42 tom Exp $
30 .TH curs_color 3X ""
31 .ie \n(.g .ds `` \(lq
32 .el       .ds `` ``
33 .ie \n(.g .ds '' \(rq
34 .el       .ds '' ''
35 .de bP
36 .IP \(bu 4
37 ..
38 .ds n 5
39 .na
40 .hy 0
41 .SH NAME
42 \fBstart_color\fR,
43 \fBinit_pair\fR,
44 \fBinit_color\fR,
45 \fBhas_colors\fR,
46 \fBcan_change_color\fR,
47 \fBcolor_content\fR,
48 \fBpair_content\fR,
49 \fBCOLOR_PAIR\fR \- \fBcurses\fR color manipulation routines
50 .ad
51 .hy
52 .SH SYNOPSIS
53 \fB# include <curses.h>\fR
54 .sp
55 \fBint start_color(void);\fR
56 .br
57 \fBint init_pair(short pair, short f, short b);\fR
58 .br
59 \fBint init_color(short color, short r, short g, short b);\fR
60 .br
61 \fBbool has_colors(void);\fR
62 .br
63 \fBbool can_change_color(void);\fR
64 .br
65 \fBint color_content(short color, short *r, short *g, short *b);\fR
66 .br
67 \fBint pair_content(short pair, short *f, short *b);\fR
68 .br
69 \fBint COLOR_PAIR(int n);\fR
70 .br
71 .SH DESCRIPTION
72 .SS Overview
73 \fBcurses\fR supports color attributes on terminals with that capability.
74 To use these routines \fBstart_color\fR must be called, usually right after
75 \fBinitscr\fR.
76 Colors are always used in pairs (referred to as color-pairs).
77 A color-pair consists of a foreground color (for characters) and a background
78 color (for the blank field on which the characters are displayed).
79 A programmer initializes a color-pair with the routine \fBinit_pair\fR.
80 After it has been initialized, \fBCOLOR_PAIR\fR(\fIn\fR), a macro defined in
81 \fB<curses.h>\fR, can be used as a new video attribute.
82 .PP
83 If a terminal is capable of redefining colors, the programmer can use the
84 routine \fBinit_color\fR to change the definition of a color.
85 The routines \fBhas_colors\fR and \fBcan_change_color\fR
86 return \fBTRUE\fR or \fBFALSE\fR,
87 depending on whether the terminal has color capabilities and whether the
88 programmer can change the colors.
89 The routine \fBcolor_content\fR allows a
90 programmer to extract the amounts of red, green, and blue components in an
91 initialized color.
92 The routine \fBpair_content\fR allows a programmer to find
93 out how a given color-pair is currently defined.
94 .SS Color Rendering
95 The \fBcurses\fP library combines these inputs to produce the
96 actual foreground and background colors shown on the screen:
97 .bP
98 per-character video attributes (e.g., via \fBwaddch\fP),
99 .bP
100 the window attribute (e.g., by \fBwattrset\fP), and
101 .bP
102 the background character (e.g., \fBwbkgdset\fP).
103 .PP
104 Per-character and window attributes are usually set by a parameter containing
105 video attributes including a \fBCOLOR_PAIR\fP value.
106 Some functions such as \fBwattr_set\fP use a separate parameter which
107 is the color pair number.
108 .PP
109 The background character is a special case: it includes a character value,
110 just as if it were passed to \fBwaddch\fP.
111 .PP
112 The \fBcurses\fP library does the actual work of combining these color
113 pairs in an internal function called from \fBwaddch\fP:
114 .bP
115 If the parameter passed to \fBwaddch\fP is \fIblank\fP,
116 and it uses the special color pair 0,
117 .RS
118 .bP
119 \fBcurses\fP next checks the window attribute.
120 .bP
121 If the window attribute does not use color pair 0,
122 \fBcurses\fP uses the color pair from the window attribute.
123 .bP
124 Otherwise, \fBcurses\fP uses the background character.
125 .RE
126 .bP
127 If the parameter passed to \fBwaddch\fP is \fInot blank\fP,
128 or it does not use the special color pair 0,
129 \fBcurses\fP prefers the color pair from the parameter,
130 if it is nonzero.
131 Otherwise, it tries the window attribute next, and finally the
132 background character.
133 .PP
134 Some \fBcurses\fP functions such as \fBwprintw\fP call \fBwaddch\fP.
135 Those do not combine its parameter with a color pair.
136 Consequently those calls use only the window attribute or
137 the background character.
138 .SS Routine Descriptions
139 The \fBstart_color\fR routine requires no arguments.
140 It must be called if the programmer wants to use colors, and before any other
141 color manipulation routine is called.
142 It is good practice to call this routine right after \fBinitscr\fR.
143 \fBstart_color\fR does this:
144 .bP
145 It initializes two global variables, \fBCOLORS\fR and
146 \fBCOLOR_PAIRS\fR (respectively defining the maximum number of colors
147 and color-pairs the terminal can support).
148 .bP
149 It initializes the special color pair \fB0\fP to the default foreground
150 and background colors.
151 No other color pairs are initialized.
152 .bP
153 It restores the colors on the terminal to the values
154 they had when the terminal was just turned on.
155 .bP
156 If the terminal supports the \fBinitc\fP (\fBinitialize_color\fP) capability,
157 \fBstart_color\fP
158 initializes its internal table representing the
159 red, green and blue components of the color palette.
160 .IP
161 The components depend on whether the terminal uses
162 CGA (aka "ANSI") or
163 HLS (i.e., the \fBhls\fP (\fBhue_lightness_saturation\fP) capability is set).
164 The table is initialized first for eight basic colors
165 (black, red, green, yellow, blue, magenta, cyan, and white),
166 and after that (if the terminal supports more than eight colors)
167 the components are initialized to \fB1000\fP.
168 .IP
169 \fBstart_color\fP does not attempt to set the terminal's color palette
170 to match its built-in table.
171 An application may use \fBinit_color\fP to alter the internal table
172 along with the terminal's color.
173 .PP
174 These limits apply to color values and color pairs.
175 Values outside these limits are not legal, and may result in a runtime error:
176 .bP
177 \fBCOLORS\fP corresponds to the terminal database's \fBmax_colors\fP capability,
178 which is typically a signed 16-bit integer (see \fBterminfo\fR(\*n)).
179 .bP
180 color values are expected to be in the range \fB0\fP to \fBCOLORS\-1\fP,
181 inclusive (including \fB0\fP and \fBCOLORS\-1\fP).
182 .bP
183 a special color value \fB\-1\fP is used in certain extended functions
184 to denote the \fIdefault color\fP (see \fBuse_default_colors\fP).
185 .bP
186 \fBCOLOR_PAIRS\fP corresponds to the terminal database's \fBmax_pairs\fP capability,
187 which is typically a signed 16-bit integer (see \fBterminfo\fR(\*n)).
188 .bP
189 legal color pair values are in the range \fB1\fP to \fBCOLOR_PAIRS\-1\fP,
190 inclusive.
191 .bP
192 color pair \fB0\fP is special; it denotes \*(``no color\*(''.
193 .IP
194 Color pair \fB0\fP is assumed to be white on black,
195 but is actually whatever the terminal implements before color is initialized.
196 It cannot be modified by the application.
197 .PP
198 The \fBinit_pair\fR routine changes the definition of a color-pair.
199 It takes three arguments: the number of the color-pair to be changed, the foreground
200 color number, and the background color number.
201 For portable applications:
202 .bP
203 The first argument must be a legal color pair value.
204 If default colors are used (see \fBuse_default_colors\fP)
205 the upper limit is adjusted to allow for extra pairs which use
206 a default color in foreground and/or background.
207 .bP
208 The second and third arguments must be legal color values.
209 .PP
210 If the color-pair was previously initialized,
211 the screen is refreshed and all occurrences of that color-pair
212 are changed to the new definition.
213 .PP
214 As an extension, ncurses allows you to set color pair \fB0\fP via
215 the \fBassume_default_colors\fR routine, or to specify the use of
216 default colors (color number \fB\-1\fR) if you first invoke the
217 \fBuse_default_colors\fR routine.
218 .PP
219 The \fBinit_color\fR routine changes the definition of a color.
220 It takes four arguments: the number of the color to be changed followed by three RGB values
221 (for the amounts of red, green, and blue components).
222 The first argument must be a legal color value;
223 default colors are not allowed here.
224 (See the section \fBColors\fR for the default color index.)
225 Each of the last three arguments
226 must be a value in the range \fB0\fP through \fB1000\fP.
227 When \fBinit_color\fR is used, all
228 occurrences of that color on the screen immediately change to the new
229 definition.
230 .PP
231 The \fBhas_colors\fR routine requires no arguments.
232 It returns \fBTRUE\fR if
233 the terminal can manipulate colors; otherwise, it returns \fBFALSE\fR.
234 This routine facilitates writing terminal-independent programs.
235 For example, a programmer can use it to decide
236 whether to use color or some other video attribute.
237 .PP
238 The \fBcan_change_color\fR routine requires no arguments.
239 It returns \fBTRUE\fR if the terminal supports colors
240 and can change their definitions;
241 other, it returns \fBFALSE\fR.
242 This routine facilitates writing terminal-independent programs.
243 .PP
244 The \fBcolor_content\fR routine gives programmers a way to find the intensity
245 of the red, green, and blue (RGB) components in a color.
246 It requires four arguments: the color number, and three addresses
247 of \fBshort\fRs for storing
248 the information about the amounts of red, green, and blue components in the
249 given color.
250 The first argument must be a legal color value, i.e.,
251 \fB0\fP through \fBCOLORS\-1\fP, inclusive.
252 The values that are stored at the addresses pointed to by the
253 last three arguments are in the range
254 \fB0\fP (no component) through \fB1000\fP (maximum amount of component), inclusive.
255 .PP
256 The \fBpair_content\fR routine allows programmers to find out what colors a
257 given color-pair consists of.
258 It requires three arguments: the color-pair
259 number, and two addresses of \fBshort\fRs for storing the foreground and the
260 background color numbers.
261 The first argument must be a legal color value,
262 i.e., in the range \fB1\fP through \fBCOLOR_PAIRS\-1\fR, inclusive.
263 The values that are stored at the addresses pointed
264 to by the second and third arguments are in the
265 range \fB0\fP through \fBCOLORS\fR, inclusive.
266 .SS Colors
267 In \fB<curses.h>\fR the following macros are defined.
268 These are the standard colors (ISO-6429).
269 \fBcurses\fR also assumes that \fBCOLOR_BLACK\fR is the default
270 background color for all terminals.
271 .PP
272 .nf
273       \fBCOLOR_BLACK\fR
274       \fBCOLOR_RED\fR
275       \fBCOLOR_GREEN\fR
276       \fBCOLOR_YELLOW\fR
277       \fBCOLOR_BLUE\fR
278       \fBCOLOR_MAGENTA\fR
279       \fBCOLOR_CYAN\fR
280       \fBCOLOR_WHITE\fR
281 .fi
282 .SH RETURN VALUE
283 The routines \fBcan_change_color()\fR and \fBhas_colors()\fR return \fBTRUE\fR
284 or \fBFALSE\fR.
285 .PP
286 All other routines return the integer \fBERR\fR upon failure and an \fBOK\fR
287 (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful
288 completion.
289 .PP
290 X/Open defines no error conditions.
291 This implementation will return \fBERR\fR on attempts to
292 use color values outside the range \fB0\fP to COLORS\-1
293 (except for the default colors extension),
294 or use color pairs outside the range \fB0\fP to \fBCOLOR_PAIRS\-1\fP.
295 Color values used in \fBinit_color\fP must be in the range \fB0\fP to \fB1000\fP.
296 An error is returned from all functions
297 if the terminal has not been initialized.
298 An error is returned from secondary functions such as \fBinit_pair\fP
299 if \fBstart_color\fP was not called.
300 .RS 3
301 .TP 5
302 \fBinit_color\fP
303 returns an error if the terminal does not support
304 this feature, e.g., if the \fIinitialize_color\fP capability is absent
305 from the terminal description.
306 .TP 5
307 \fBstart_color\fP
308 returns an error if the color table cannot be allocated.
309 .RE
310 .SH NOTES
311 In the \fIncurses\fR implementation, there is a separate color activation flag,
312 color palette, color pairs table, and associated COLORS and COLOR_PAIRS counts
313 for each screen; the \fBstart_color\fR function only affects the current
314 screen.
315 The SVr4/XSI interface is not really designed with this in mind, and
316 historical implementations may use a single shared color palette.
317 .PP
318 Note that setting an implicit background color via a color pair affects only
319 character cells that a character write operation explicitly touches.
320 To change
321 the background color used when parts of a window are blanked by erasing or
322 scrolling operations, see \fBcurs_bkgd\fR(3X).
323 .PP
324 Several caveats apply on 386 and 486 machines with VGA-compatible graphics:
325 .bP
326 COLOR_YELLOW is actually brown.
327 To get yellow, use COLOR_YELLOW combined with the \fBA_BOLD\fR attribute.
328 .bP
329 The A_BLINK attribute should in theory cause the background to go bright.
330 This often fails to work, and even some cards for which it mostly works
331 (such as the
332 Paradise and compatibles) do the wrong thing when you try to set a bright
333 "yellow" background (you get a blinking yellow foreground instead).
334 .bP
335 Color RGB values are not settable.
336 .SH PORTABILITY
337 This implementation satisfies XSI Curses's minimum maximums
338 for \fBCOLORS\fR and \fBCOLOR_PAIRS\fR.
339 .PP
340 The \fBinit_pair\fP routine accepts negative values of foreground
341 and background color to support the \fBuse_default_colors\fP extension,
342 but only if that routine has been first invoked.
343 .PP
344 The assumption that \fBCOLOR_BLACK\fR is the default
345 background color for all terminals can be modified using the
346 \fBassume_default_colors\fP extension.
347 .PP
348 This implementation checks the pointers,
349 e.g., for the values returned by
350 \fBcolor_content\fP and \fBpair_content\fP,
351 and will treat those as optional parameters when null.
352 .SH SEE ALSO
353 \fBcurses\fR(3X),
354 \fBcurs_initscr\fR(3X),
355 \fBcurs_attr\fR(3X),
356 \fBcurs_variables\fR(3X),
357 \fBdefault_colors\fR(3X)