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

NAME

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

SYNOPSIS

11       #include <curses.h>
12
13       int start_color(void);
14
15       bool has_colors(void);
16       bool can_change_color(void);
17
18       int init_pair(short pair, short f, short b);
19       int init_color(short color, short r, short g, short b);
20       /* extensions */
21       int init_extended_pair(int pair, int f, int b);
22       int init_extended_color(int color, int r, int g, int b);
23
24       int color_content(short color, short *r, short *g, short *b);
25       int pair_content(short pair, short *f, short *b);
26       /* extensions */
27       int extended_color_content(int color, int *r, int *g, int *b);
28       int extended_pair_content(int pair, int *f, int *b);
29
30       /* extensions */
31       void reset_color_pairs(void);
32
33       int COLOR_PAIR(int n);
34       PAIR_NUMBER(attrs);
35

DESCRIPTION

37   Overview
38       curses supports color attributes on terminals with that capability.  To
39       use these routines start_color must  be  called,  usually  right  after
40       initscr.  Colors are always used in pairs (referred to as color-pairs).
41       A color-pair consists of a foreground  color  (for  characters)  and  a
42       background  color (for the blank field on which the characters are dis‐
43       played).  A  programmer  initializes  a  color-pair  with  the  routine
44       init_pair.  After it has been initialized, COLOR_PAIR(n) can be used to
45       convert the pair to a video attribute.
46
47       If a terminal is capable of redefining colors, the programmer  can  use
48       the  routine  init_color to change the definition of a color.  The rou‐
49       tines has_colors and can_change_color return TRUE or  FALSE,  depending
50       on whether the terminal has color capabilities and whether the program‐
51       mer can change the colors.  The routine color_content allows a program‐
52       mer  to  extract  the  amounts of red, green, and blue components in an
53       initialized color.  The routine pair_content  allows  a  programmer  to
54       find out how a given color-pair is currently defined.
55
56   Color Rendering
57       The  curses  library  combines these inputs to produce the actual fore‐
58       ground and background colors shown on the screen:
59
60       ·   per-character video attributes (e.g., via waddch),
61
62       ·   the window attribute (e.g., by wattrset), and
63
64       ·   the background character (e.g., wbkgdset).
65
66       Per-character and window attributes are usually set by a parameter con‐
67       taining  video attributes including a color pair value.  Some functions
68       such as wattr_set use a separate parameter which is the color pair num‐
69       ber.
70
71       The  background  character  is  a special case: it includes a character
72       value, just as if it were passed to waddch.
73
74       The curses library does the actual work of combining these color  pairs
75       in an internal function called from waddch:
76
77       ·   If the parameter passed to waddch is blank, and it uses the special
78           color pair 0,
79
80           ·   curses next checks the window attribute.
81
82           ·   If the window attribute does not use color pair 0, curses  uses
83               the color pair from the window attribute.
84
85           ·   Otherwise, curses uses the background character.
86
87       ·   If  the parameter passed to waddch is not blank, or it does not use
88           the special color pair 0, curses prefers the color  pair  from  the
89           parameter,  if  it  is nonzero.  Otherwise, it tries the window at‐
90           tribute next, and finally the background character.
91
92       Some curses functions such as wprintw call waddch.  Those do  not  com‐
93       bine its parameter with a color pair.  Consequently those calls use on‐
94       ly the window attribute or the background character.
95

CONSTANTS

97       In <curses.h> the following macros are defined.  These are the standard
98       colors (ISO-6429).  curses also assumes that COLOR_BLACK is the default
99       background color for all terminals.
100
101             COLOR_BLACK
102             COLOR_RED
103             COLOR_GREEN
104             COLOR_YELLOW
105             COLOR_BLUE
106             COLOR_MAGENTA
107             COLOR_CYAN
108             COLOR_WHITE
109
110       Some terminals support more than the eight (8)  “ANSI”  colors.   There
111       are no standard names for those additional colors.
112

VARIABLES

114   COLORS
115       is  initialized by start_color to the maximum number of colors the ter‐
116       minal can support.
117
118   COLOR_PAIRS
119       is initialized by start_color to the maximum number of color pairs  the
120       terminal can support.
121

FUNCTIONS

