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