1curs_color(3CURSES) Curses Library Functions curs_color(3CURSES)
2
3
4
6 curs_color, start_color, init_pair, init_color, has_colors,
7 can_change_color, color_content, pair_content - curses color manipula‐
8 tion functions
9
11 cc [ flag ... ] file ... -lcurses [ library ... ]
12 #include <curses.h>
13
14 int start_color(void);
15
16
17 int init_pair(short pair, short fg, short bg);
18
19
20 int init_color(short color, short red, short green, short blue);
21
22
23 bool has_colors(void);
24
25
26 bool can_change_color(void);
27
28
29 int color_content(short color, short *redp, short *greenp, short *bluep);
30
31
32 int pair_content(short pair, short *fgp, short *bgp);
33
34
36 Overview
37 curses provides routines that manipulate color on color alphanumeric
38 terminals. To use these routines start_color() must be called, usually
39 right after initscr(). See curs_initscr(3CURSES). Colors are always
40 used in pairs (referred to as color-pairs). A color-pair consists of a
41 foreground color (for characters) and a background color (for the field
42 on which the characters are displayed). A programmer initializes a
43 color-pair with the routine init_pair. After it has been initialized,
44 COLOR_PAIR(n), a macro defined in <curses.h>, can be used in the same
45 ways other video attributes can be used. If a terminal is capable of
46 redefining colors, the programmer can use the routine init_color() to
47 change the definition of a color. The routines has_colors() and
48 can_change_color() return TRUE or FALSE, depending on whether the ter‐
49 minal has color capabilities and whether the programmer can change the
50 colors. The routine color_content() allows a programmer to identify the
51 amounts of red, green, and blue components in an initialized color. The
52 routine pair_content() allows a programmer to find out how a given
53 color-pair is currently defined.
54
55 Routine Descriptions
56 The start_color() routine requires no arguments. It must be called if
57 the programmer wants to use colors, and before any other color manipu‐
58 lation routine is called. It is good practice to call this routine
59 right after initscr(). start_color() initializes eight basic colors
60 (black, red, green, yellow, blue, magenta, cyan, and white), and two
61 global variables, COLORS and COLOR_PAIRS (respectively defining the
62 maximum number of colors and color-pairs the terminal can support). It
63 also restores the colors on the terminal to the values they had when
64 the terminal was just turned on.
65
66
67 The init_pair() routine changes the definition of a color-pair. It
68 takes three arguments: the number of the color-pair to be changed, the
69 foreground color number, and the background color number. The value of
70 the first argument must be between 1 and COLOR_PAIRS−1. The value of
71 the second and third arguments must be between 0 and COLORS. If the
72 color-pair was previously initialized, the screen is refreshed and all
73 occurrences of that color-pair is changed to the new definition.
74
75
76 The init_color() routine changes the definition of a color. It takes
77 four arguments: the number of the color to be changed followed by three
78 RGB values (for the amounts of red, green, and blue components). The
79 value of the first argument must be between 0 and COLORS. (See the sec‐
80 tion Colors for the default color index.) Each of the last three argu‐
81 ments must be a value between 0 and 1000. When init_color() is used,
82 all occurrences of that color on the screen immediately change to the
83 new definition.
84
85
86 The has_colors() routine requires no arguments. It returns TRUE if the
87 terminal can manipulate colors; otherwise, it returns FALSE. This rou‐
88 tine facilitates writing terminal-independent programs. For example, a
89 programmer can use it to decide whether to use color or some other
90 video attribute.
91
92
93 The can_change_color() routine requires no arguments. It returns TRUE
94 if the terminal supports colors and can change their definitions;
95 other, it returns FALSE. This routine facilitates writing terminal-
96 independent programs.
97
98
99 The color_content() routine gives users a way to find the intensity of
100 the red, green, and blue (RGB) components in a color. It requires four
101 arguments: the color number, and three addresses of shorts for storing
102 the information about the amounts of red, green, and blue components in
103 the given color. The value of the first argument must be between 0 and
104 COLORS. The values that are stored at the addresses pointed to by the
105 last three arguments are between 0 (no component) and 1000 (maximum
106 amount of component).
107
108
109 The pair_content() routine allows users to find out what colors a given
110 color-pair consists of. It requires three arguments: the color-pair
111 number, and two addresses of shorts for storing the foreground and the
112 background color numbers. The value of the first argument must be
113 between 1 and COLOR_PAIRS−1. The values that are stored at the
114 addresses pointed to by the second and third arguments are between 0
115 and COLORS.
116
117 Colors
118 In <curses.h> the following macros are defined. These are the default
119 colors. curses also assumes that COLOR_BLACK is the default background
120 color for all terminals.
121
122 COLOR_BLACK
123 COLOR_RED
124 COLOR_GREEN
125 COLOR_YELLOW
126 COLOR_BLUE
127 COLOR_MAGENTA
128 COLOR_CYAN
129 COLOR_WHITE
130
131
133 All routines that return an integer return ERR upon failure and OK upon
134 successful completion.
135
137 See attributes(5) for descriptions of the following attributes:
138
139
140
141
142 ┌─────────────────────────────┬─────────────────────────────┐
143 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
144 ├─────────────────────────────┼─────────────────────────────┤
145 │MT-Level │Unsafe │
146 └─────────────────────────────┴─────────────────────────────┘
147
149 curs_attr(3CURSES), curs_initscr(3CURSES), curses(3CURSES),
150 attributes(5)
151
153 The header <curses.h> automatically includes the headers <stdio.h> and
154 <unctrl.h>.
155
156
157
158SunOS 5.11 31 Dec 1996 curs_color(3CURSES)