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