1curs_attr(3X)                                                    curs_attr(3X)
2
3
4

NAME

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

SYNOPSIS

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

DESCRIPTION

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 (i.e., 259 is 4 more than the limit
103       255).
104
105       The PAIR_NUMBER macro extracts a pair number from an int  (or  chtype).
106       For  example,  the input and output values in these statements would be
107       the same:
108
109           int value = A_BOLD | COLOR_PAIR(input);
110           int output = PAIR_NUMBER(value);
111
112       The attrset routine is a legacy feature predating SVr4 curses but  kept
113       in X/Open Curses for the same reason that SVr4 curses kept it: compati‐
114       bility.
115
116       The remaining attr* functions operate exactly  like  the  corresponding
117       attr_*  functions,  except  that they take arguments of type int rather
118       than attr_t.
119
120       There is no corresponding attrget function as such  in  X/Open  Curses,
121       although ncurses provides getattrs (see curs_legacy(3X)).
122
123   Change character rendition
124       The  routine  chgat changes the attributes of a given number of charac‐
125       ters starting at the current cursor location of stdscr.   It  does  not
126       update  the cursor and does not perform wrapping.  A character count of
127       -1 or greater than the remaining  window  width  means  to  change  at‐
128       tributes  all the way to the end of the current line.  The wchgat func‐
129       tion generalizes this to any window; the mvwchgat function does a  cur‐
130       sor move before acting.
131
132       In  these  functions, the color pair argument is a color-pair index (as
133       in the first argument of init_pair, see curs_color(3X)).
134
135   Change window color
136       The routine color_set sets the current color of the given window to the
137       foreground/background  combination  described by the color pair parame‐
138       ter.
139
140   Standout
141       The routine standout is the same as  attron(A_STANDOUT).   The  routine
142       standend  is  the  same as attrset(A_NORMAL) or attrset(0), that is, it
143       turns off all attributes.
144
145       X/Open does not mark these "restricted", because
146
147       ·   they have well established legacy use, and
148
149       ·   there is no ambiguity about the way the attributes  might  be  com‐
150           bined with a color pair.
151

VIDEO ATTRIBUTES

153       The following video attributes, defined in <curses.h>, can be passed to
154       the routines attron, attroff, and attrset, or OR'd with the  characters
155       passed to addch (see curs_addch(3X)).
156
157              Name           Description
158              ─────────────────────────────────────────────────────────────────
159              A_NORMAL       Normal display (no highlight)
160              A_STANDOUT     Best highlighting mode of the terminal.
161              A_UNDERLINE    Underlining
162              A_REVERSE      Reverse video
163              A_BLINK        Blinking
164              A_DIM          Half bright
165              A_BOLD         Extra bright or bold
166              A_PROTECT      Protected mode
167              A_INVIS        Invisible or blank mode
168              A_ALTCHARSET   Alternate character set
169              A_ITALIC       Italics (non-X/Open extension)
170              A_CHARTEXT     Bit-mask to extract a character
171              A_COLOR        Bit-mask to extract a color (legacy routines)
172
173       These  video  attributes are supported by attr_on and related functions
174       (which also support the attributes recognized by attron, etc.):
175
176              Name            Description
177              ─────────────────────────────────────────
178              WA_HORIZONTAL   Horizontal highlight
179              WA_LEFT         Left highlight
180              WA_LOW          Low highlight
181              WA_RIGHT        Right highlight
182              WA_TOP          Top highlight
183              WA_VERTICAL     Vertical highlight
184
185       The return values of many of these routines are  not  meaningful  (they
186       are  implemented  as macro-expanded assignments and simply return their
187       argument).  The SVr4 manual page claims (falsely) that  these  routines
188       always return 1.
189

NOTES

191       These functions may be macros:
192
193              attroff,  wattroff, attron, wattron, attrset, wattrset, standend
194              and standout.
195
196       Color pair values can only be OR'd with attributes if the  pair  number
197       is less than 256.  The alternate functions such as color_set can pass a
198       color pair value directly.  However, ncurses ABI 4 and 5 simply OR this
199       value  within  the  alternate functions.  You must use ncurses ABI 6 to
200       support more than 256 color pairs.
201

HISTORY