123   start_color
124       The  start_color  routine  requires no arguments.  It must be called if
125       the programmer wants to use colors, and before any other color  manipu‐
126       lation  routine  is  called.   It is good practice to call this routine
127       right after initscr.  start_color does this:
128
129       ·   It initializes two global variables, COLORS  and  COLOR_PAIRS  (re‐
130           spectively  defining  the  maximum number of colors and color-pairs
131           the terminal can support).
132
133       ·   It initializes the special color pair 0 to the  default  foreground
134           and background colors.  No other color pairs are initialized.
135
136       ·   It  restores the colors on the terminal to the values they had when
137           the terminal was just turned on.
138
139       ·   If the terminal supports the initc  (initialize_color)  capability,
140           start_color  initializes  its  internal table representing the red,
141           green and blue components of the color palette.
142
143           The components depend on whether the terminal uses CGA (aka “ANSI”)
144           or  HLS  (i.e.,  the  hls  (hue_lightness_saturation) capability is
145           set).  The table  is  initialized  first  for  eight  basic  colors
146           (black,  red,  green,  yellow, blue, magenta, cyan, and white), and
147           after that (if the terminal supports more than  eight  colors)  the
148           components are initialized to 1000.
149
150           start_color does not attempt to set the terminal's color palette to
151           match its built-in table.  An application may use init_color to al‐
152           ter the internal table along with the terminal's color.
153
154       These  limits  apply  to  color values and color pairs.  Values outside
155       these limits are not legal, and may result in a runtime error:
156
157       ·   COLORS corresponds to the terminal database's max_colors  capabili‐
158           ty, (see terminfo(5)).
159
160       ·   color  values are expected to be in the range 0 to COLORS-1, inclu‐
161           sive (including 0 and COLORS-1).
162
163       ·   a special color value -1 is used in certain extended  functions  to
164           denote the default color (see use_default_colors).
165
166       ·   COLOR_PAIRS  corresponds to the terminal database's max_pairs capa‐
167           bility, (see terminfo(5)).
168
169       ·   legal color pair values are in the range 1 to COLOR_PAIRS-1, inclu‐
170           sive.
171
172       ·   color pair 0 is special; it denotes “no color”.
173
174           Color pair 0 is assumed to be white on black, but is actually what‐
175           ever the terminal implements before color is initialized.  It  can‐
176           not be modified by the application.
177
178   has_colors
179       The  has_colors  routine requires no arguments.  It returns TRUE if the
180       terminal can manipulate colors; otherwise, it returns FALSE.  This rou‐
181       tine facilitates writing terminal-independent programs.  For example, a
182       programmer can use it to decide whether to  use  color  or  some  other
183       video attribute.
184
185   can_change_color
186       The can_change_color routine requires no arguments.  It returns TRUE if
187       the terminal supports colors and can change their  definitions;  other,
188       it  returns  FALSE.  This routine facilitates writing terminal-indepen‐
189       dent programs.
190
191   init_pair
192       The init_pair routine changes the definition of a color-pair.  It takes
193       three  arguments: the number of the color-pair to be changed, the fore‐
194       ground color number, and the background color number.  For portable ap‐
195       plications:
196
197       ·   The  first  argument  must be a legal color pair value.  If default
198           colors are used (see use_default_colors) the upper limit is adjust‐
199           ed to allow for extra pairs which use a default color in foreground
200           and/or background.
201
202       ·   The second and third arguments must be legal color values.
203
204       If the color-pair was previously initialized, the screen  is  refreshed
205       and  all  occurrences of that color-pair are changed to the new defini‐
206       tion.
207
208       As an extension, ncurses allows you to set color pair  0  via  the  as‐
209       sume_default_colors(3X)  routine, or to specify the use of default col‐
210       ors (color number -1) if you first  invoke  the  use_default_colors(3X)
211       routine.
212
213       The  extension  reset_color_pairs  tells  ncurses to discard all of the
214       color-pair information which was set with init_pair.  It  also  touches
215       the  current-  and  standard-screens, allowing an application to switch
216       color palettes rapidly.
217
218   init_color
219       The init_color routine changes the definition of  a  color.   It  takes
220       four arguments: the number of the color to be changed followed by three
221       RGB values (for the amounts of red, green, and blue components).
222
223       ·   The first argument must be a legal color value; default colors  are
224           not  allowed  here.   (See the section Colors for the default color
225           index.)
226
227       ·   Each of the last three arguments must be a value  in  the  range  0
228           through 1000.
229
230       When  init_color  is  used, all occurrences of that color on the screen
231       immediately change to the new definition.
232
233   color_content
234       The color_content routine gives programmers a way to find the intensity
235       of  the  red, green, and blue (RGB) components in a color.  It requires
236       four arguments: the color number, and three  addresses  of  shorts  for
237       storing  the information about the amounts of red, green, and blue com‐
238       ponents in the given color.
239
240       ·   The first argument must be a legal color  value,  i.e.,  0  through
241           COLORS-1, inclusive.
242
243       ·   The  values that are stored at the addresses pointed to by the last
244           three arguments are in the range  0  (no  component)  through  1000
245           (maximum amount of component), inclusive.
246
247   pair_content
248       The  pair_content  routine allows programmers to find out what colors a
249       given color-pair consists of.  It requires three arguments: the  color-
250       pair number, and two addresses of shorts for storing the foreground and
251       the background color numbers.
252
253       ·   The first argument must be a legal color value, i.e., in the  range
254           1 through COLOR_PAIRS-1, inclusive.
255
256       ·   The  values that are stored at the addresses pointed to by the sec‐
257           ond and third arguments are in the range 0 through  COLORS,  inclu‐
258           sive.
259
260   PAIR_NUMBER
261       PAIR_NUMBER(attrs)  extracts  the  color value from its attrs parameter
262       and returns it as a color pair number.
263
264   COLOR_PAIR
265       Its inverse COLOR_PAIR(n) converts a color pair number to an attribute.
266       Attributes  can  hold color pairs in the range 0 to 255.  If you need a
267       color pair larger than that, you must use functions  such  as  attr_set
268       (which  pass  the  color  pair as a separate parameter) rather than the
269       legacy functions such as attrset.
270

