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.
58
59       -    The  value of the second and third arguments must be between 0 and
60            COLORS.  Color pair 0 is assumed to be white on black, but is  ac‐
61            tually  whatever  the terminal implements before color is initial‐
62            ized.  It cannot be modified by the application.
63
64       If the color-pair was previously initialized, the screen  is  refreshed
65       and  all  occurrences of that color-pair are changed to the new defini‐
66       tion.
67
68       As an extension, ncurses allows you to set color pair  0  via  the  as‐
69       sume_default_colors  routine,  or  to specify the use of default colors
70       (color number -1) if you first invoke the use_default_colors routine.
71
72       The init_color routine changes the definition of  a  color.   It  takes
73       four arguments: the number of the color to be changed followed by three
74       RGB values (for the amounts of red, green, and blue  components).   The
75       value  of  the  first  argument must be between 0 and COLORS.  (See the
76       section Colors for the default color index.)  Each of  the  last  three
77       arguments must be a value between 0 and 1000.  When init_color is used,
78       all occurrences of that color on the screen immediately change  to  the
79       new definition.
80
81       The  has_colors  routine requires no arguments.  It returns TRUE if the
82       terminal can manipulate colors; otherwise, it returns FALSE.  This rou‐
83       tine facilitates writing terminal-independent programs.  For example, a
84       programmer can use it to decide whether to  use  color  or  some  other
85       video attribute.
86
87       The can_change_color routine requires no arguments.  It returns TRUE if
88       the terminal supports colors and can change their  definitions;  other,
89       it  returns  FALSE.  This routine facilitates writing terminal-indepen‐
90       dent programs.
91
92       The color_content routine gives programmers a way to find the intensity
93       of  the  red, green, and blue (RGB) components in a color.  It requires
94       four arguments: the color number, and three  addresses  of  shorts  for
95       storing  the information about the amounts of red, green, and blue com‐
96       ponents in the given color.  The value of the first  argument  must  be
97       between  0  and  COLORS.   The  values that are stored at the addresses
98       pointed to by the last three arguments are between 0 (no component) and
99       1000 (maximum amount of component).
100
101       The  pair_content  routine allows programmers to find out what colors a
102       given color-pair consists of.  It requires three arguments: the  color-
103       pair number, and two addresses of shorts for storing the foreground and
104       the background color numbers.  The value of the first argument must  be
105       between  1  and  COLOR_PAIRS-1.   The values that are stored at the ad‐
106       dresses pointed to by the second and third arguments are between 0  and
107       COLORS.
108
109   Colors
110       In  <curses.h> the following macros are defined.  These are the default
111       colors.  curses also assumes that COLOR_BLACK is the default background
112       color for all terminals.
113
114             COLOR_BLACK
115             COLOR_RED
116             COLOR_GREEN
117             COLOR_YELLOW
118             COLOR_BLUE
119             COLOR_MAGENTA
120             COLOR_CYAN
121             COLOR_WHITE
122

RETURN VALUE

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

NOTES

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

PORTABILITY

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

SEE ALSO

189       curses(3X), curs_initscr(3X), curs_attr(3X), default_colors(3X)
190
191
192
193                                                                curs_color(3X)
Impressum