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