203       X/Open Curses is largely based  on  SVr4  curses,  adding  support  for
204       “wide-characters”  (not  specific to Unicode).  Some of the X/Open dif‐
205       ferences from SVr4 curses address the way video attributes can  be  ap‐
206       plied  to  wide-characters.   But aside from that, attrset and attr_set
207       are similar.  SVr4 curses provided the basic features for  manipulating
208       video  attributes.  However, earlier versions of curses provided a part
209       of these features.
210
211       As seen in 2.8BSD, curses assumed 7-bit characters,  using  the  eighth
212       bit  of  a byte to represent the standout feature (often implemented as
213       bold and/or reverse video).  The BSD curses library provided  functions
214       standout  and  standend which were carried along into X/Open Curses due
215       to their pervasive use in legacy applications.
216
217       Some terminals in the 1980s  could  support  a  variety  of  video  at‐
218       tributes,  although the BSD curses library could do nothing with those.
219       System V (1983) provided an improved curses library.  It defined the A_
220       symbols  for  use  by  applications to manipulate the other attributes.
221       There are few useful references for the chronology.
222
223       Goodheart's book UNIX Curses Explained (1991)  describes  SVr3  (1987),
224       commenting on several functions:
225
226       ·   the  attron,  attroff, attrset functions (and most of the functions
227           found in SVr4 but not in BSD curses) were introduced by System V,
228
229       ·   the alternate character set feature with A_ALTCHARSET was added  in
230           SVr2 and improved in SVr3 (by adding acs_map[]),
231
232       ·   start_color  and  related color-functions were introduced by System
233           V.3.2,
234
235       ·   pads, soft-keys were added in SVr3, and
236
237       Goodheart did not mention the background character or the cchar_t type.
238       Those are respectively SVr4 and X/Open features.  He did mention the A_
239       constants, but did not indicate their values.  Those were not the  same
240       in different systems, even for those marked as System V.
241
242       Different  Unix  systems  used  different  sizes  for the bit-fields in
243       chtype for characters and colors, and took into account  the  different
244       integer sizes (32-bit versus 64-bit).
245
246       This  table  showing  the number of bits for A_COLOR and A_CHARTEXT was
247       gleaned from the curses header files for various operating systems  and
248       architectures.   The inferred architecture and notes reflect the format
249       and size of the defined constants as well as clues such as  the  alter‐
250       nate  character  set implementation.  A 32-bit library can be used on a
251       64-bit system, but not necessarily the reverse.
252
253              Year   System        Arch    Color   Char   Notes
254              ────────────────────────────────────────────────────────────────
255              1992   Solaris 5.2   32      6       17     SVr4 curses
256              1992   HPUX 9        32      no      8      SVr2 curses
257              1992   AIX 3.2       32      no      23     SVr2 curses
258              1994   OSF/1 r3      32      no      23     SVr2 curses
259              1995   HP-UX 10.00   32      6       16     SVr3 “curses_colr”
260              1995   HP-UX 10.00   32      6       8      SVr4, X/Open curses
261              1995   Solaris 5.4   32/64   7       16     X/Open curses
262              1996   AIX 4.2       32      7       16     X/Open curses
263              1996   OSF/1 r4      32      6       16     X/Open curses
264
265              1997   HP-UX 11.00   32      6       8      X/Open curses
266              2000   U/Win         32/64   7/31    16     uses chtype
267
268       Notes:
269
270          Regarding HP-UX,
271
272          ·   HP-UX 10.20 (1996) added support for 64-bit  PA-RISC  processors
273              in 1996.
274
275          ·   HP-UX  10.30 (1997) marked “curses_colr” obsolete.  That version
276              of curses was dropped with HP-UX 11.30 in 2006.
277
278          Regarding OSF/1 (and Tru64),
279
280          ·   These used 64-bit hardware.  Like ncurses, the OSF/1 curses  in‐
281              terface is not customized for 32-bit and 64-bit versions.
282
283          ·   Unlike other systems which evolved from AT&T code, OSF/1 provid‐
284              ed a new implementation for X/Open curses.
285
286          Regarding Solaris,
287
288          ·   The initial release of Solaris was in 1992.
289
290          ·   The xpg4 (X/Open) curses was developed by MKS from 1990 to 1995.
291              Sun's copyright began in 1996.
292
293          ·   Sun updated the X/Open curses interface after 64-bit support was
294              introduced in 1997, but did not modify the  SVr4  curses  inter‐
295              face.
296
297          Regarding U/Win,
298
299          ·   Development  of  the  curses  library  began in 1991, stopped in
300              2000.
301
302          ·   Color support was added in 1998.
303
304          ·   The library uses only chtype (no cchar_t).
305
306       Once X/Open curses was adopted in the mid-1990s, the  constraint  of  a
307       32-bit interface with many colors and wide-characters for chtype became
308       a moot point.  The cchar_t structure (whose size and  members  are  not
309       specified in X/Open Curses) could be extended as needed.
310
311       Other interfaces are rarely used now:
312
313       ·   BSD  curses was improved slightly in 1993/1994 using Keith Bostic's
314           modification to make the library 8-bit clean  for  nvi.   He  moved
315           standout attribute to a structure member.
316
317           The  resulting  4.4BSD curses was replaced by ncurses over the next
318           ten years.
319
320       ·   U/Win is rarely used now.
321

EXTENSIONS

