DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

color(CURSES)


color -- color manipulation functions

Synopsis

cc [options] file -lcurses
#include <curses.h>

bool can_change_color(void);

int color_content(short color, short *red, short *green, short *blue);

bool has_colors(void);

int init_color(short color, short red, short green, short blue);

int init_pair(short pair, short f, short b);

int pair_content(short pair, short *f, short *b);

int start_color(void);

int COLOR_PAIR(int n);

int PAIR_NUMBER(int value);

extern int COLOR_PAIRS;

extern int COLORS;

Description

These functions manipulate color on terminals that support color.

Querying Capabilities

The has_colors(CURSES) function indicates whether the terminal is a color terminal. The can_change_color(CURSES) function indicates whether the terminal is a color terminal on which colors can be redefined.

Initialisation

The start_color(CURSES) function must be called in order to enable use of colors and before any color manipulation function is called. The function initialises eight basic colors (black, blue, green, cyan, red, magenta, yellow, and white) that can be specified by the color macros (such as COLOR_BLACK) defined in <curses.h>. (See ``Color-related Macros''.) The initial appearance of these eight colors is not specified.

The function also initialises two global external variables:

The start_color(CURSES) function also restores the colors on the terminal to terminal-specific initial values. The initial background color is assumed to be black for all terminals.

Color Identification

The init_color(CURSES) function redefines color number color, on terminals that support the redefinition of colors, to have the red, green, and blue intensity components specified by red, green, and blue, respectively. Calling init_color(CURSES) also changes all occurrences of the specified color on the screen to the new definition.

The color_content(CURSES) function identifies the intensity components of color number color. It stores the red, green, and blue intensity components of this color in the addresses pointed to by red, green, and blue, respectively.

For both functions, the color argument must be in the range from 0 to and including COLORS-1. Valid intensity values range from 0 (no intensity component) up to and including 1000 (maximum intensity in that component).

User-Defined Color Pairs

Calling init_pair(CURSES) defines or redefines color-pair number pair to have foreground color f and background color b. Calling init_pair(CURSES) changes any characters that were displayed in the color pair's old definition to the new definition and refreshes the screen.

After defining the color pair, the macro COLOR_PAIR(n) returns the value of color pair n. This value is the color attribute as it would be extracted from a chtype. Conversely, the macro PAIR_NUMBER(value) returns the color pair number associated with the color attribute value.

The pair_content(CURSES) function retrieves the component colors of a color-pair number pair. It stores the foreground and background color numbers in the variables pointed to by f and b, respectively.

With init_pair(CURSES) and pair_content(CURSES), the value of pair must be in a range from 0 to and including COLOR_PAIRS-1. (There may be an implementation-specific upper limit on the valid value of pair, but any such limit is at least 63.) Valid values for f and b are the range from 0 to and including COLORS-1.

Return value

The has_colors(CURSES) function returns TRUE if the terminal can manipulate colors; otherwise, it returns FALSE.

The can_change_color(CURSES) function returns TRUE if the terminal supports colors and can change their definitions; otherwise, it returns FALSE.

Upon successful completion, the other functions return OK; otherwise, they return ERR.

Errors

No errors are defined.

Usage

To use these functions, start_color(CURSES) must be called, usually right after initscr(CURSES).

The can_change_color(CURSES) and has_colors(CURSES) functions facilitate writing terminal-independent programs. For example, a programmer can use them to decide whether to use color or some other video attribute.

On color terminals, a typical value of COLORS is 8 and the macros such as COLOR_BLACK return a value within the range from 0 to and including 7. However, applications cannot rely on this to be true.

Standards Conformance

The Single UNIX Specification, Version 2; The Open Group.

References

attroff(CURSES), delscreen(CURSES), curses(F)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005