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