Attribute functions
Adapted from NCURSES Programming HOWTO, by Pradeep Padala.
The functions attron(), attroff() and attrset(), and their sister functions such as attr_get(), can be used to switch attributes on and off, get attributes and produce a colorful display.
The attributes
Section titled “The attributes”The functions attron() and attroff() take a bit-mask of attributes and switch them on or off, respectively. The following video attributes, which are defined in curses.h, can be passed to these functions.
A_NORMAL Normal display (no highlight)A_STANDOUT Best highlighting mode of the terminal.A_UNDERLINE UnderliningA_REVERSE Reverse videoA_BLINK BlinkingA_DIM Half brightA_BOLD Extra bright or boldA_PROTECT Protected modeA_INVIS Invisible or blank modeA_ALTCHARSET Alternate character setA_CHARTEXT Bit-mask to extract a characterCOLOR_PAIR(n) Color-pair number nThe last one is the most colorful one :-) Colors explains it.
We can OR (|) any number of the above attributes to get a combined effect. If you wanted reverse video with blinking characters, you can use
attron() vs attrset()
Section titled “attron() vs attrset()”Then what is the difference between attron() and attrset()? attrset() sets the attributes of the window, whereas attron() just switches on the attribute given to it. So attrset() fully overrides whatever attributes the window previously had and sets it to the new attributes. Similarly, attroff() just switches off the attributes given to it as an argument. This gives us the flexibility of managing attributes easily. But if you use them carelessly, you may lose track of what attributes the window has and garble the display. This is especially true while managing menus with colors and highlighting. So decide on a consistent policy and stick to it. You can always use standend(), which is equivalent to attrset(A_NORMAL), which turns off all attributes and brings you to normal mode.
attr_get()
Section titled “attr_get()”The function attr_get() gets the window’s current attributes and color pair: the ones it will give the next characters written to it. Though we might not use this as often as the above functions, it is useful when you need to change the attributes for a while and then put back what was there. It reports nothing about characters already on the screen; to read those, use inch().
The attr_ functions
Section titled “The attr_ functions”There is a series of functions like attr_set(), attr_on(), etc. These are similar to the above functions, except that they take parameters of type attr_t.
The wattr functions
Section titled “The wattr functions”For each of the above functions, we have a corresponding function with ‘w’ which operates on a particular window. The above functions operate on stdscr.