1curs_color(3X)                                                  curs_color(3X)
2
3
4

NAME

6       start_color, init_pair, init_color, has_colors, can_change_color,
7       color_content, pair_content, COLOR_PAIR - curses color manipulation
8       routines
9

SYNOPSIS

11       # include <curses.h>
12       int start_color(void);
13       int init_pair(short pair, short f, short b);
14       int init_color(short color, short r, short g, short b);
15       bool has_colors(void);
16       bool can_change_color(void);
17       int color_content(short color, short *r, short *g, short *b);
18       int pair_content(short pair, short *f, short *b);
19

DESCRIPTION

21   Overview
22       curses  support color attributes on terminals with that capability.  To
23       use these routines start_color must  be  called,  usually  right  after
24       initscr.  Colors are always used in pairs (referred to as color-pairs).
25       A color-pair consists of a foreground  color  (for  characters)  and  a
26       background  color (for the blank field on which the characters are dis‐
27       played).  A  programmer  initializes  a  color-pair  with  the  routine
28       init_pair.   After  it has been initialized, COLOR_PAIR(n), a macro de‐
29       fined in <curses.h>, can be used as a new video attribute.
30
31       If a terminal is capable of redefining colors, the programmer  can  use
32       the  routine  init_color to change the definition of a color.  The rou‐
33       tines has_colors and can_change_color return TRUE or  FALSE,  depending
34       on whether the terminal has color capabilities and whether the program‐
35       mer can change the colors.  The routine color_content allows a program‐
36       mer  to  extract  the  amounts of red, green, and blue components in an
37       initialized color.  The routine pair_content  allows  a  programmer  to
38       find out how a given color-pair is currently defined.
39
40   Routine Descriptions
41       The  start_color  routine  requires no arguments.  It must be called if
42       the programmer wants to use colors, and before any other color  manipu‐
43       lation  routine  is  called.   It is good practice to call this routine
44       right  after  initscr.   start_color  initializes  eight  basic  colors
45       (black,  red,  green,  yellow, blue, magenta, cyan, and white), and two
46       global variables, COLORS and  COLOR_PAIRS  (respectively  defining  the
47       maximum number of colors and color-pairs the terminal can support).  It
48       also restores the colors on the terminal to the values  they  had  when
49       the terminal was just turned on.
50
51       The init_pair routine changes the definition of a color-pair.  It takes
52       three arguments: the number of the color-pair to be changed, the  fore‐
53       ground color number, and the background color number.  For portable ap‐
54       plications:
55
56       -    The value of the  first  argument  must  be  between  1  and  COL‐
57            OR_PAIRS-1,  except  that  if default colors are used (see use_de‐
58            fault_colors) the upper limit is adjusted to allow for extra pairs
59            which use a default color in foreground and/or background.
60
61       -    The  value of the second and third arguments must be between 0 and
62            COLORS.  Color pair 0 is assumed to be white on black, but is  ac‐
63            tually  whatever  the terminal implements before color is initial‐
64            ized.  It cannot be modified by the application.
65
66       If the color-pair was previously initialized, the screen  is  refreshed
67       and  all  occurrences of that color-pair are changed to the new defini‐
68       tion.
69
70       As an extension, ncurses allows you to set color pair  0  via  the  as‐
71       sume_default_colors  routine,  or  to specify the use of default colors
72       (color number -1) if you first invoke the use_default_colors routine.
73
74       The init_color routine changes the definition of  a  color.   It  takes
75       four arguments: the number of the color to be changed followed by three
76       RGB values (for the amounts of red, green, and blue  components).   The
77       value  of  the  first  argument must be between 0 and COLORS.  (See the
78       section Colors for the default color index.)  Each of  the  last  three
79       arguments must be a value between 0 and 1000.  When init_color is used,
80       all occurrences of that color on the screen immediately change  to  the
81       new definition.
82
83       The  has_colors  routine requires no arguments.  It returns TRUE if the
84       terminal can manipulate colors; otherwise, it returns FALSE.  This rou‐
85       tine facilitates writing terminal-independent programs.  For example, a
86       programmer can use it to decide whether to  use  color  or  some  other
87       video attribute.
88
89       The can_change_color routine requires no arguments.  It returns TRUE if
90       the terminal supports colors and can change their  definitions;  other,
91       it  returns  FALSE.  This routine facilitates writing terminal-indepen‐
92       dent programs.
93
94       The color_content routine gives programmers a way to find the intensity
95       of  the  red, green, and blue (RGB) components in a color.  It requires
96       four arguments: the color number, and three  addresses  of  shorts  for
97       storing  the information about the amounts of red, green, and blue com‐
98       ponents in the given color.  The value of the first  argument  must  be
99       between  0  and  COLORS.   The  values that are stored at the addresses
100       pointed to by the last three arguments are between 0 (no component) and
101       1000 (maximum amount of component).
102
103       The  pair_content  routine allows programmers to find out what colors a
104       given color-pair consists of.  It requires three arguments: the  color-
105       pair number, and two addresses of shorts for storing the foreground and
106       the background color numbers.  The value of the first argument must  be
107       between  1  and  COLOR_PAIRS-1.   The values that are stored at the ad‐
108       dresses pointed to by the second and third arguments are between 0  and
109       COLORS.
110
111   Colors
112       In  <curses.h> the following macros are defined.  These are the default
113       colors.  curses also assumes that COLOR_BLACK is the default background
114       color for all terminals.
115
116             COLOR_BLACK
117             COLOR_RED
118             COLOR_GREEN
119             COLOR_YELLOW
120             COLOR_BLUE
121             COLOR_MAGENTA
122             COLOR_CYAN
123             COLOR_WHITE
124

