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
13       int start_color(void);
14       int init_pair(short pair, short f, short b);
15       int init_color(short color, short r, short g, short b);
16       bool has_colors(void);
17       bool can_change_color(void);
18       int color_content(short color, short *r, short *g, short *b);
19       int pair_content(short pair, short *f, short *b);
20

DESCRIPTION

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

RETURN VALUE

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

NOTES

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

PORTABILITY

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

SEE ALSO

192       curses(3X),  curs_initscr(3X),  curs_attr(3X),  curs_variables(3X), de‐
193       fault_colors(3X)
194
195
196
197                                                                curs_color(3X)
Impressum