1curs_attr(3X) curs_attr(3X)
2
3
4
6 attr_get, wattr_get, attr_set, wattr_set, attr_off, wattr_off, attr_on,
7 wattr_on, attroff, wattroff, attron, wattron, attrset, wattrset, chgat,
8 wchgat, mvchgat, mvwchgat, color_set, wcolor_set, standend, wstandend,
9 standout, wstandout - curses character and window attribute control
10 routines
11
13 #include <curses.h>
14
15 int attr_get(attr_t *attrs, short *pair, void *opts);
16 int wattr_get(WINDOW *win, attr_t *attrs, short *pair, void *opts);
17 int attr_set(attr_t attrs, short pair, void *opts);
18 int wattr_set(WINDOW *win, attr_t attrs, short pair, void *opts);
19
20 int attr_off(attr_t attrs, void *opts);
21 int wattr_off(WINDOW *win, attr_t attrs, void *opts);
22 int attr_on(attr_t attrs, void *opts);
23 int wattr_on(WINDOW *win, attr_t attrs, void *opts);
24
25 int attroff(int attrs);
26 int wattroff(WINDOW *win, int attrs);
27 int attron(int attrs);
28 int wattron(WINDOW *win, int attrs);
29 int attrset(int attrs);
30 int wattrset(WINDOW *win, int attrs);
31
32 int chgat(int n, attr_t attr, short pair, const void *opts);
33 int wchgat(WINDOW *win,
34 int n, attr_t attr, short pair, const void *opts);
35 int mvchgat(int y, int x,
36 int n, attr_t attr, short pair, const void *opts);
37 int mvwchgat(WINDOW *win, int y, int x,
38 int n, attr_t attr, short pair, const void *opts);
39
40 int color_set(short pair, void* opts);
41 int wcolor_set(WINDOW *win, short pair, void* opts);
42
43 int standend(void);
44 int wstandend(WINDOW *win);
45 int standout(void);
46 int wstandout(WINDOW *win);
47
49 These routines manipulate the current attributes of the named window,
50 which then apply to all characters that are written into the window
51 with waddch, waddstr and wprintw. Attributes are a property of the
52 character, and move with the character through any scrolling and in‐
53 sert/delete line/character operations. To the extent possible, they
54 are displayed as appropriate modifications to the graphic rendition of
55 characters put on the screen.
56
57 These routines do not affect the attributes used when erasing portions
58 of the window. See curs_bkgd(3X) for functions which modify the at‐
59 tributes used for erasing and clearing.
60
61 Routines which do not have a WINDOW* parameter apply to stdscr. For
62 example, attr_set is the stdscr variant of wattr_set.
63
64 Window attributes
65 There are two sets of functions:
66
67 · functions for manipulating the window attributes and color: wat‐
68 tr_set and wattr_get.
69
70 · functions for manipulating only the window attributes (not color):
71 wattr_on and wattr_off.
72
73 The wattr_set function sets the current attributes of the given window
74 to attrs, with color specified by pair.
75
76 Use wattr_get to retrieve attributes for the given window.
77
78 Use attr_on and wattr_on to turn on window attributes, i.e., values
79 OR'd together in attr, without affecting other attributes. Use at‐
80 tr_off and wattr_off to turn off window attributes, again values OR'd
81 together in attr, without affecting other attributes.
82
83 Legacy window attributes
84 The X/Open window attribute routines which set or get, turn on or off
85 are extensions of older routines which assume that color pairs are OR'd
86 into the attribute parameter. These newer routines use similar names,
87 because X/Open simply added an underscore (_) for the newer names.
88
89 The int datatype used in the legacy routines is treated as if it is the
90 same size as chtype (used by addch(3X)). It holds the common video at‐
91 tributes (such as bold, reverse), as well as a few bits for color.
92 Those bits correspond to the A_COLOR symbol. The COLOR_PAIR macro pro‐
93 vides a value which can be OR'd into the attribute parameter. For ex‐
94 ample, as long as that value fits into the A_COLOR mask, then these
95 calls produce similar results:
96
97 attrset(A_BOLD | COLOR_PAIR(pair));
98 attr_set(A_BOLD, pair, NULL);
99
100 However, if the value does not fit, then the COLOR_PAIR macro uses only
101 the bits that fit. For example, because in ncurses A_COLOR has eight
102 (8) bits, then COLOR_PAIR(259) is 4 (259-255).
103
104 The PAIR_NUMBER macro extracts a pair number from an int (or chtype).
105 For example, the input and output values in these statements would be
106 the same:
107
108 int value = A_BOLD | COLOR_PAIR(input);
109 int output = PAIR_NUMBER(value);
110
111 The attrset routine is a legacy feature predating SVr4 curses but kept
112 in X/Open Curses for the same reason that SVr4 curses kept it: compati‐
113 bility.
114
115 The remaining attr* functions operate exactly like the corresponding
116 attr_* functions, except that they take arguments of type int rather
117 than attr_t.
118
119 There is no corresponding attrget function as such in X/Open Curses,
120 although ncurses provides getattrs (see curs_legacy(3X)).
121
122 Change character rendition
123 The routine chgat changes the attributes of a given number of charac‐
124 ters starting at the current cursor location of stdscr. It does not
125 update the cursor and does not perform wrapping. A character count of
126 -1 or greater than the remaining window width means to change at‐
127 tributes all the way to the end of the current line. The wchgat func‐
128 tion generalizes this to any window; the mvwchgat function does a cur‐
129 sor move before acting.
130
131 In these functions, the color pair argument is a color-pair index (as
132 in the first argument of init_pair, see curs_color(3X)).
133
134 Change window color
135 The routine color_set sets the current color of the given window to the
136 foreground/background combination described by the color pair parame‐
137 ter.
138
139 Standout
140 The routine standout is the same as attron(A_STANDOUT). The routine
141 standend is the same as attrset(A_NORMAL) or attrset(0), that is, it
142 turns off all attributes.
143
144 X/Open does not mark these "restricted", because
145
146 · they have well established legacy use, and
147
148 · there is no ambiguity about the way the attributes might be com‐
149 bined with a color pair.
150
152 The following video attributes, defined in <curses.h>, can be passed to
153 the routines attron, attroff, and attrset, or OR'd with the characters
154 passed to addch (see curs_addch(3X)).
155
156 Name Description
157 ─────────────────────────────────────────────────────────────────
158 A_NORMAL Normal display (no highlight)
159 A_STANDOUT Best highlighting mode of the terminal.
160 A_UNDERLINE Underlining
161 A_REVERSE Reverse video
162 A_BLINK Blinking
163 A_DIM Half bright
164 A_BOLD Extra bright or bold
165 A_PROTECT Protected mode
166 A_INVIS Invisible or blank mode
167 A_ALTCHARSET Alternate character set
168 A_ITALIC Italics (non-X/Open extension)
169 A_CHARTEXT Bit-mask to extract a character
170 A_COLOR Bit-mask to extract a color (legacy routines)
171
172 These video attributes are supported by attr_on and related functions
173 (which also support the attributes recognized by attron, etc.):
174
175 Name Description
176 ─────────────────────────────────────────
177 WA_HORIZONTAL Horizontal highlight
178 WA_LEFT Left highlight
179 WA_LOW Low highlight
180 WA_RIGHT Right highlight
181 WA_TOP Top highlight
182 WA_VERTICAL Vertical highlight
183
184 The return values of many of these routines are not meaningful (they
185 are implemented as macro-expanded assignments and simply return their
186 argument). The SVr4 manual page claims (falsely) that these routines
187 always return 1.
188
190 These functions may be macros:
191
192 attroff, wattroff, attron, wattron, attrset, wattrset, standend
193 and standout.
194
195 Color pair values can only be OR'd with attributes if the pair number
196 is less than 256. The alternate functions such as color_set can pass a
197 color pair value directly. However, ncurses ABI 4 and 5 simply OR this
198 value within the alternate functions. You must use ncurses ABI 6 to
199 support more than 256 color pairs.
200
202 X/Open Curses is largely based on SVr4 curses, adding support for
203 “wide-characters” (not specific to Unicode). Some of the X/Open dif‐
204 ferences from SVr4 curses address the way video attributes can be ap‐
205 plied to wide-characters. But aside from that, attrset and attr_set
206 are similar. SVr4 curses provided the basic features for manipulating
207 video attributes. However, earlier versions of curses provided a part
208 of these features.
209
210 As seen in 2.8BSD, curses assumed 7-bit characters, using the eighth
211 bit of a byte to represent the standout feature (often implemented as
212 bold and/or reverse video). The BSD curses library provided functions
213 standout and standend which were carried along into X/Open Curses due
214 to their pervasive use in legacy applications.
215
216 Some terminals in the 1980s could support a variety of video at‐
217 tributes, although the BSD curses library could do nothing with those.
218 System V (1983) provided an improved curses library. It defined the A_
219 symbols for use by applications to manipulate the other attributes.
220 There are few useful references for the chronology.
221
222 Goodheart's book UNIX Curses Explained (1991) describes SVr3 (1987),
223 commenting on several functions:
224
225 · the attron, attroff, attrset functions (and most of the functions
226 found in SVr4 but not in BSD curses) were introduced by System V,
227
228 · the alternate character set feature with A_ALTCHARSET was added in
229 SVr2 and improved in SVr3 (by adding acs_map[]),
230
231 · start_color and related color-functions were introduced by System
232 V.3.2,
233
234 · pads, soft-keys were added in SVr3, and
235
236 Goodheart did not mention the background character or the cchar_t type.
237 Those are respectively SVr4 and X/Open features. He did mention the A_
238 constants, but did not indicate their values. Those were not the same
239 in different systems, even for those marked as System V.
240
241 Different Unix systems used different sizes for the bit-fields in
242 chtype for characters and colors, and took into account the different
243 integer sizes (32-bit versus 64-bit).
244
245 This table showing the number of bits for A_COLOR and A_CHARTEXT was
246 gleaned from the curses header files for various operating systems and
247 architectures. The inferred architecture and notes reflect the format
248 and size of the defined constants as well as clues such as the alter‐
249 nate character set implementation. A 32-bit library can be used on a
250 64-bit system, but not necessarily the reverse.
251
252 Year System Arch Color Char Notes
253 ────────────────────────────────────────────────────────────────
254 1992 Solaris 5.2 32 6 17 SVr4 curses
255 1992 HPUX 9 32 no 8 SVr2 curses
256 1992 AIX 3.2 32 no 23 SVr2 curses
257 1994 OSF/1 r3 32 no 23 SVr2 curses
258 1995 HP-UX 10.00 32 6 16 SVr3 “curses_colr”
259 1995 HP-UX 10.00 32 6 8 SVr4, X/Open curses
260 1995 Solaris 5.4 32/64 7 16 X/Open curses
261 1996 AIX 4.2 32 7 16 X/Open curses
262 1996 OSF/1 r4 32 6 16 X/Open curses
263 1997 HP-UX 11.00 32 6 8 X/Open curses
264
265 2000 U/Win 32/64 7/31 16 uses chtype
266
267 Notes:
268
269 Regarding HP-UX,
270
271 · HP-UX 10.20 (1996) added support for 64-bit PA-RISC processors
272 in 1996.
273
274 · HP-UX 10.30 (1997) marked “curses_colr” obsolete. That version
275 of curses was dropped with HP-UX 11.30 in 2006.
276
277 Regarding OSF/1 (and Tru64),
278
279 · These used 64-bit hardware. Like ncurses, the OSF/1 curses in‐
280 terface is not customized for 32-bit and 64-bit versions.
281
282 · Unlike other systems which evolved from AT&T code, OSF/1 provid‐
283 ed a new implementation for X/Open curses.
284
285 Regarding Solaris,
286
287 · The initial release of Solaris was in 1992.
288
289 · The xpg4 (X/Open) curses was developed by MKS from 1990 to 1995.
290 Sun's copyright began in 1996.
291
292 · Sun updated the X/Open curses interface after 64-bit support was
293 introduced in 1997, but did not modify the SVr4 curses inter‐
294 face.
295
296 Regarding U/Win,
297
298 · Development of the curses library began in 1991, stopped in
299 2000.
300
301 · Color support was added in 1998.
302
303 · The library uses only chtype (no cchar_t).
304
305 Once X/Open curses was adopted in the mid-1990s, the constraint of a
306 32-bit interface with many colors and wide-characters for chtype became
307 a moot point. The cchar_t structure (whose size and members are not
308 specified in X/Open Curses) could be extended as needed.
309
310 Other interfaces are rarely used now:
311
312 · BSD curses was improved slightly in 1993/1994 using Keith Bostic's
313 modification to make the library 8-bit clean for nvi. He moved
314 standout attribute to a structure member.
315
316 The resulting 4.4BSD curses was replaced by ncurses over the next
317 ten years.
318
319 · U/Win is rarely used now.
320
322 This implementation provides the A_ITALIC attribute for terminals which
323 have the enter_italics_mode (sitm) and exit_italics_mode (ritm) capa‐
324 bilities. Italics are not mentioned in X/Open Curses. Unlike the oth‐
325 er video attributes, A_ITALIC is unrelated to the set_attributes capa‐
326 bilities. This implementation makes the assumption that exit_at‐
327 tribute_mode may also reset italics.
328
329 Each of the functions added by XSI Curses has a parameter opts, which
330 X/Open Curses still (after more than twenty years) documents as re‐
331 served for future use, saying that it should be NULL. This implementa‐
332 tion uses that parameter in ABI 6 for the functions which have a color-
333 pair parameter to support extended color pairs:
334
335 · For functions which modify the color, e.g., wattr_set, if opts is
336 set it is treated as a pointer to int, and used to set the color
337 pair instead of the short pair parameter.
338
339 · For functions which retrieve the color, e.g., wattr_get, if opts is
340 set it is treated as a pointer to int, and used to retrieve the
341 color pair as an int value, in addition retrieving it via the stan‐
342 dard pointer to short parameter.
343
344 The remaining functions which have opts, but do not manipulate color,
345 e.g., wattr_on and wattr_off are not used by this implementation except
346 to check that they are NULL.
347
349 These functions are supported in the XSI Curses standard, Issue 4. The
350 standard defined the dedicated type for highlights, attr_t, which was
351 not defined in SVr4 curses. The functions taking attr_t arguments were
352 not supported under SVr4.
353
354 Very old versions of this library did not force an update of the screen
355 when changing the attributes. Use touchwin to force the screen to
356 match the updated attributes.
357
358 The XSI Curses standard states that whether the traditional functions
359 attron/attroff/attrset can manipulate attributes other than A_BLINK,
360 A_BOLD, A_DIM, A_REVERSE, A_STANDOUT, or A_UNDERLINE is "unspecified".
361 Under this implementation as well as SVr4 curses, these functions cor‐
362 rectly manipulate all other highlights (specifically, A_ALTCHARSET,
363 A_PROTECT, and A_INVIS).
364
365 XSI Curses added these entry points:
366
367 attr_get, attr_on, attr_off, attr_set, wattr_on, wattr_off, wat‐
368 tr_get, wattr_set
369
370 The new functions are intended to work with a new series of highlight
371 macros prefixed with WA_. The older macros have direct counterparts in
372 the newer set of names:
373
374 Name Description
375 ────────────────────────────────────────────────────────────
376 WA_NORMAL Normal display (no highlight)
377 WA_STANDOUT Best highlighting mode of the terminal.
378 WA_UNDERLINE Underlining
379 WA_REVERSE Reverse video
380 WA_BLINK Blinking
381 WA_DIM Half bright
382 WA_BOLD Extra bright or bold
383 WA_ALTCHARSET Alternate character set
384
385 XSI curses does not assign values to these symbols, nor does it state
386 whether or not they are related to the similarly-named A_NORMAL, etc.:
387
388 · The XSI curses standard specifies that each pair of corresponding
389 A_ and WA_-using functions operates on the same current-highlight
390 information.
391
392 · However, in some implementations, those symbols have unrelated val‐
393 ues.
394
395 For example, the Solaris xpg4 (X/Open) curses declares attr_t to be
396 an unsigned short integer (16-bits), while chtype is a unsigned in‐
397 teger (32-bits). The WA_ symbols in this case are different from
398 the A_ symbols because they are used for a smaller datatype which
399 does not represent A_CHARTEXT or A_COLOR.
400
401 In this implementation (as in many others), the values happen to be
402 the same because it simplifies copying information between chtype
403 and cchar_t variables.
404
405 The XSI standard extended conformance level adds new highlights A_HORI‐
406 ZONTAL, A_LEFT, A_LOW, A_RIGHT, A_TOP, A_VERTICAL (and corresponding
407 WA_ macros for each). As of August 2013, no known terminal provides
408 these highlights (i.e., via the sgr1 capability).
409
411 All routines return the integer OK on success, or ERR on failure.
412
413 X/Open does not define any error conditions.
414
415 This implementation
416
417 · returns an error if the window pointer is null.
418
419 · returns an error if the color pair parameter for wcolor_set is out‐
420 side the range 0..COLOR_PAIRS-1.
421
422 · does not return an error if either of the parameters of wattr_get
423 used for retrieving attribute or color-pair values is NULL.
424
425 Functions with a "mv" prefix first perform a cursor movement using
426 wmove, and return an error if the position is outside the window, or if
427 the window pointer is null.
428
430 curses(3X), curs_addch(3X), curs_addstr(3X), curs_bkgd(3X),
431 curs_printw(3X), curs_variables(3X)
432
433
434
435 curs_attr(3X)