RETURN VALUE

126       The routines can_change_color() and has_colors() return TRUE or FALSE.
127
128       All  other routines return the integer ERR upon failure and an OK (SVr4
129       specifies only "an integer value other than ERR") upon successful  com‐
130       pletion.
131
132       X/Open  defines  no  error conditions.  This implementation will return
133       ERR on attempts to use color values outside the  range  0  to  COLORS-1
134       (except  for  the default colors extension), or use color pairs outside
135       the range 0 to COLOR_PAIR-1.  Color values used in init_color  must  be
136       in the range 0 to 1000.  An error is returned from all functions if the
137       terminal has not been initialized.  An error is returned from secondary
138       functions such as init_pair if start_color was not called.
139
140              init_color
141                   returns an error if the terminal does not support this fea‐
142                   ture, e.g., if the initialize_color  capability  is  absent
143                   from the terminal description.
144
145              start_color
146                   returns an error If the color table cannot be allocated.
147

NOTES

149       In  the  ncurses  implementation,  there is a separate color activation
150       flag, color palette, color pairs table, and associated COLORS and  COL‐
151       OR_PAIRS  counts for each screen; the start_color function only affects
152       the current screen.  The SVr4/XSI interface is not really designed with
153       this  in  mind,  and historical implementations may use a single shared
154       color palette.
155
156       Note that setting an implicit background color via a color pair affects
157       only character cells that a character write operation explicitly touch‐
158       es.  To change the background color used when parts  of  a  window  are
159       blanked by erasing or scrolling operations, see curs_bkgd(3X).
160
161       Several  caveats  apply  on  386  and  486 machines with VGA-compatible
162       graphics:
163
164       -    COLOR_YELLOW is actually brown.  To get yellow,  use  COLOR_YELLOW
165            combined with the A_BOLD attribute.
166
167       -    The  A_BLINK attribute should in theory cause the background to go
168            bright.  This often fails to work, and even some cards  for  which
169            it  mostly  works  (such  as  the Paradise and compatibles) do the
170            wrong thing when you try to set a bright "yellow" background  (you
171            get a blinking yellow foreground instead).
172
173       -    Color RGB values are not settable.
174

PORTABILITY

176       This  implementation satisfies XSI Curses's minimum maximums for COLORS
177       and COLOR_PAIRS.
178
179       The init_pair routine accepts negative values of foreground  and  back‐
180       ground  color  to support the use_default_colors extension, but only if
181       that routine has been first invoked.
182
183       The assumption that COLOR_BLACK is the default background color for all
184       terminals can be modified using the assume_default_colors extension.
185
186       This  implementation checks the pointers, e.g., for the values returned
187       by color_content and pair_content, and will treat those as optional pa‐
188       rameters when null.
189

SEE ALSO

191       curses(3X), curs_initscr(3X), curs_attr(3X), default_colors(3X)
192
193
194
195                                                                curs_color(3X)
Impressum