]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_color.3x
ncurses 6.0 - patch 20151010
[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.39 2015/06/06 23:29:02 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 .SH DESCRIPTION
70 .SS Overview
71 \fBcurses\fR supports color attributes on terminals with that capability.
72 To use these routines \fBstart_color\fR must be called, usually right after
73 \fBinitscr\fR.
74 Colors are always used in pairs (referred to as color-pairs).
75 A color-pair consists of a foreground color (for characters) and a background
76 color (for the blank field on which the characters are displayed).
77 A programmer initializes a color-pair with the routine \fBinit_pair\fR.
78 After it has been initialized, \fBCOLOR_PAIR\fR(\fIn\fR), a macro defined in
79 \fB<curses.h>\fR, can be used as a new video attribute.
80 .PP
81 If a terminal is capable of redefining colors, the programmer can use the
82 routine \fBinit_color\fR to change the definition of a color.
83 The routines \fBhas_colors\fR and \fBcan_change_color\fR
84 return \fBTRUE\fR or \fBFALSE\fR,
85 depending on whether the terminal has color capabilities and whether the
86 programmer can change the colors.
87 The routine \fBcolor_content\fR allows a
88 programmer to extract the amounts of red, green, and blue components in an
89 initialized color.
90 The routine \fBpair_content\fR allows a programmer to find
91 out how a given color-pair is currently defined.
92 .SS Color Rendering
93 The \fBcurses\fP library combines these inputs to produce the
94 actual foreground and background colors shown on the screen:
95 .bP
96 per-character video attributes (e.g., via \fBwaddch\fP),
97 .bP
98 the window attribute (e.g., by \fBwattrset\fP), and
99 .bP
100 the background character (e.g., \fBwbkgdset\fP).
101 .PP
102 Per-character and window attributes are usually set by a parameter containing
103 video attributes including a \fBCOLOR_PAIR\fP value.
104 Some functions such as \fBwattr_set\fP use a separate parameter which
105 is the color pair number.
106 .PP
107 The background character is a special case: it includes a character value,
108 just as if it were passed to \fBwaddch\fP.
109 .PP
110 The \fBcurses\fP library does the actual work of combining these color
111 pairs in an internal function called from \fBwaddch\fP:
112 .bP
113 If the parameter passed to \fBwaddch\fP is \fIblank\fP,
114 and it uses the special color pair 0,
115 .RS
116 .bP
117 \fBcurses\fP next checks the window attribute.
118 .bP
119 If the window attribute does not use color pair 0,
120 \fBcurses\fP uses the color pair from the window attribute.
121 .bP
122 Otherwise, \fBcurses\fP uses the background character.
123 .RE
124 .bP
125 If the parameter passed to \fBwaddch\fP is \fInot blank\fP,
126 or it does not use the special color pair 0,
127 \fBcurses\fP prefers the color pair from the parameter,
128 if it is nonzero.
129 Otherwise, it tries the window attribute next, and finally the
130 background character.
131 .PP
132 Some \fBcurses\fP functions such as \fBwprintw\fP call \fBwaddch\fP.
133 Those do not combine its parameter with a color pair.
134 Consequently those calls use only the window attribute or
135 the background character.
136 .SS Routine Descriptions
137 The \fBstart_color\fR routine requires no arguments.
138 It must be called if the programmer wants to use colors, and before any other
139 color manipulation routine is called.
140 It is good practice to call this routine right after \fBinitscr\fR.
141 \fBstart_color\fR does this:
142 .bP
143 It initializes two global variables, \fBCOLORS\fR and
144 \fBCOLOR_PAIRS\fR (respectively defining the maximum number of colors
145 and color-pairs the terminal can support).
146 .bP
147 It initializes the special color pair \fB0\fP to the default foreground
148 and background colors.
149 No other color pairs are initialized.
150 .bP
151 It restores the colors on the terminal to the values
152 they had when the terminal was just turned on.
153 .bP
154 If the terminal supports the \fBinitc\fP (\fBinitialize_color\fP) capability,
155 \fBstart_color\fP
156 initializes its internal table representing the
157 red, green and blue components of the color palette.
158 .IP
159 The components depend on whether the terminal uses
160 CGA (aka "ANSI") or
161 HLS (i.e., the \fBhls\fP (\fBhue_lightness_saturation\fP) capability is set).
162 The table is initialized first for eight basic colors
163 (black, red, green, yellow, blue, magenta, cyan, and white),
164 and after that (if the terminal supports more than eight colors)
165 the components are initialized to \fB1000\fP.
166 .IP
167 \fBstart_color\fP does not attempt to set the terminal's color palette
168 to match its built-in table.
169 An application may use \fBinit_color\fP to alter the internal table
170 along with the terminal's color.
171 .PP
172 These limits apply to color values and color pairs.
173 Values outside these limits are not legal, and may result in a runtime error:
174 .bP
175 \fBCOLORS\fP corresponds to the terminal database's \fBmax_colors\fP capability,
176 which is typically a signed 16-bit integer (see \fBterminfo\fR(\*n)).
177 .bP
178 color values are expected to be in the range \fB0\fP to \fBCOLORS\-1\fP,
179 inclusive (including \fB0\fP and \fBCOLORS\-1\fP).
180 .bP
181 a special color value \fB\-1\fP is used in certain extended functions
182 to denote the \fIdefault color\fP (see \fBuse_default_colors\fP).
183 .bP
184 \fBCOLOR_PAIRS\fP corresponds to the terminal database's \fBmax_pairs\fP capability,
185 which is typically a signed 16-bit integer (see \fBterminfo\fR(\*n)).
186 .bP
187 legal color pair values are in the range \fB1\fP to \fBCOLOR_PAIRS\-1\fP,
188 inclusive.
189 .bP
190 color pair \fB0\fP is special; it denotes \*(``no color\*(''.
191 .IP
192 Color pair \fB0\fP is assumed to be white on black,
193 but is actually whatever the terminal implements before color is initialized.
194 It cannot be modified by the application.
195 .PP
196 The \fBinit_pair\fR routine changes the definition of a color-pair.
197 It takes three arguments: the number of the color-pair to be changed, the foreground
198 color number, and the background color number.
199 For portable applications:
200 .bP
201 The first argument must be a legal color pair value.
202 If default colors are used (see \fBuse_default_colors\fP)
203 the upper limit is adjusted to allow for extra pairs which use
204 a default color in foreground and/or background.
205 .bP
206 The second and third arguments must be legal color values.
207 .PP
208 If the color-pair was previously initialized,
209 the screen is refreshed and all occurrences of that color-pair
210 are changed to the new definition.
211 .PP
212 As an extension, ncurses allows you to set color pair \fB0\fP via
213 the \fBassume_default_colors\fR routine, or to specify the use of
214 default colors (color number \fB\-1\fR) if you first invoke the
215 \fBuse_default_colors\fR routine.
216 .PP
217 The \fBinit_color\fR routine changes the definition of a color.
218 It takes four arguments: the number of the color to be changed followed by three RGB values
219 (for the amounts of red, green, and blue components).
220 The first argument must be a legal color value;
221 default colors are not allowed here.
222 (See the section \fBColors\fR for the default color index.)
223 Each of the last three arguments
224 must be a value in the range \fB0\fP through \fB1000\fP.
225 When \fBinit_color\fR is used, all
226 occurrences of that color on the screen immediately change to the new
227 definition.
228 .PP
229 The \fBhas_colors\fR routine requires no arguments.
230 It returns \fBTRUE\fR if
231 the terminal can manipulate colors; otherwise, it returns \fBFALSE\fR.
232 This routine facilitates writing terminal-independent programs.
233 For example, a programmer can use it to decide
234 whether to use color or some other video attribute.
235 .PP
236 The \fBcan_change_color\fR routine requires no arguments.
237 It returns \fBTRUE\fR if the terminal supports colors
238 and can change their definitions;
239 other, it returns \fBFALSE\fR.
240 This routine facilitates writing terminal-independent programs.
241 .PP
242 The \fBcolor_content\fR routine gives programmers a way to find the intensity
243 of the red, green, and blue (RGB) components in a color.
244 It requires four arguments: the color number, and three addresses
245 of \fBshort\fRs for storing
246 the information about the amounts of red, green, and blue components in the
247 given color.
248 The first argument must be a legal color value, i.e.,
249 \fB0\fP through \fBCOLORS\-1\fP, inclusive.
250 The values that are stored at the addresses pointed to by the
251 last three arguments are in the range
252 \fB0\fP (no component) through \fB1000\fP (maximum amount of component), inclusive.
253 .PP
254 The \fBpair_content\fR routine allows programmers to find out what colors a
255 given color-pair consists of.
256 It requires three arguments: the color-pair
257 number, and two addresses of \fBshort\fRs for storing the foreground and the
258 background color numbers.
259 The first argument must be a legal color value,
260 i.e., in the range \fB1\fP through \fBCOLOR_PAIRS\-1\fR, inclusive.
261 The values that are stored at the addresses pointed
262 to by the second and third arguments are in the
263 range \fB0\fP through \fBCOLORS\fR, inclusive.
264 .SS Colors
265 In \fB<curses.h>\fR the following macros are defined.
266 These are the standard colors (ISO-6429).
267 \fBcurses\fR also assumes that \fBCOLOR_BLACK\fR is the default
268 background color for all terminals.
269 .PP
270 .nf
271       \fBCOLOR_BLACK\fR
272       \fBCOLOR_RED\fR
273       \fBCOLOR_GREEN\fR
274       \fBCOLOR_YELLOW\fR
275       \fBCOLOR_BLUE\fR
276       \fBCOLOR_MAGENTA\fR
277       \fBCOLOR_CYAN\fR
278       \fBCOLOR_WHITE\fR
279 .fi
280 .SH RETURN VALUE
281 The routines \fBcan_change_color()\fR and \fBhas_colors()\fR return \fBTRUE\fR
282 or \fBFALSE\fR.
283 .PP
284 All other routines return the integer \fBERR\fR upon failure and an \fBOK\fR
285 (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful
286 completion.
287 .PP
288 X/Open defines no error conditions.
289 This implementation will return \fBERR\fR on attempts to
290 use color values outside the range \fB0\fP to COLORS\-1
291 (except for the default colors extension),
292 or use color pairs outside the range \fB0\fP to \fBCOLOR_PAIRS\-1\fP.
293 Color values used in \fBinit_color\fP must be in the range \fB0\fP to \fB1000\fP.
294 An error is returned from all functions
295 if the terminal has not been initialized.
296 An error is returned from secondary functions such as \fBinit_pair\fP
297 if \fBstart_color\fP was not called.
298 .RS 3
299 .TP 5
300 \fBinit_color\fP
301 returns an error if the terminal does not support
302 this feature, e.g., if the \fIinitialize_color\fP capability is absent
303 from the terminal description.
304 .TP 5
305 \fBstart_color\fP
306 returns an error if the color table cannot be allocated.
307 .RE
308 .SH NOTES
309 In the \fIncurses\fR implementation, there is a separate color activation flag,
310 color palette, color pairs table, and associated COLORS and COLOR_PAIRS counts
311 for each screen; the \fBstart_color\fR function only affects the current
312 screen.
313 The SVr4/XSI interface is not really designed with this in mind, and
314 historical implementations may use a single shared color palette.
315 .PP
316 Note that setting an implicit background color via a color pair affects only
317 character cells that a character write operation explicitly touches.
318 To change
319 the background color used when parts of a window are blanked by erasing or
320 scrolling operations, see \fBcurs_bkgd\fR(3X).
321 .PP
322 Several caveats apply on 386 and 486 machines with VGA-compatible graphics:
323 .bP
324 COLOR_YELLOW is actually brown.
325 To get yellow, use COLOR_YELLOW combined with the \fBA_BOLD\fR attribute.
326 .bP
327 The A_BLINK attribute should in theory cause the background to go bright.
328 This often fails to work, and even some cards for which it mostly works
329 (such as the
330 Paradise and compatibles) do the wrong thing when you try to set a bright
331 "yellow" background (you get a blinking yellow foreground instead).
332 .bP
333 Color RGB values are not settable.
334 .SH PORTABILITY
335 This implementation satisfies XSI Curses's minimum maximums
336 for \fBCOLORS\fR and \fBCOLOR_PAIRS\fR.
337 .PP
338 The \fBinit_pair\fP routine accepts negative values of foreground
339 and background color to support the \fBuse_default_colors\fP extension,
340 but only if that routine has been first invoked.
341 .PP
342 The assumption that \fBCOLOR_BLACK\fR is the default
343 background color for all terminals can be modified using the
344 \fBassume_default_colors\fP extension.
345 .PP
346 This implementation checks the pointers,
347 e.g., for the values returned by
348 \fBcolor_content\fP and \fBpair_content\fP,
349 and will treat those as optional parameters when null.
350 .SH SEE ALSO
351 \fBcurses\fR(3X),
352 \fBcurs_initscr\fR(3X),
353 \fBcurs_attr\fR(3X),
354 \fBcurs_variables\fR(3X),
355 \fBdefault_colors\fR(3X)