od_set_color()¶
Selects foreground and background text colors
Synopsis¶
void od_set_color(INT nForeground, INT nBackground);
Return value¶
N/A
Description¶
od_set_color() selects the foreground and background used for subsequently
displayed text. It combines both arguments into an IBM-PC attribute and passes
the result to od_set_attrib(). ANSI, AVATAR, or RIP
operation is required for the color change to take effect on the caller's
terminal.
The foreground may be any of the following values:
| Value | Color |
|---|---|
D_BLACK |
Black |
D_BLUE |
Dark blue |
D_GREEN |
Dark green |
D_CYAN |
Dark cyan |
D_RED |
Dark red |
D_MAGENTA |
Dark magenta |
D_BROWN |
Brown |
D_GREY |
Light grey, historically called dark white |
L_BLACK |
High-intensity black, normally displayed as dark grey |
L_BLUE |
Bright blue |
L_GREEN |
Bright green |
L_CYAN |
Bright cyan |
L_RED |
Bright red |
L_MAGENTA |
Bright magenta |
L_YELLOW |
Yellow |
L_WHITE |
Bright white |
An ordinary background uses one of the eight D_* values. A blinking
background uses the corresponding B_* name:
| Ordinary | Blinking |
|---|---|
D_BLACK |
B_BLACK |
D_BLUE |
B_BLUE |
D_GREEN |
B_GREEN |
D_CYAN |
B_CYAN |
D_RED |
B_RED |
D_MAGENTA |
B_MAGENTA |
D_BROWN |
B_BROWN |
D_GREY |
B_GREY |
The B_* values set the traditional IBM-PC blink bit. A modern terminal may
display that bit as a bright background or may ignore blinking; OpenDoors
cannot control that terminal preference.
For example:
od_set_color(L_WHITE, D_BLACK);
selects bright white on black. The equivalent combined-attribute call is:
od_set_attrib(L_WHITE | (D_BLACK << 4));
Both arguments must be one of the documented color constants. The function
does not independently validate them. When graphics are unavailable,
od_set_attrib() leaves the current attribute unchanged
and records ERR_NOGRAPHICS.
Example¶
The following helpers retain the unmodified half of a color while changing the other half. They assume they are the only routines used by the application to select colors:
static INT current_foreground = D_GREY;
static INT current_background = D_BLACK;
static void set_foreground(INT foreground)
{
current_foreground = foreground;
od_set_color(current_foreground, current_background);
}
static void set_background(INT background)
{
current_background = background;
od_set_color(current_foreground, current_background);
}
They may then be called independently:
set_foreground(L_YELLOW);
set_background(D_BLUE);