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