]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_color.3x
ncurses 5.7 - patch 20100102
[ncurses.git] / man / curs_color.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2005,2009 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.29 2009/01/24 23:10:02 tom Exp $
30 .TH curs_color 3X ""
31 .na
32 .hy 0
33 .SH NAME
34 \fBstart_color\fR,
35 \fBinit_pair\fR,
36 \fBinit_color\fR,
37 \fBhas_colors\fR,
38 \fBcan_change_color\fR,
39 \fBcolor_content\fR,
40 \fBpair_content\fR,
41 \fBCOLOR_PAIR\fR - \fBcurses\fR color manipulation routines
42 .ad
43 .hy
44 .SH SYNOPSIS
45 \fB# include <curses.h>\fR
46 .br
47 \fBint start_color(void);\fR
48 .br
49 \fBint init_pair(short pair, short f, short b);\fR
50 .br
51 \fBint init_color(short color, short r, short g, short b);\fR
52 .br
53 \fBbool has_colors(void);\fR
54 .br
55 \fBbool can_change_color(void);\fR
56 .br
57 \fBint color_content(short color, short *r, short *g, short *b);\fR
58 .br
59 \fBint pair_content(short pair, short *f, short *b);\fR
60 .br
61 .SH DESCRIPTION
62 .SS Overview
63 \fBcurses\fR support color attributes on terminals with that capability.  To
64 use these routines \fBstart_color\fR must be called, usually right after
65 \fBinitscr\fR.  Colors are always used in pairs (referred to as color-pairs).
66 A color-pair consists of a foreground color (for characters) and a background
67 color (for the blank field on which the characters are displayed).  A
68 programmer initializes a color-pair with the routine \fBinit_pair\fR.  After it
69 has been initialized, \fBCOLOR_PAIR\fR(\fIn\fR), a macro defined in
70 \fB<curses.h>\fR, can be used as a new video attribute.
71 .PP
72 If a terminal is capable of redefining colors, the programmer can use the
73 routine \fBinit_color\fR to change the definition of a color.  The routines
74 \fBhas_colors\fR and \fBcan_change_color\fR return \fBTRUE\fR or \fBFALSE\fR,
75 depending on whether the terminal has color capabilities and whether the
76 programmer can change the colors.  The routine \fBcolor_content\fR allows a
77 programmer to extract the amounts of red, green, and blue components in an
78 initialized color.  The routine \fBpair_content\fR allows a programmer to find
79 out how a given color-pair is currently defined.
80 .SS Routine Descriptions
81 The \fBstart_color\fR routine requires no arguments.  It must be
82 called if the programmer wants to use colors, and before any other
83 color manipulation routine is called.  It is good practice to call
84 this routine right after \fBinitscr\fR.  \fBstart_color\fR initializes
85 eight basic colors (black, red, green, yellow, blue, magenta, cyan,
86 and white), and two global variables, \fBCOLORS\fR and
87 \fBCOLOR_PAIRS\fR (respectively defining the maximum number of colors
88 and color-pairs the terminal can support).  It also restores the
89 colors on the terminal to the values they had when the terminal was
90 just turned on.
91 .PP
92 The \fBinit_pair\fR routine changes the definition of a color-pair.  It takes
93 three arguments: the number of the color-pair to be changed, the foreground
94 color number, and the background color number.
95 For portable applications:
96 .TP 5
97 -
98 The value of the first argument
99 must be between \fB1\fR and \fBCOLOR_PAIRS-1\fR,
100 except that if default colors are used (see \fBuse_default_colors\fP)
101 the upper limit is adjusted to allow for extra pairs which use
102 a default color in foreground and/or background.
103 .TP 5
104 -
105 The value of the second and
106 third arguments must be between 0 and \fBCOLORS\fR.
107 Color pair 0 is assumed to be white on black,
108 but is actually whatever the terminal implements before color is initialized.
109 It cannot be modified by the application.
110 .PP
111 If the color-pair was previously
112 initialized, the screen is refreshed and all occurrences of that color-pair
113 are changed to the new definition.
114 .PP
115 As an extension, ncurses allows you to set color pair 0 via
116 the \fBassume_default_colors\fR routine, or to specify the use of
117 default colors (color number \fB-1\fR) if you first invoke the
118 \fBuse_default_colors\fR routine.
119 .PP
120 The \fBinit_color\fR routine changes the definition of a color.  It takes four
121 arguments: the number of the color to be changed followed by three RGB values
122 (for the amounts of red, green, and blue components).  The value of the first
123 argument must be between \fB0\fR and \fBCOLORS\fR.  (See the section
124 \fBColors\fR for the default color index.)  Each of the last three arguments
125 must be a value between 0 and 1000.  When \fBinit_color\fR is used, all
126 occurrences of that color on the screen immediately change to the new
127 definition.
128 .PP
129 The \fBhas_colors\fR routine requires no arguments.  It returns \fBTRUE\fR if
130 the terminal can manipulate colors; otherwise, it returns \fBFALSE\fR.  This
131 routine facilitates writing terminal-independent programs.  For example, a
132 programmer can use it to decide whether to use color or some other video
133 attribute.
134 .PP
135 The \fBcan_change_color\fR routine requires no arguments.  It returns
136 \fBTRUE\fR if the terminal supports colors and can change their definitions;
137 other, it returns \fBFALSE\fR.  This routine facilitates writing
138 terminal-independent programs.
139 .PP
140 The \fBcolor_content\fR routine gives programmers a way to find the intensity
141 of the red, green, and blue (RGB) components in a color.  It requires four
142 arguments: the color number, and three addresses of \fBshort\fRs for storing
143 the information about the amounts of red, green, and blue components in the
144 given color.  The value of the first argument must be between 0 and
145 \fBCOLORS\fR.  The values that are stored at the addresses pointed to by the
146 last three arguments are between 0 (no component) and 1000 (maximum amount of
147 component).
148 .PP
149 The \fBpair_content\fR routine allows programmers to find out what colors a
150 given color-pair consists of.  It requires three arguments: the color-pair
151 number, and two addresses of \fBshort\fRs for storing the foreground and the
152 background color numbers.  The value of the first argument must be between 1
153 and \fBCOLOR_PAIRS-1\fR.  The values that are stored at the addresses pointed
154 to by the second and third arguments are between 0 and \fBCOLORS\fR.
155 .SS Colors
156 In \fB<curses.h>\fR the following macros are defined.  These are the default
157 colors.  \fBcurses\fR also assumes that \fBCOLOR_BLACK\fR is the default
158 background color for all terminals.
159 .PP
160 .nf
161       \fBCOLOR_BLACK\fR
162       \fBCOLOR_RED\fR
163       \fBCOLOR_GREEN\fR
164       \fBCOLOR_YELLOW\fR
165       \fBCOLOR_BLUE\fR
166       \fBCOLOR_MAGENTA\fR
167       \fBCOLOR_CYAN\fR
168       \fBCOLOR_WHITE\fR
169 .fi
170 .SH RETURN VALUE
171 The routines \fBcan_change_color()\fR and \fBhas_colors()\fR return \fBTRUE\fR
172 or \fBFALSE\fR.
173 .PP
174 All other routines return the integer \fBERR\fR upon failure and an \fBOK\fR
175 (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful
176 completion.
177 .PP
178 X/Open defines no error conditions.
179 This implementation will return \fBERR\fR on attempts to
180 use color values outside the range 0 to COLORS-1
181 (except for the default colors extension),
182 or use color pairs outside the range 0 to COLOR_PAIR-1.
183 Color values used in \fBinit_color\fP must be in the range 0 to 1000.
184 An error is returned from all functions
185 if the terminal has not been initialized.
186 An error is returned from secondary functions such as \fBinit_pair\fP
187 if \fBstart_color\fP was not called.
188 .RS
189 .TP 5
190 \fBinit_color\fP
191 returns an error if the terminal does not support
192 this feature, e.g., if the \fIinitialize_color\fP capability is absent
193 from the terminal description.
194 .TP 5
195 \fBstart_color\fP
196 returns an error
197 If the color table cannot be allocated.
198 .RE
199 .SH NOTES
200 In the \fIncurses\fR implementation, there is a separate color activation flag,
201 color palette, color pairs table, and associated COLORS and COLOR_PAIRS counts
202 for each screen; the \fBstart_color\fR function only affects the current
203 screen.  The SVr4/XSI interface is not really designed with this in mind, and
204 historical implementations may use a single shared color palette.
205 .PP
206 Note that setting an implicit background color via a color pair affects only
207 character cells that a character write operation explicitly touches.  To change
208 the background color used when parts of a window are blanked by erasing or
209 scrolling operations, see \fBcurs_bkgd\fR(3X).
210 .PP
211 Several caveats apply on 386 and 486 machines with VGA-compatible graphics:
212 .TP 5
213 -
214 COLOR_YELLOW is actually brown.  To get yellow, use COLOR_YELLOW combined with
215 the \fBA_BOLD\fR attribute.
216 .TP 5
217 -
218 The A_BLINK attribute should in theory cause the background to go bright.  This
219 often fails to work, and even some cards for which it mostly works (such as the
220 Paradise and compatibles) do the wrong thing when you try to set a bright
221 "yellow" background (you get a blinking yellow foreground instead).
222 .TP 5
223 -
224 Color RGB values are not settable.
225 .SH PORTABILITY
226 This implementation satisfies XSI Curses's minimum maximums
227 for \fBCOLORS\fR and \fBCOLOR_PAIRS\fR.
228 .PP
229 The \fBinit_pair\fP routine accepts negative values of foreground
230 and background color to support the \fBuse_default_colors\fP extension,
231 but only if that routine has been first invoked.
232 .PP
233 The assumption that \fBCOLOR_BLACK\fR is the default
234 background color for all terminals can be modified using the
235 \fBassume_default_colors\fP extension.
236 .PP
237 This implementation checks the pointers,
238 e.g., for the values returned by
239 \fBcolor_content\fP and \fBpair_content\fP,
240 and will treat those as optional parameters when null.
241 .SH SEE ALSO
242 \fBcurses\fR(3X),
243 \fBcurs_initscr\fR(3X),
244 \fBcurs_attr\fR(3X),
245 \fBdefault_colors\fR(3X)
246 .\"#
247 .\"# The following sets edit modes for GNU EMACS
248 .\"# Local Variables:
249 .\"# mode:nroff
250 .\"# fill-column:79
251 .\"# End: