]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_color.3x.html
ncurses 5.9 - patch 20141220
[ncurses.git] / doc / html / man / curs_color.3x.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
2 <!-- 
3   ****************************************************************************
4   * Copyright (c) 1998-2009,2010 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.36 2014/11/16 00:44:29 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 <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>                                           <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
44
45
46
47
48 </PRE>
49 <H2>NAME</H2><PRE>
50        <STRONG>start_color</STRONG>, <STRONG>init_pair</STRONG>, <STRONG>init_color</STRONG>, <STRONG>has_colors</STRONG>,
51        <STRONG>can_change_color</STRONG>, <STRONG>color_content</STRONG>, <STRONG>pair_content</STRONG>, <STRONG>COLOR_PAIR</STRONG>
52        - <STRONG>curses</STRONG> color manipulation routines
53
54
55 </PRE>
56 <H2>SYNOPSIS</H2><PRE>
57        <STRONG>#</STRONG> <STRONG>include</STRONG> <STRONG>&lt;curses.h&gt;</STRONG>
58
59        <STRONG>int</STRONG> <STRONG>start_color(void);</STRONG>
60        <STRONG>int</STRONG> <STRONG>init_pair(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>f,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
61        <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>
62        <STRONG>bool</STRONG> <STRONG>has_colors(void);</STRONG>
63        <STRONG>bool</STRONG> <STRONG>can_change_color(void);</STRONG>
64        <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>
65        <STRONG>*b);</STRONG>
66        <STRONG>int</STRONG> <STRONG>pair_content(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>*f,</STRONG> <STRONG>short</STRONG> <STRONG>*b);</STRONG>
67
68
69 </PRE>
70 <H2>DESCRIPTION</H2><PRE>
71    <STRONG>Overview</STRONG>
72        <STRONG>curses</STRONG> support color attributes on terminals with that ca-
73        pability.   To  use  these  routines  <STRONG>start_color</STRONG>  must be
74        called, usually right after <STRONG>initscr</STRONG>.   Colors  are  always
75        used  in pairs (referred to as color-pairs).  A color-pair
76        consists of a foreground  color  (for  characters)  and  a
77        background color (for the blank field on which the charac-
78        ters are displayed).  A programmer  initializes  a  color-
79        pair  with  the routine <STRONG>init_pair</STRONG>.  After it has been ini-
80        tialized, <STRONG>COLOR_PAIR</STRONG>(<EM>n</EM>), a macro  defined  in  <STRONG>&lt;curses.h&gt;</STRONG>,
81        can be used as a new video attribute.
82
83        If  a  terminal  is capable of redefining colors, the pro-
84        grammer can use the routine <STRONG>init_color</STRONG> to change the defi-
85        nition   of   a   color.    The  routines  <STRONG>has_colors</STRONG>  and
86        <STRONG>can_change_color</STRONG>  return  <STRONG>TRUE</STRONG>  or  <STRONG>FALSE</STRONG>,  depending   on
87        whether  the  terminal  has color capabilities and whether
88        the programmer can change the colors.   The  routine  <STRONG>col-</STRONG>
89        <STRONG>or_content</STRONG>  allows  a programmer to extract the amounts of
90        red, green, and blue components in an  initialized  color.
91        The  routine  <STRONG>pair_content</STRONG> allows a programmer to find out
92        how a given color-pair is currently defined.
93
94    <STRONG>Routine</STRONG> <STRONG>Descriptions</STRONG>
95        The <STRONG>start_color</STRONG> routine requires no arguments.  It must be
96        called  if  the programmer wants to use colors, and before
97        any other color manipulation routine  is  called.   It  is
98        good  practice  to  call this routine right after <STRONG>initscr</STRONG>.
99        <STRONG>start_color</STRONG> initializes eight basic  colors  (black,  red,
100        green,  yellow,  blue,  magenta, cyan, and white), and two
101        global variables,  <STRONG>COLORS</STRONG>  and  <STRONG>COLOR_PAIRS</STRONG>  (respectively
102        defining  the maximum number of colors and color-pairs the
103        terminal can support).  It also restores the colors on the
104        terminal to the values they had when the terminal was just
105        turned on.
106
107        These limits apply to color values and color pairs.   Val-
108        ues  outside these limits are not legal, and may result in
109        a runtime error:
110
111        <STRONG>o</STRONG>   <STRONG>COLORS</STRONG> corresponds to the terminal database's <STRONG>max_col-</STRONG>
112            <STRONG>ors</STRONG> capability, which is typically a signed 16-bit in-
113            teger (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
114
115        <STRONG>o</STRONG>   color values are expected to be in the range <STRONG>0</STRONG> to <STRONG>COL-</STRONG>
116            <STRONG>ORS-1</STRONG>, inclusive (including <STRONG>0</STRONG> and <STRONG>COLORS-1</STRONG>).
117
118        <STRONG>o</STRONG>   a  special  color value <STRONG>-1</STRONG> is used in certain extended
119            functions to denote the  <EM>default</EM>  <EM>color</EM>  (see  <STRONG>use_de-</STRONG>
120            <STRONG>fault_colors</STRONG>).
121
122        <STRONG>o</STRONG>   <STRONG>COLOR_PAIRS</STRONG>  corresponds  to  the  terminal database's
123            <STRONG>max_pairs</STRONG> capability,  which  is  typically  a  signed
124            16-bit integer (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
125
126        <STRONG>o</STRONG>   legal  color  pair  values  are in the range <STRONG>1</STRONG> to <STRONG>COL-</STRONG>
127            <STRONG>OR_PAIRS-1</STRONG>, inclusive.
128
129        <STRONG>o</STRONG>   color pair <STRONG>0</STRONG> is special; it denotes "no color".
130
131            Color pair <STRONG>0</STRONG> is assumed to be white on black,  but  is
132            actually whatever the terminal implements before color
133            is initialized.  It cannot be modified by the applica-
134            tion.
135
136        The  <STRONG>init_pair</STRONG>  routine changes the definition of a color-
137        pair.  It takes three arguments: the number of the  color-
138        pair  to  be changed, the foreground color number, and the
139        background color number.  For portable applications:
140
141        <STRONG>o</STRONG>   The first argument must be a legal color  pair  value.
142            If  default  colors  are used (see <STRONG>use_default_colors</STRONG>)
143            the upper limit is adjusted to allow for  extra  pairs
144            which  use  a default color in foreground and/or back-
145            ground.
146
147        <STRONG>o</STRONG>   The second and third arguments  must  be  legal  color
148            values.
149
150        If  the  color-pair was previously initialized, the screen
151        is refreshed and all occurrences of  that  color-pair  are
152        changed to the new definition.
153
154        As  an  extension,  ncurses allows you to set color pair <STRONG>0</STRONG>
155        via the <STRONG>assume_default_colors</STRONG> routine, or to  specify  the
156        use  of  default colors (color number <STRONG>-1</STRONG>) if you first in-
157        voke the <STRONG>use_default_colors</STRONG> routine.
158
159        The <STRONG>init_color</STRONG> routine changes the definition of a  color.
160        It  takes  four  arguments:  the number of the color to be
161        changed followed by three RGB values (for the  amounts  of
162        red, green, and blue components).  The first argument must
163        be a legal color value; default  colors  are  not  allowed
164        here.   (See  the section <STRONG>Colors</STRONG> for the default color in-
165        dex.)  Each of the last three arguments must be a value in
166        the  range  <STRONG>0</STRONG>  through <STRONG>1000</STRONG>.  When <STRONG>init_color</STRONG> is used, all
167        occurrences of that color on the screen immediately change
168        to the new definition.
169
170        The  <STRONG>has_colors</STRONG> routine requires no arguments.  It returns
171        <STRONG>TRUE</STRONG> if the terminal can manipulate colors; otherwise,  it
172        returns <STRONG>FALSE</STRONG>.  This routine facilitates writing terminal-
173        independent programs.  For example, a programmer  can  use
174        it  to decide whether to use color or some other video at-
175        tribute.
176
177        The <STRONG>can_change_color</STRONG> routine requires  no  arguments.   It
178        returns  <STRONG>TRUE</STRONG>  if  the  terminal  supports  colors and can
179        change their definitions; other, it returns  <STRONG>FALSE</STRONG>.   This
180        routine facilitates writing terminal-independent programs.
181
182        The  <STRONG>color_content</STRONG> routine gives programmers a way to find
183        the intensity of the red, green, and blue (RGB) components
184        in a color.  It requires four arguments: the color number,
185        and three addresses of <STRONG>short</STRONG>s for storing the  information
186        about  the  amounts  of red, green, and blue components in
187        the given color.  The first argument must be a legal color
188        value,  i.e.,  <STRONG>0</STRONG>  through <STRONG>COLORS-1</STRONG>, inclusive.  The values
189        that are stored at the addresses pointed to  by  the  last
190        three  arguments are in the range <STRONG>0</STRONG> (no component) through
191        <STRONG>1000</STRONG> (maximum amount of component), inclusive.
192
193        The <STRONG>pair_content</STRONG> routine allows programmers  to  find  out
194        what  colors  a given color-pair consists of.  It requires
195        three arguments: the color-pair number, and two  addresses
196        of  <STRONG>short</STRONG>s  for  storing the foreground and the background
197        color numbers.  The first argument must be a  legal  color
198        value,  i.e., in the range <STRONG>1</STRONG> through <STRONG>COLOR_PAIRS-1</STRONG>, inclu-
199        sive.  The values that are stored at the addresses pointed
200        to  by  the  second and third arguments are in the range <STRONG>0</STRONG>
201        through <STRONG>COLORS</STRONG>, inclusive.
202
203    <STRONG>Colors</STRONG>
204        In <STRONG>&lt;curses.h&gt;</STRONG> the following macros are defined.  These are
205        the  default colors.  <STRONG>curses</STRONG> also assumes that <STRONG>COLOR_BLACK</STRONG>
206        is the default background color for all terminals.
207
208              <STRONG>COLOR_BLACK</STRONG>
209              <STRONG>COLOR_RED</STRONG>
210              <STRONG>COLOR_GREEN</STRONG>
211              <STRONG>COLOR_YELLOW</STRONG>
212              <STRONG>COLOR_BLUE</STRONG>
213              <STRONG>COLOR_MAGENTA</STRONG>
214              <STRONG>COLOR_CYAN</STRONG>
215              <STRONG>COLOR_WHITE</STRONG>
216
217
218 </PRE>
219 <H2>RETURN VALUE</H2><PRE>
220        The routines <STRONG>can_change_color()</STRONG>  and  <STRONG>has_colors()</STRONG>  return
221        <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>.
222
223        All other routines return the integer <STRONG>ERR</STRONG> upon failure and
224        an <STRONG>OK</STRONG> (SVr4 specifies only "an integer  value  other  than
225        <STRONG>ERR</STRONG>") upon successful completion.
226
227        X/Open  defines  no error conditions.  This implementation
228        will return <STRONG>ERR</STRONG> on attempts to use  color  values  outside
229        the range <STRONG>0</STRONG> to COLORS-1 (except for the default colors ex-
230        tension), or use color pairs outside the range <STRONG>0</STRONG>  to  <STRONG>COL-</STRONG>
231        <STRONG>OR_PAIRS-1</STRONG>.   Color  values  used in <STRONG>init_color</STRONG> must be in
232        the range <STRONG>0</STRONG> to <STRONG>1000</STRONG>.  An error is returned from all  func-
233        tions  if the terminal has not been initialized.  An error
234        is returned from secondary functions such as <STRONG>init_pair</STRONG>  if
235        <STRONG>start_color</STRONG> was not called.
236
237           <STRONG>init_color</STRONG>
238                returns  an error if the terminal does not support
239                this feature, e.g., if the <EM>initialize</EM><STRONG>_</STRONG><EM>color</EM>  capa-
240                bility is absent from the terminal description.
241
242           <STRONG>start_color</STRONG>
243                returns  an error if the color table cannot be al-
244                located.
245
246
247 </PRE>
248 <H2>NOTES</H2><PRE>
249        In the <EM>ncurses</EM> implementation, there is a  separate  color
250        activation flag, color palette, color pairs table, and as-
251        sociated COLORS and COLOR_PAIRS counts  for  each  screen;
252        the  <STRONG>start_color</STRONG> function only affects the current screen.
253        The SVr4/XSI interface is not really designed with this in
254        mind,  and  historical  implementations  may  use a single
255        shared color palette.
256
257        Note that setting an implicit background color via a color
258        pair  affects  only character cells that a character write
259        operation explicitly touches.  To  change  the  background
260        color  used  when parts of a window are blanked by erasing
261        or scrolling operations, see <STRONG><A HREF="curs_bkgd.3x.html">curs_bkgd(3x)</A></STRONG>.
262
263        Several caveats apply on 386 and 486  machines  with  VGA-
264        compatible graphics:
265
266        <STRONG>o</STRONG>   COLOR_YELLOW  is  actually  brown.  To get yellow, use
267            COLOR_YELLOW combined with the <STRONG>A_BOLD</STRONG> attribute.
268
269        <STRONG>o</STRONG>   The A_BLINK attribute should in theory cause the back-
270            ground  to  go  bright.  This often fails to work, and
271            even some cards for which it mostly works (such as the
272            Paradise  and compatibles) do the wrong thing when you
273            try to set a bright "yellow"  background  (you  get  a
274            blinking yellow foreground instead).
275
276        <STRONG>o</STRONG>   Color RGB values are not settable.
277
278
279 </PRE>
280 <H2>PORTABILITY</H2><PRE>
281        This  implementation  satisfies XSI Curses's minimum maxi-
282        mums for <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG>.
283
284        The <STRONG>init_pair</STRONG> routine accepts  negative  values  of  fore-
285        ground   and  background  color  to  support  the  <STRONG>use_de-</STRONG>
286        <STRONG>fault_colors</STRONG> extension, but only if that routine has  been
287        first invoked.
288
289        The  assumption that <STRONG>COLOR_BLACK</STRONG> is the default background
290        color for all terminals can  be  modified  using  the  <STRONG>as-</STRONG>
291        <STRONG>sume_default_colors</STRONG> extension.
292
293        This  implementation  checks  the  pointers, e.g., for the
294        values returned by  <STRONG>color_content</STRONG>  and  <STRONG>pair_content</STRONG>,  and
295        will treat those as optional parameters when null.
296
297
298 </PRE>
299 <H2>SEE ALSO</H2><PRE>
300        <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>curs_vari-</STRONG>
301        <STRONG><A HREF="curs_variables.3x.html">ables(3x)</A></STRONG>, <STRONG><A HREF="default_colors.3x.html">default_colors(3x)</A></STRONG>
302
303
304
305                                                          <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
306 </PRE>
307 <HR>
308 Man(1) output converted with <a href="http://invisible-island.net/scripts/readme.html#others_scripts">man2html</a>
309 </BODY>
310 </HTML>