]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_color.3x.html
ncurses 5.3
[ncurses.git] / doc / html / man / curs_color.3x.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2 <!-- 
3   ****************************************************************************
4   * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc.              *
5   *                                                                          *
6   * Permission is hereby granted, free of charge, to any person obtaining a  *
7   * copy of this software and associated documentation files (the            *
8   * "Software"), to deal in the Software without restriction, including      *
9   * without limitation the rights to use, copy, modify, merge, publish,      *
10   * distribute, distribute with modifications, sublicense, and/or sell       *
11   * copies of the Software, and to permit persons to whom the Software is    *
12   * furnished to do so, subject to the following conditions:                 *
13   *                                                                          *
14   * The above copyright notice and this permission notice shall be included  *
15   * in all copies or substantial portions of the Software.                   *
16   *                                                                          *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18   * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20   * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22   * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23   * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24   *                                                                          *
25   * Except as contained in this notice, the name(s) of the above copyright   *
26   * holders shall not be used in advertising or otherwise to promote the     *
27   * sale, use or other dealings in this Software without prior written       *
28   * authorization.                                                           *
29   ****************************************************************************
30   * @Id: curs_color.3x,v 1.19 2002/02/16 22:38:32 tom Exp @
31 -->
32 <HTML>
33 <HEAD>
34 <TITLE>curs_color 3x</TITLE>
35 <link rev=made href="mailto:bug-ncurses@gnu.org">
36 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
37 </HEAD>
38 <BODY>
39 <H1>curs_color 3x</H1>
40 <HR>
41 <PRE>
42 <!-- Manpage converted by man2html 3.0.1 -->
43
44 </PRE>
45 <H2>NAME</H2><PRE>
46        <STRONG>start_color</STRONG>,     <STRONG>init_pair</STRONG>,     <STRONG>init_color</STRONG>,    <STRONG>has_colors</STRONG>,
47        <STRONG>can_change_color</STRONG>, <STRONG>color_content</STRONG>, <STRONG>pair_content</STRONG>,  <STRONG>COLOR_PAIR</STRONG>
48        - <STRONG>curses</STRONG> color manipulation routines
49
50
51 </PRE>
52 <H2>SYNOPSIS</H2><PRE>
53        <STRONG>#</STRONG> <STRONG>include</STRONG> <STRONG>&lt;curses.h&gt;</STRONG>
54        <STRONG>int</STRONG> <STRONG>start_color(void);</STRONG>
55        <STRONG>int</STRONG> <STRONG>init_pair(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>f,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
56        <STRONG>int</STRONG> <STRONG>init_color(short</STRONG> <STRONG>color,</STRONG> <STRONG>short</STRONG> <STRONG>r,</STRONG> <STRONG>short</STRONG> <STRONG>g,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
57        <STRONG>bool</STRONG> <STRONG>has_colors(void);</STRONG>
58        <STRONG>bool</STRONG> <STRONG>can_change_color(void);</STRONG>
59        <STRONG>int</STRONG>  <STRONG>color_content(short</STRONG>  <STRONG>color,</STRONG> <STRONG>short</STRONG> <STRONG>*r,</STRONG> <STRONG>short</STRONG> <STRONG>*g,</STRONG> <STRONG>short</STRONG>
60        <STRONG>*b);</STRONG>
61        <STRONG>int</STRONG> <STRONG>pair_content(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>*f,</STRONG> <STRONG>short</STRONG> <STRONG>*b);</STRONG>
62
63
64 </PRE>
65 <H2>DESCRIPTION</H2><PRE>
66    <STRONG>Overview</STRONG>
67        <STRONG>curses</STRONG> support color attributes  on  terminals  with  that
68        capability.   To  use  these  routines <STRONG>start_color</STRONG> must be
69        called, usually right after <STRONG>initscr</STRONG>.   Colors  are  always
70        used  in pairs (referred to as color-pairs).  A color-pair
71        consists of a foreground  color  (for  characters)  and  a
72        background color (for the blank field on which the charac-
73        ters are displayed).  A programmer  initializes  a  color-
74        pair  with  the routine <STRONG>init_pair</STRONG>.  After it has been ini-
75        tialized, <STRONG>COLOR_PAIR</STRONG>(<EM>n</EM>), a macro  defined  in  <STRONG>&lt;curses.h&gt;</STRONG>,
76        can be used as a new video attribute.
77
78        If  a  terminal  is capable of redefining colors, the pro-
79        grammer can use the routine <STRONG>init_color</STRONG> to change the defi-
80        nition   of   a   color.    The  routines  <STRONG>has_colors</STRONG>  and
81        <STRONG>can_change_color</STRONG>  return  <STRONG>TRUE</STRONG>  or  <STRONG>FALSE</STRONG>,  depending   on
82        whether  the  terminal  has color capabilities and whether
83        the  programmer  can  change  the  colors.   The   routine
84        <STRONG>color_content</STRONG>  allows  a programmer to extract the amounts
85        of red, green,  and  blue  components  in  an  initialized
86        color.   The  routine  <STRONG>pair_content</STRONG> allows a programmer to
87        find out how a given color-pair is currently defined.
88
89    <STRONG>Routine</STRONG> <STRONG>Descriptions</STRONG>
90        The <STRONG>start_color</STRONG> routine requires no arguments.  It must be
91        called  if  the programmer wants to use colors, and before
92        any other color manipulation routine  is  called.   It  is
93        good  practice  to  call this routine right after <STRONG>initscr</STRONG>.
94        <STRONG>start_color</STRONG> initializes eight basic  colors  (black,  red,
95        green,  yellow,  blue,  magenta, cyan, and white), and two
96        global variables,  <STRONG>COLORS</STRONG>  and  <STRONG>COLOR_PAIRS</STRONG>  (respectively
97        defining  the maximum number of colors and color-pairs the
98        terminal can support).  It also restores the colors on the
99        terminal to the values they had when the terminal was just
100        turned on.
101
102        The <STRONG>init_pair</STRONG> routine changes the definition of  a  color-
103        pair.   It takes three arguments: the number of the color-
104        pair to be changed, the foreground color number,  and  the
105        background color number.  For portable applications:
106
107        -    The value of the first argument must be between <STRONG>1</STRONG> and
108             <STRONG>COLOR_PAIRS-1</STRONG>.
109
110        -    The value of the second and third arguments  must  be
111             between  0  and  <STRONG>COLORS</STRONG> (the 0 color pair is wired to
112             white on black and cannot be changed).
113
114        If the color-pair was previously initialized,  the  screen
115        is  refreshed  and  all occurrences of that color-pair are
116        changed to the new definition.
117
118        As an extension, ncurses allows you to set  color  pair  0
119        via  the  <STRONG>assume_default_colors</STRONG> routine, or to specify the
120        use of default colors  (color  number  <STRONG>-1</STRONG>)  if  you  first
121        invoke the <STRONG>use_default_colors</STRONG> routine.
122
123        The  <STRONG>init_color</STRONG> routine changes the definition of a color.
124        It takes four arguments: the number of  the  color  to  be
125        changed  followed  by three RGB values (for the amounts of
126        red, green, and blue components).  The value of the  first
127        argument  must  be between <STRONG>0</STRONG> and <STRONG>COLORS</STRONG>.  (See the section
128        <STRONG>Colors</STRONG> for the default color index.)   Each  of  the  last
129        three  arguments must be a value between 0 and 1000.  When
130        <STRONG>init_color</STRONG> is used, all occurrences of that color  on  the
131        screen immediately change to the new definition.
132
133        The  <STRONG>has_colors</STRONG> routine requires no arguments.  It returns
134        <STRONG>TRUE</STRONG> if the terminal can manipulate colors; otherwise,  it
135        returns <STRONG>FALSE</STRONG>.  This routine facilitates writing terminal-
136        independent programs.  For example, a programmer  can  use
137        it  to  decide  whether  to  use color or some other video
138        attribute.
139
140        The <STRONG>can_change_color</STRONG> routine requires  no  arguments.   It
141        returns  <STRONG>TRUE</STRONG>  if  the  terminal  supports  colors and can
142        change their definitions; other, it returns  <STRONG>FALSE</STRONG>.   This
143        routine facilitates writing terminal-independent programs.
144
145        The <STRONG>color_content</STRONG> routine gives programmers a way to  find
146        the intensity of the red, green, and blue (RGB) components
147        in a color.  It requires four arguments: the color number,
148        and  three addresses of <STRONG>short</STRONG>s for storing the information
149        about the amounts of red, green, and  blue  components  in
150        the  given color.  The value of the first argument must be
151        between 0 and <STRONG>COLORS</STRONG>.  The values that are stored  at  the
152        addresses  pointed  to  by  the  last  three arguments are
153        between 0 (no component) and 1000 (maximum amount of  com-
154        ponent).
155
156        The  <STRONG>pair_content</STRONG>  routine  allows programmers to find out
157        what colors a given color-pair consists of.   It  requires
158        three  arguments: the color-pair number, and two addresses
159        of <STRONG>short</STRONG>s for storing the foreground  and  the  background
160        color  numbers.   The  value of the first argument must be
161        between 1 and <STRONG>COLOR_PAIRS-1</STRONG>.  The values that  are  stored
162        at  the addresses pointed to by the second and third argu-
163        ments are between 0 and <STRONG>COLORS</STRONG>.
164
165    <STRONG>Colors</STRONG>
166        In <STRONG>&lt;curses.h&gt;</STRONG> the following macros are defined.  These are
167        the  default colors.  <STRONG>curses</STRONG> also assumes that <STRONG>COLOR_BLACK</STRONG>
168        is the default background color for all terminals.
169
170              <STRONG>COLOR_BLACK</STRONG>
171              <STRONG>COLOR_RED</STRONG>
172              <STRONG>COLOR_GREEN</STRONG>
173              <STRONG>COLOR_YELLOW</STRONG>
174              <STRONG>COLOR_BLUE</STRONG>
175              <STRONG>COLOR_MAGENTA</STRONG>
176              <STRONG>COLOR_CYAN</STRONG>
177              <STRONG>COLOR_WHITE</STRONG>
178
179
180 </PRE>
181 <H2>RETURN VALUE</H2><PRE>
182        The routines <STRONG>can_change_color()</STRONG>  and  <STRONG>has_colors()</STRONG>  return
183        <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>.
184
185        All other routines return the integer <STRONG>ERR</STRONG> upon failure and
186        an <STRONG>OK</STRONG> (SVr4 specifies only "an integer  value  other  than
187        <STRONG>ERR</STRONG>") upon successful completion.
188
189
190 </PRE>
191 <H2>NOTES</H2><PRE>
192        In  the  <EM>ncurses</EM> implementation, there is a separate color
193        activation flag, color palette,  color  pairs  table,  and
194        associated  COLORS and COLOR_PAIRS counts for each screen;
195        the <STRONG>start_color</STRONG> function only affects the current  screen.
196        The SVr4/XSI interface is not really designed with this in
197        mind, and historical  implementations  may  use  a  single
198        shared color palette.
199
200        Note that setting an implicit background color via a color
201        pair affects only character cells that a  character  write
202        operation  explicitly  touches.   To change the background
203        color used when parts of a window are blanked  by  erasing
204        or scrolling operations, see <STRONG><A HREF="curs_bkgd.3x.html">curs_bkgd(3x)</A></STRONG>.
205
206        Several  caveats  apply  on 386 and 486 machines with VGA-
207        compatible graphics:
208
209        -    COLOR_YELLOW is actually brown.  To get  yellow,  use
210             COLOR_YELLOW combined with the <STRONG>A_BOLD</STRONG> attribute.
211
212        -    The  A_BLINK  attribute  should  in  theory cause the
213             background to go bright.  This often fails  to  work,
214             and  even  some cards for which it mostly works (such
215             as the Paradise and compatibles) do the  wrong  thing
216             when you try to set a bright "yellow" background (you
217             get a blinking yellow foreground instead).
218
219        -    Color RGB values are not settable.
220
221
222 </PRE>
223 <H2>PORTABILITY</H2><PRE>
224        This implementation satisfies XSI Curses's  minimum  maxi-
225        mums for <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG>.
226
227        The  <STRONG>init_pair</STRONG>  routine  accepts  negative values of fore-
228        ground   and   background    color    to    support    the
229        <STRONG>use_default_colors</STRONG> extension, but only if that routine has
230        been first invoked.
231
232        The assumption that <STRONG>COLOR_BLACK</STRONG> is the default  background
233        color   for  all  terminals  can  be  modified  using  the
234        <STRONG>assume_default_colors</STRONG> extension,
235
236
237
238 </PRE>
239 <H2>SEE ALSO</H2><PRE>
240        <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_initscr.3x.html">curs_initscr(3x)</A></STRONG>, <STRONG><A HREF="curs_attr.3x.html">curs_attr(3x)</A></STRONG>,  <STRONG>default_col-</STRONG>
241        <STRONG><A HREF="default_colors.3x.html">ors(3x)</A></STRONG>
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273 </PRE>
274 <HR>
275 <ADDRESS>
276 Man(1) output converted with
277 <a href="http://www.oac.uci.edu/indiv/ehood/man2html.html">man2html</a>
278 </ADDRESS>
279 </BODY>
280 </HTML>