]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_color.3x
ncurses 5.6 - patch 20070317
[ncurses.git] / man / curs_color.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2004,2005 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.28 2005/12/18 00:00:37 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 .TP 5
101 -
102 The value of the second and
103 third arguments must be between 0 and \fBCOLORS\fR.
104 Color pair 0 is assumed to be white on black,
105 but is actually whatever the terminal implements before color is initialized.
106 It cannot be modified by the application.
107 .PP
108 If the color-pair was previously
109 initialized, the screen is refreshed and all occurrences of that color-pair
110 are changed to the new definition.
111 .PP
112 As an extension, ncurses allows you to set color pair 0 via
113 the \fBassume_default_colors\fR routine, or to specify the use of
114 default colors (color number \fB-1\fR) if you first invoke the
115 \fBuse_default_colors\fR routine.
116 .PP
117 The \fBinit_color\fR routine changes the definition of a color.  It takes four
118 arguments: the number of the color to be changed followed by three RGB values
119 (for the amounts of red, green, and blue components).  The value of the first
120 argument must be between \fB0\fR and \fBCOLORS\fR.  (See the section
121 \fBColors\fR for the default color index.)  Each of the last three arguments
122 must be a value between 0 and 1000.  When \fBinit_color\fR is used, all
123 occurrences of that color on the screen immediately change to the new
124 definition.
125 .PP
126 The \fBhas_colors\fR routine requires no arguments.  It returns \fBTRUE\fR if
127 the terminal can manipulate colors; otherwise, it returns \fBFALSE\fR.  This
128 routine facilitates writing terminal-independent programs.  For example, a
129 programmer can use it to decide whether to use color or some other video
130 attribute.
131 .PP
132 The \fBcan_change_color\fR routine requires no arguments.  It returns
133 \fBTRUE\fR if the terminal supports colors and can change their definitions;
134 other, it returns \fBFALSE\fR.  This routine facilitates writing
135 terminal-independent programs.
136 .PP
137 The \fBcolor_content\fR routine gives programmers a way to find the intensity
138 of the red, green, and blue (RGB) components in a color.  It requires four
139 arguments: the color number, and three addresses of \fBshort\fRs for storing
140 the information about the amounts of red, green, and blue components in the
141 given color.  The value of the first argument must be between 0 and
142 \fBCOLORS\fR.  The values that are stored at the addresses pointed to by the
143 last three arguments are between 0 (no component) and 1000 (maximum amount of
144 component).
145 .PP
146 The \fBpair_content\fR routine allows programmers to find out what colors a
147 given color-pair consists of.  It requires three arguments: the color-pair
148 number, and two addresses of \fBshort\fRs for storing the foreground and the
149 background color numbers.  The value of the first argument must be between 1
150 and \fBCOLOR_PAIRS-1\fR.  The values that are stored at the addresses pointed
151 to by the second and third arguments are between 0 and \fBCOLORS\fR.
152 .SS Colors
153 In \fB<curses.h>\fR the following macros are defined.  These are the default
154 colors.  \fBcurses\fR also assumes that \fBCOLOR_BLACK\fR is the default
155 background color for all terminals.
156 .PP
157 .nf
158       \fBCOLOR_BLACK\fR
159       \fBCOLOR_RED\fR
160       \fBCOLOR_GREEN\fR
161       \fBCOLOR_YELLOW\fR
162       \fBCOLOR_BLUE\fR
163       \fBCOLOR_MAGENTA\fR
164       \fBCOLOR_CYAN\fR
165       \fBCOLOR_WHITE\fR
166 .fi
167 .SH RETURN VALUE
168 The routines \fBcan_change_color()\fR and \fBhas_colors()\fR return \fBTRUE\fR
169 or \fBFALSE\fR.
170 .PP
171 All other routines return the integer \fBERR\fR upon failure and an \fBOK\fR
172 (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful
173 completion.
174 .PP
175 X/Open defines no error conditions.
176 This implementation will return \fBERR\fR on attempts to
177 use color values outside the range 0 to COLORS-1
178 (except for the default colors extension),
179 or use color pairs outside the range 0 to COLOR_PAIR-1.
180 Color values used in \fBinit_color\fP must be in the range 0 to 1000.
181 An error is returned from all functions
182 if the terminal has not been initialized.
183 An error is returned from secondary functions such as \fBinit_pair\fP
184 if \fBstart_color\fP was not called.
185 .RS
186 .TP 5
187 \fBinit_color\fP
188 returns an error if the terminal does not support
189 this feature, e.g., if the \fIinitialize_color\fP capability is absent
190 from the terminal description.
191 .TP 5
192 \fBstart_color\fP
193 returns an error
194 If the color table cannot be allocated.
195 .RE
196 .SH NOTES
197 In the \fIncurses\fR implementation, there is a separate color activation flag,
198 color palette, color pairs table, and associated COLORS and COLOR_PAIRS counts
199 for each screen; the \fBstart_color\fR function only affects the current
200 screen.  The SVr4/XSI interface is not really designed with this in mind, and
201 historical implementations may use a single shared color palette.
202 .PP
203 Note that setting an implicit background color via a color pair affects only
204 character cells that a character write operation explicitly touches.  To change
205 the background color used when parts of a window are blanked by erasing or
206 scrolling operations, see \fBcurs_bkgd\fR(3X).
207 .PP
208 Several caveats apply on 386 and 486 machines with VGA-compatible graphics:
209 .TP 5
210 -
211 COLOR_YELLOW is actually brown.  To get yellow, use COLOR_YELLOW combined with
212 the \fBA_BOLD\fR attribute.
213 .TP 5
214 -
215 The A_BLINK attribute should in theory cause the background to go bright.  This
216 often fails to work, and even some cards for which it mostly works (such as the
217 Paradise and compatibles) do the wrong thing when you try to set a bright
218 "yellow" background (you get a blinking yellow foreground instead).
219 .TP 5
220 -
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 \fBdefault_colors\fR(3X)
243 .\"#
244 .\"# The following sets edit modes for GNU EMACS
245 .\"# Local Variables:
246 .\"# mode:nroff
247 .\"# fill-column:79
248 .\"# End: