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