323       This implementation provides the A_ITALIC attribute for terminals which
324       have  the  enter_italics_mode (sitm) and exit_italics_mode (ritm) capa‐
325       bilities.  Italics are not mentioned in X/Open Curses.  Unlike the oth‐
326       er  video attributes, A_ITALIC is unrelated to the set_attributes capa‐
327       bilities.  This  implementation  makes  the  assumption  that  exit_at‐
328       tribute_mode may also reset italics.
329
330       Each  of  the functions added by XSI Curses has a parameter opts, which
331       X/Open Curses still (after more than twenty  years)  documents  as  re‐
332       served for future use, saying that it should be NULL.  This implementa‐
333       tion uses that parameter in ABI 6 for the functions which have a color-
334       pair parameter to support extended color pairs:
335
336       ·   For  functions  which modify the color, e.g., wattr_set, if opts is
337           set it is treated as a pointer to int, and used to  set  the  color
338           pair instead of the short pair parameter.
339
340       ·   For functions which retrieve the color, e.g., wattr_get, if opts is
341           set it is treated as a pointer to int, and  used  to  retrieve  the
342           color pair as an int value, in addition retrieving it via the stan‐
343           dard pointer to short parameter.
344
345       The remaining functions which have opts, but do not  manipulate  color,
346       e.g., wattr_on and wattr_off are not used by this implementation except
347       to check that they are NULL.
348

PORTABILITY

350       These functions are supported in the XSI Curses standard, Issue 4.  The
351       standard  defined  the dedicated type for highlights, attr_t, which was
352       not defined in SVr4 curses.  The functions taking attr_t arguments were
353       not supported under SVr4.
354
355       Very old versions of this library did not force an update of the screen
356       when changing the attributes.  Use touchwin  to  force  the  screen  to
357       match the updated attributes.
358
359       The  XSI  Curses standard states that whether the traditional functions
360       attron/attroff/attrset can manipulate attributes  other  than  A_BLINK,
361       A_BOLD,  A_DIM, A_REVERSE, A_STANDOUT, or A_UNDERLINE is "unspecified".
362       Under this implementation as well as SVr4 curses, these functions  cor‐
363       rectly  manipulate  all  other  highlights (specifically, A_ALTCHARSET,
364       A_PROTECT, and A_INVIS).
365
366       XSI Curses added these entry points:
367
368              attr_get, attr_on, attr_off, attr_set, wattr_on, wattr_off, wat‐
369              tr_get, wattr_set
370
371       The  new  functions are intended to work with a new series of highlight
372       macros prefixed with WA_.  The older macros have direct counterparts in
373       the newer set of names:
374
375              Name            Description
376              ────────────────────────────────────────────────────────────
377              WA_NORMAL       Normal display (no highlight)
378              WA_STANDOUT     Best highlighting mode of the terminal.
379              WA_UNDERLINE    Underlining
380              WA_REVERSE      Reverse video
381              WA_BLINK        Blinking
382              WA_DIM          Half bright
383              WA_BOLD         Extra bright or bold
384              WA_ALTCHARSET   Alternate character set
385
386       XSI  curses  does not assign values to these symbols, nor does it state
387       whether or not they are related to the similarly-named A_NORMAL, etc.:
388
389       ·   The XSI curses standard specifies that each pair  of  corresponding
390           A_  and  WA_-using functions operates on the same current-highlight
391           information.
392
393       ·   However, in some implementations, those symbols have unrelated val‐
394           ues.
395
396           For example, the Solaris xpg4 (X/Open) curses declares attr_t to be
397           an unsigned short integer (16-bits), while chtype is a unsigned in‐
398           teger  (32-bits).   The WA_ symbols in this case are different from
399           the A_ symbols because they are used for a smaller  datatype  which
400           does not represent A_CHARTEXT or A_COLOR.
401
402           In this implementation (as in many others), the values happen to be
403           the same because it simplifies copying information  between  chtype
404           and cchar_t variables.
405
406       The XSI standard extended conformance level adds new highlights A_HORI‐
407       ZONTAL, A_LEFT, A_LOW, A_RIGHT, A_TOP,  A_VERTICAL  (and  corresponding
408       WA_  macros  for  each).  As of August 2013, no known terminal provides
409       these highlights (i.e., via the sgr1 capability).
410

RETURN VALUE

412       All routines return the integer OK on success, or ERR on failure.
413
414       X/Open does not define any error conditions.
415
416       This implementation
417
418       ·   returns an error if the window pointer is null.
419
420       ·   returns an error if the color pair parameter for wcolor_set is out‐
421           side the range 0..COLOR_PAIRS-1.
422
423       ·   does  not  return an error if either of the parameters of wattr_get
424           used for retrieving attribute or color-pair values is NULL.
425
426       Functions with a "mv" prefix first  perform  a  cursor  movement  using
427       wmove, and return an error if the position is outside the window, or if
428       the window pointer is null.
429

SEE ALSO

431       curses(3X), curs_addch(3X), curs_addstr(3X), curs_bkgd(3X),
432       curs_printw(3X), curs_variables(3X)
433
434
435
436                                                                 curs_attr(3X)
Impressum