Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

attroff(3XC)

delscreen(3XC)

can_change_color(3XC)

NAME

can_change_color, color_content, COLOR_PAIR, has_colors, init_color, init_pair, pair_content, PAIR_NUMBER, start_color − manipulate color information

SYNOPSIS

#include <curses.h>

bool can_change_color(void);

int color_content(short color, short ∗r, short ∗g,
short ∗b);

int COLOR_PAIR(int n);

bool has_colors(void);

int init_color(short color, short r, short g, short b);

int init_pair(short pair, short fg, short bg);

int pair_content(short pair, short ∗fg, short ∗bg);

int PAIR_NUMBER(int value);

int start_color(void);

ARGUMENTS

colorIs the number of the color for which to provide information (0 to COLORS). 

rIs a pointer to the RGB value for the amount of red in color. 

gIs a pointer to the RGB value for the amount of green in color. 

bIs a pointer to the RGB value for the amount of blue in color. 

nIs the number of a color pair. 

pairIs the number of the color pair for which to provide information (1 to COLOR_PAIRS). 

fgIs a pointer to the number of the foreground color (0 to COLORS) in pair. 

bgIs a pointer to the number of the background color (0 to COLORS ) in pair. 

valueIs a color attribute value. 

DESCRIPTION

The start_color() function initializes the use of color.  It must be used if color is to be used in the program.  It must be called before any other color functions, ideally right after initscr(3XC).  Eight basic colors are initialized (black, red, green, yellow, blue, magenta, cyan, and white) and two global variables (COLORS and COLOR_PAIRS).  The former variable specifies the number of colors the terminal supports, the latter the number of color pairs.  Colors are always in pairs consisting of a foreground color (for characters) and a background color (for the the rest of the character cell).  The initial appearance of these colors is unspecified. 

The init_pair() function initializes a color pair so that it can be used as a parameter.  COLOR_PAIR() can be used as an attribute and as a parameter to functions like attr_set(3XC).  Its first parameter is the number of the color pair to be changed; the second parameter is the number of the foreground color; the third parameter is the number of the background color.  The maximum number of color pairs and colors the terminal can support are defined in the global variables COLOR_PAIRS and COLORS, respectively. 

Color pair 0 (zero) is reserved for use by X/Open Curses. 

Each time that a color pair is initialized, the screen is refreshed and all occurrences of that color pair are updated to reflect the new definition. 

The init_color() function redefines the color using the number of the color and the RGB values for red, green, and blue as parameters. 

The following default colors are defined (X/Open Curses assumes that COLOR_BLACK is the default background color for all terminals):

COLOR_BLACK
COLOR_RED
COLOR_GREEN
COLOR_YELLOW
COLOR_BLUE
COLOR_MAGENTA
COLOR_CYAN
COLOR_WHITE

Each time that a color is redefined with the init_color() function, the screen is refreshed and all occurrences of that color are updated to reflect the new definition. 

The can_change_color() function returns TRUE if the terminal supports color and the colors can be changed.  The has_colors() function returns TRUE if the terminal supports color.  These functions are useful when writing terminal-independent programs.  They can be used to determine whether to replace color with another attribute on a particular terminal. 

The color_content() function provides information on the amount of red, green, and blue in a particular color.  The intensity of each color is stored in the addresses pointed to by the r, g, andb parameters, respectively.  The values passed back range from 0 (zero) (no component of that color) to 1000 (maximum amount of component). 

The pair_content() function provides information on what colors compose the specified color pair.  The numbers of the foreground and background colors are passed back in the addresses pointed to by the fg and bg parameters, respectively.  The values stored in fg and bg range from 0 (zero) to COLORS. 

RETURN VALUES

The has_colors() function returns TRUE if the terminal is able to handle colors.  Otherwise, it returns FALSE. 

The can_change_color() function returns TRUE if the terminal supports colors and is able to change their definitions.  Otherwise, it returns FALSE. 

On success, the other functions return OK.  Otherwise, they return ERR. 

ERRORS

None. 

SEE ALSO

attroff(3XC), delscreen(3XC)

SunOS 5.6  —  Last change: 1 Jun 1996

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026