]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_color.3x.html
9cf3791793c61a09817f73d332d3461949a74655
[ncurses.git] / doc / html / man / curs_color.3x.html
1 <!-- 
2   ****************************************************************************
3   * Copyright (c) 1998-2010,2015 Free Software Foundation, Inc.              *
4   *                                                                          *
5   * Permission is hereby granted, free of charge, to any person obtaining a  *
6   * copy of this software and associated documentation files (the            *
7   * "Software"), to deal in the Software without restriction, including      *
8   * without limitation the rights to use, copy, modify, merge, publish,      *
9   * distribute, distribute with modifications, sublicense, and/or sell       *
10   * copies of the Software, and to permit persons to whom the Software is    *
11   * furnished to do so, subject to the following conditions:                 *
12   *                                                                          *
13   * The above copyright notice and this permission notice shall be included  *
14   * in all copies or substantial portions of the Software.                   *
15   *                                                                          *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17   * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19   * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21   * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22   * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23   *                                                                          *
24   * Except as contained in this notice, the name(s) of the above copyright   *
25   * holders shall not be used in advertising or otherwise to promote the     *
26   * sale, use or other dealings in this Software without prior written       *
27   * authorization.                                                           *
28   ****************************************************************************
29   * @Id: curs_color.3x,v 1.40 2015/12/05 20:09:42 tom Exp @
30 -->
31 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
32 <HTML>
33 <HEAD>
34 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
35 <meta name="generator" content="Manpage converted by man2html - see http://invisible-island.net/scripts/readme.html#others_scripts">
36 <TITLE>curs_color 3x</TITLE>
37 <link rev=made href="mailto:bug-ncurses@gnu.org">
38 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
39 </HEAD>
40 <BODY>
41 <H1 class="no-header">curs_color 3x</H1>
42 <PRE>
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><H2><a name="h2-NAME">NAME</a></H2><PRE>
49        <STRONG>start_color</STRONG>, <STRONG>init_pair</STRONG>, <STRONG>init_color</STRONG>, <STRONG>has_colors</STRONG>,
50        <STRONG>can_change_color</STRONG>, <STRONG>color_content</STRONG>, <STRONG>pair_content</STRONG>, <STRONG>COLOR_PAIR</STRONG>
51        - <STRONG>curses</STRONG> color manipulation routines
52
53
54 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
55        <STRONG>#</STRONG> <STRONG>include</STRONG> <STRONG>&lt;curses.h&gt;</STRONG>
56
57        <STRONG>int</STRONG> <STRONG>start_color(void);</STRONG>
58        <STRONG>int</STRONG> <STRONG>init_pair(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>f,</STRONG> <STRONG>short</STRONG> <STRONG>b);</STRONG>
59        <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>
60        <STRONG>bool</STRONG> <STRONG>has_colors(void);</STRONG>
61        <STRONG>bool</STRONG> <STRONG>can_change_color(void);</STRONG>
62        <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>
63        <STRONG>*b);</STRONG>
64        <STRONG>int</STRONG> <STRONG>pair_content(short</STRONG> <STRONG>pair,</STRONG> <STRONG>short</STRONG> <STRONG>*f,</STRONG> <STRONG>short</STRONG> <STRONG>*b);</STRONG>
65        <STRONG>int</STRONG> <STRONG>COLOR_PAIR(int</STRONG> <STRONG>n);</STRONG>
66
67
68 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
69
70 </PRE><H3><a name="h3-Overview">Overview</a></H3><PRE>
71        <STRONG>curses</STRONG> supports color attributes on  terminals  with  that
72        capability.   To  use  these  routines <STRONG>start_color</STRONG> must be
73        called, usually right after <STRONG>initscr</STRONG>.   Colors  are  always
74        used  in pairs (referred to as color-pairs).  A color-pair
75        consists of a foreground  color  (for  characters)  and  a
76        background color (for the blank field on which the charac-
77        ters are displayed).  A programmer  initializes  a  color-
78        pair  with  the routine <STRONG>init_pair</STRONG>.  After it has been ini-
79        tialized, <STRONG>COLOR_PAIR</STRONG>(<EM>n</EM>), a macro  defined  in  <STRONG>&lt;curses.h&gt;</STRONG>,
80        can be used as a new video attribute.
81
82        If  a  terminal  is capable of redefining colors, the pro-
83        grammer can use the routine <STRONG>init_color</STRONG> to change the defi-
84        nition   of   a   color.    The  routines  <STRONG>has_colors</STRONG>  and
85        <STRONG>can_change_color</STRONG>  return  <STRONG>TRUE</STRONG>  or  <STRONG>FALSE</STRONG>,  depending   on
86        whether  the  terminal  has color capabilities and whether
87        the programmer can change the colors.   The  routine  <STRONG>col-</STRONG>
88        <STRONG>or_content</STRONG>  allows  a programmer to extract the amounts of
89        red, green, and blue components in an  initialized  color.
90        The  routine  <STRONG>pair_content</STRONG> allows a programmer to find out
91        how a given color-pair is currently defined.
92
93
94 </PRE><H3><a name="h3-Color-Rendering">Color Rendering</a></H3><PRE>
95        The <STRONG>curses</STRONG> library combines these inputs  to  produce  the
96        actual  foreground  and  background  colors  shown  on the
97        screen:
98
99        <STRONG>o</STRONG>   per-character video attributes (e.g., via <STRONG>waddch</STRONG>),
100
101        <STRONG>o</STRONG>   the window attribute (e.g., by <STRONG>wattrset</STRONG>), and
102
103        <STRONG>o</STRONG>   the background character (e.g., <STRONG>wbkgdset</STRONG>).
104
105        Per-character and window attributes are usually set  by  a
106        parameter  containing  video  attributes  including a <STRONG>COL-</STRONG>
107        <STRONG>OR_PAIR</STRONG> value.  Some functions such  as  <STRONG>wattr_set</STRONG>  use  a
108        separate parameter which is the color pair number.
109
110        The  background character is a special case: it includes a
111        character value, just as if it were passed to <STRONG>waddch</STRONG>.
112
113        The <STRONG>curses</STRONG> library does the actual work of combining these
114        color pairs in an internal function called from <STRONG>waddch</STRONG>:
115
116        <STRONG>o</STRONG>   If the parameter passed to <STRONG>waddch</STRONG> is <EM>blank</EM>, and it us-
117            es the special color pair 0,
118
119            <STRONG>o</STRONG>   <STRONG>curses</STRONG> next checks the window attribute.
120
121            <STRONG>o</STRONG>   If the window attribute does not use color pair 0,
122                <STRONG>curses</STRONG>  uses  the  color  pair from the window at-
123                tribute.
124
125            <STRONG>o</STRONG>   Otherwise, <STRONG>curses</STRONG> uses the background character.
126
127        <STRONG>o</STRONG>   If the parameter passed to <STRONG>waddch</STRONG> is <EM>not</EM> <EM>blank</EM>, or  it
128            does  not use the special color pair 0, <STRONG>curses</STRONG> prefers
129            the color pair from the parameter, if it  is  nonzero.
130            Otherwise, it tries the window attribute next, and fi-
131            nally the background character.
132
133        Some <STRONG>curses</STRONG> functions such as <STRONG>wprintw</STRONG> call <STRONG>waddch</STRONG>.   Those
134        do  not  combine  its parameter with a color pair.  Conse-
135        quently those calls use only the window attribute  or  the
136        background character.
137
138
139 </PRE><H3><a name="h3-Routine-Descriptions">Routine Descriptions</a></H3><PRE>
140        The <STRONG>start_color</STRONG> routine requires no arguments.  It must be
141        called if the programmer wants to use colors,  and  before
142        any  other  color  manipulation  routine is called.  It is
143        good practice to call this routine  right  after  <STRONG>initscr</STRONG>.
144        <STRONG>start_color</STRONG> does this:
145
146        <STRONG>o</STRONG>   It  initializes  two global variables, <STRONG>COLORS</STRONG> and <STRONG>COL-</STRONG>
147            <STRONG>OR_PAIRS</STRONG> (respectively defining the maximum number  of
148            colors and color-pairs the terminal can support).
149
150        <STRONG>o</STRONG>   It initializes the special color pair <STRONG>0</STRONG> to the default
151            foreground and  background  colors.   No  other  color
152            pairs are initialized.
153
154        <STRONG>o</STRONG>   It  restores  the colors on the terminal to the values
155            they had when the terminal was just turned on.
156
157        <STRONG>o</STRONG>   If the terminal supports the <STRONG>initc</STRONG>  (<STRONG>initialize_color</STRONG>)
158            capability, <STRONG>start_color</STRONG> initializes its internal table
159            representing the red, green and blue components of the
160            color palette.
161
162            The components depend on whether the terminal uses CGA
163            (aka "ANSI") or HLS (i.e., the <STRONG>hls</STRONG> (<STRONG>hue_lightness_sat-</STRONG>
164            <STRONG>uration</STRONG>) capability is set).  The table is initialized
165            first for eight basic colors (black, red, green,  yel-
166            low,  blue,  magenta, cyan, and white), and after that
167            (if the terminal supports more than eight colors)  the
168            components are initialized to <STRONG>1000</STRONG>.
169
170            <STRONG>start_color</STRONG>  does  not  attempt  to set the terminal's
171            color palette to match its built-in table.  An  appli-
172            cation  may use <STRONG>init_color</STRONG> to alter the internal table
173            along with the terminal's color.
174
175        These limits apply to color values and color pairs.   Val-
176        ues  outside these limits are not legal, and may result in
177        a runtime error:
178
179        <STRONG>o</STRONG>   <STRONG>COLORS</STRONG> corresponds to the terminal database's <STRONG>max_col-</STRONG>
180            <STRONG>ors</STRONG> capability, which is typically a signed 16-bit in-
181            teger (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
182
183        <STRONG>o</STRONG>   color values are expected to be in the range <STRONG>0</STRONG> to <STRONG>COL-</STRONG>
184            <STRONG>ORS-1</STRONG>, inclusive (including <STRONG>0</STRONG> and <STRONG>COLORS-1</STRONG>).
185
186        <STRONG>o</STRONG>   a  special  color value <STRONG>-1</STRONG> is used in certain extended
187            functions to denote the  <EM>default</EM>  <EM>color</EM>  (see  <STRONG>use_de-</STRONG>
188            <STRONG>fault_colors</STRONG>).
189
190        <STRONG>o</STRONG>   <STRONG>COLOR_PAIRS</STRONG>  corresponds  to  the  terminal database's
191            <STRONG>max_pairs</STRONG> capability,  which  is  typically  a  signed
192            16-bit integer (see <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>).
193
194        <STRONG>o</STRONG>   legal  color  pair  values  are in the range <STRONG>1</STRONG> to <STRONG>COL-</STRONG>
195            <STRONG>OR_PAIRS-1</STRONG>, inclusive.
196
197        <STRONG>o</STRONG>   color pair <STRONG>0</STRONG> is special; it denotes "no color".
198
199            Color pair <STRONG>0</STRONG> is assumed to be white on black,  but  is
200            actually whatever the terminal implements before color
201            is initialized.  It cannot be modified by the applica-
202            tion.
203
204        The  <STRONG>init_pair</STRONG>  routine changes the definition of a color-
205        pair.  It takes three arguments: the number of the  color-
206        pair  to  be changed, the foreground color number, and the
207        background color number.  For portable applications:
208
209        <STRONG>o</STRONG>   The first argument must be a legal color  pair  value.
210            If  default  colors  are used (see <STRONG>use_default_colors</STRONG>)
211            the upper limit is adjusted to allow for  extra  pairs
212            which  use  a default color in foreground and/or back-
213            ground.
214
215        <STRONG>o</STRONG>   The second and third arguments  must  be  legal  color
216            values.
217
218        If  the  color-pair was previously initialized, the screen
219        is refreshed and all occurrences of  that  color-pair  are
220        changed to the new definition.
221
222        As  an  extension,  ncurses allows you to set color pair <STRONG>0</STRONG>
223        via the <STRONG>assume_default_colors</STRONG> routine, or to  specify  the
224        use  of  default colors (color number <STRONG>-1</STRONG>) if you first in-
225        voke the <STRONG>use_default_colors</STRONG> routine.
226
227        The <STRONG>init_color</STRONG> routine changes the definition of a  color.
228        It  takes  four  arguments:  the number of the color to be
229        changed followed by three RGB values (for the  amounts  of
230        red, green, and blue components).  The first argument must
231        be a legal color value; default  colors  are  not  allowed
232        here.   (See  the section <STRONG>Colors</STRONG> for the default color in-
233        dex.)  Each of the last three arguments must be a value in
234        the  range  <STRONG>0</STRONG>  through <STRONG>1000</STRONG>.  When <STRONG>init_color</STRONG> is used, all
235        occurrences of that color on the screen immediately change
236        to the new definition.
237
238        The  <STRONG>has_colors</STRONG> routine requires no arguments.  It returns
239        <STRONG>TRUE</STRONG> if the terminal can manipulate colors; otherwise,  it
240        returns <STRONG>FALSE</STRONG>.  This routine facilitates writing terminal-
241        independent programs.  For example, a programmer  can  use
242        it  to decide whether to use color or some other video at-
243        tribute.
244
245        The <STRONG>can_change_color</STRONG> routine requires  no  arguments.   It
246        returns  <STRONG>TRUE</STRONG>  if  the  terminal  supports  colors and can
247        change their definitions; other, it returns  <STRONG>FALSE</STRONG>.   This
248        routine facilitates writing terminal-independent programs.
249
250        The  <STRONG>color_content</STRONG> routine gives programmers a way to find
251        the intensity of the red, green, and blue (RGB) components
252        in a color.  It requires four arguments: the color number,
253        and three addresses of <STRONG>short</STRONG>s for storing the  information
254        about  the  amounts  of red, green, and blue components in
255        the given color.  The first argument must be a legal color
256        value,  i.e.,  <STRONG>0</STRONG>  through <STRONG>COLORS-1</STRONG>, inclusive.  The values
257        that are stored at the addresses pointed to  by  the  last
258        three  arguments are in the range <STRONG>0</STRONG> (no component) through
259        <STRONG>1000</STRONG> (maximum amount of component), inclusive.
260
261        The <STRONG>pair_content</STRONG> routine allows programmers  to  find  out
262        what  colors  a given color-pair consists of.  It requires
263        three arguments: the color-pair number, and two  addresses
264        of  <STRONG>short</STRONG>s  for  storing the foreground and the background
265        color numbers.  The first argument must be a  legal  color
266        value,  i.e., in the range <STRONG>1</STRONG> through <STRONG>COLOR_PAIRS-1</STRONG>, inclu-
267        sive.  The values that are stored at the addresses pointed
268        to  by  the  second and third arguments are in the range <STRONG>0</STRONG>
269        through <STRONG>COLORS</STRONG>, inclusive.
270
271
272 </PRE><H3><a name="h3-Colors">Colors</a></H3><PRE>
273        In <STRONG>&lt;curses.h&gt;</STRONG> the following macros are defined.  These are
274        the  standard colors (ISO-6429).  <STRONG>curses</STRONG> also assumes that
275        <STRONG>COLOR_BLACK</STRONG> is the default background color for all termi-
276        nals.
277
278              <STRONG>COLOR_BLACK</STRONG>
279              <STRONG>COLOR_RED</STRONG>
280              <STRONG>COLOR_GREEN</STRONG>
281              <STRONG>COLOR_YELLOW</STRONG>
282              <STRONG>COLOR_BLUE</STRONG>
283              <STRONG>COLOR_MAGENTA</STRONG>
284              <STRONG>COLOR_CYAN</STRONG>
285              <STRONG>COLOR_WHITE</STRONG>
286
287
288 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
289        The  routines  <STRONG>can_change_color()</STRONG>  and <STRONG>has_colors()</STRONG> return
290        <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>.
291
292        All other routines return the integer <STRONG>ERR</STRONG> upon failure and
293        an  <STRONG>OK</STRONG>  (SVr4  specifies only "an integer value other than
294        <STRONG>ERR</STRONG>") upon successful completion.
295
296        X/Open defines no error conditions.   This  implementation
297        will  return  <STRONG>ERR</STRONG>  on attempts to use color values outside
298        the range <STRONG>0</STRONG> to COLORS-1 (except for the default colors ex-
299        tension),  or  use color pairs outside the range <STRONG>0</STRONG> to <STRONG>COL-</STRONG>
300        <STRONG>OR_PAIRS-1</STRONG>.  Color values used in <STRONG>init_color</STRONG>  must  be  in
301        the  range <STRONG>0</STRONG> to <STRONG>1000</STRONG>.  An error is returned from all func-
302        tions if the terminal has not been initialized.  An  error
303        is  returned from secondary functions such as <STRONG>init_pair</STRONG> if
304        <STRONG>start_color</STRONG> was not called.
305
306           <STRONG>init_color</STRONG>
307                returns an error if the terminal does not  support
308                this  feature, e.g., if the <EM>initialize</EM><STRONG>_</STRONG><EM>color</EM> capa-
309                bility is absent from the terminal description.
310
311           <STRONG>start_color</STRONG>
312                returns an error if the color table cannot be  al-
313                located.
314
315
316 </PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE>
317        In  the  <EM>ncurses</EM> implementation, there is a separate color
318        activation flag, color palette, color pairs table, and as-
319        sociated  COLORS  and  COLOR_PAIRS counts for each screen;
320        the <STRONG>start_color</STRONG> function only affects the current  screen.
321        The SVr4/XSI interface is not really designed with this in
322        mind, and historical  implementations  may  use  a  single
323        shared color palette.
324
325        Note that setting an implicit background color via a color
326        pair affects only character cells that a  character  write
327        operation  explicitly  touches.   To change the background
328        color used when parts of a window are blanked  by  erasing
329        or scrolling operations, see <STRONG><A HREF="curs_bkgd.3x.html">curs_bkgd(3x)</A></STRONG>.
330
331        Several  caveats  apply  on 386 and 486 machines with VGA-
332        compatible graphics:
333
334        <STRONG>o</STRONG>   COLOR_YELLOW is actually brown.  To  get  yellow,  use
335            COLOR_YELLOW combined with the <STRONG>A_BOLD</STRONG> attribute.
336
337        <STRONG>o</STRONG>   The A_BLINK attribute should in theory cause the back-
338            ground to go bright.  This often fails  to  work,  and
339            even some cards for which it mostly works (such as the
340            Paradise and compatibles) do the wrong thing when  you
341            try  to  set  a  bright "yellow" background (you get a
342            blinking yellow foreground instead).
343
344        <STRONG>o</STRONG>   Color RGB values are not settable.
345
346
347 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
348        This implementation satisfies XSI Curses's  minimum  maxi-
349        mums for <STRONG>COLORS</STRONG> and <STRONG>COLOR_PAIRS</STRONG>.
350
351        The  <STRONG>init_pair</STRONG>  routine  accepts  negative values of fore-
352        ground  and  background  color  to  support  the   <STRONG>use_de-</STRONG>
353        <STRONG>fault_colors</STRONG>  extension, but only if that routine has been
354        first invoked.
355
356        The assumption that <STRONG>COLOR_BLACK</STRONG> is the default  background
357        color  for  all  terminals  can  be modified using the <STRONG>as-</STRONG>
358        <STRONG>sume_default_colors</STRONG> extension.
359
360        This implementation checks the  pointers,  e.g.,  for  the
361        values  returned  by  <STRONG>color_content</STRONG>  and <STRONG>pair_content</STRONG>, and
362        will treat those as optional parameters when null.
363
364
365 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
366        <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>
367        <STRONG><A HREF="curs_variables.3x.html">ables(3x)</A></STRONG>, <STRONG><A HREF="default_colors.3x.html">default_colors(3x)</A></STRONG>
368
369
370
371                                                          <STRONG><A HREF="curs_color.3x.html">curs_color(3x)</A></STRONG>
372 </PRE>
373 <div class="nav">
374 <ul>
375 <li><a href="#h2-NAME">NAME</a></li>
376 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
377 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
378 <ul>
379 <li><a href="#h3-Overview">Overview</a></li>
380 <li><a href="#h3-Color-Rendering">Color Rendering</a></li>
381 <li><a href="#h3-Routine-Descriptions">Routine Descriptions</a></li>
382 <li><a href="#h3-Colors">Colors</a></li>
383 </ul>
384 </li>
385 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
386 <li><a href="#h2-NOTES">NOTES</a></li>
387 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
388 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
389 </ul>
390 </div>
391 </BODY>
392 </HTML>