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