RETURN VALUE

272       The routines can_change_color and has_colors return TRUE or FALSE.
273
274       All other routines return the integer ERR upon failure and an OK  (SVr4
275       specifies  only “an integer value other than ERR”) upon successful com‐
276       pletion.
277
278       X/Open defines no error conditions.  This  implementation  will  return
279       ERR  on  attempts  to  use color values outside the range 0 to COLORS-1
280       (except for the default colors extension), or use color  pairs  outside
281       the  range 0 to COLOR_PAIRS-1.  Color values used in init_color must be
282       in the range 0 to 1000.  An error is returned from all functions if the
283       terminal has not been initialized.  An error is returned from secondary
284       functions such as init_pair if start_color was not called.
285
286          init_color
287               returns an error if the terminal does not support this feature,
288               e.g.,  if  the  initialize_color  capability is absent from the
289               terminal description.
290
291          start_color
292               returns an error if the color table cannot be allocated.
293

NOTES

295       In the ncurses implementation, there is  a  separate  color  activation
296       flag,  color palette, color pairs table, and associated COLORS and COL‐
297       OR_PAIRS counts for each screen; the start_color function only  affects
298       the current screen.  The SVr4/XSI interface is not really designed with
299       this in mind, and historical implementations may use  a  single  shared
300       color palette.
301
302       Setting  an  implicit  background  color  via a color pair affects only
303       character cells that a character write  operation  explicitly  touches.
304       To  change the background color used when parts of a window are blanked
305       by erasing or scrolling operations, see curs_bkgd(3X).
306
307       Several caveats apply on older x86 machines  (e.g.,  i386,  i486)  with
308       VGA-compatible graphics:
309
310       ·   COLOR_YELLOW  is  actually  brown.  To get yellow, use COLOR_YELLOW
311           combined with the A_BOLD attribute.
312
313       ·   The A_BLINK attribute should in theory cause the background  to  go
314           bright.  This often fails to work, and even some cards for which it
315           mostly works (such as the Paradise and compatibles)  do  the  wrong
316           thing  when  you try to set a bright “yellow” background (you get a
317           blinking yellow foreground instead).
318
319       ·   Color RGB values are not settable.
320

PORTABILITY

322       This implementation satisfies XSI Curses's minimum maximums for  COLORS
323       and COLOR_PAIRS.
324
325       The  init_pair  routine accepts negative values of foreground and back‐
326       ground color to support the use_default_colors(3X) extension, but  only
327       if that routine has been first invoked.
328
329       The assumption that COLOR_BLACK is the default background color for all
330       terminals can be modified using  the  assume_default_colors(3X)  exten‐
331       sion.
332
333       This  implementation checks the pointers, e.g., for the values returned
334       by color_content and pair_content, and will treat those as optional pa‐
335       rameters when null.
336
337       X/Open  Curses  does  not  specify a limit for the number of colors and
338       color pairs which a terminal can support.  However, in its use of short
339       for  the  parameters,  it carries over SVr4's implementation detail for
340       the compiled terminfo database, which uses signed 16-bit numbers.  This
341       implementation  provides extended versions of those functions which use
342       short parameters, allowing applications to use larger color- and  pair-
343       numbers.
344
345       The reset_color_pairs function is an extension of ncurses.
346

SEE ALSO

348       curses(3X),  curs_initscr(3X),  curs_attr(3X),  curs_variables(3X), de‐
349       fault_colors(3X)
350
351
352
353                                                                curs_color(3X)
Impressum