textattr
Sets text attributes.
Defined in header <conio.h>
Syntax
#include <conio.h>
void textattr(int newattr);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ |
Remarks
textattr lets you set both the foreground and background colors in a single call. (Normally, you set the attributes with textcolor and textbackground.)
This function does not affect any characters currently on the screen; it only affects those displayed by functions (such as cprintf) performing text mode, direct video output after this function is called.
The color information is encoded in the newattr parameter as follows:
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| B | b | b | b | f | f | f | f |
In this 8-bit newattr parameter,
^j^is the 4-bit foreground color (0 to 15). fo&b is the 3-bit background color (0 to 7). B is the blink-enable bit.
If the blink-enable bit is on, the character blinks. This can be accomplished by adding the constant BLINK to the attribute.
If you use the symbolic color constants defined in conio.h for creating text attributes with textattr, note the following limitations on the color you select for the background:
■ You can only select one of the first eight colors for the background. ■ You must shift the selected background color left by 4 bits to move it into the correct bit positions.
These symbolic constants are listed in the following table:
Numeric
| Symbolic constant | value | Foreground or background? |
| BLACK | 0 | Both |
| BLUE | 1 | Both |
| GREEN | 2 | Both |
| CYAN | 3 | Both |
| RED | 4 | Both |
| MAGENTA | 5 | Both |
| BROWN | 6 | Both |
| LIGHTGRAY | 7 | Both |
| DARKGRAY | 8 | Foreground only |
| LIGHTBLUE | 9 | Foreground only |
| LIGHTGREEN | 10 | Foreground only |
| LIGHTCYAN | 11 | Foreground only |
| LIGHTRED | 12 | Foreground only |
| LIGHTMAGENTA | 13 | Foreground only |
| YELLOW | 14 | Foreground only |
| WHITE | 15 | Foreground only |
| BLINK | 128 | Foreground only |
Return value
None.
See also
Example
#include <conio.h>
int main(void)
{
int i;
clrscrO ;
for (i = 0; i < 9; i++) {
textattr(i + ((i+1) « 4));
cprintf("This is a test\r\n");
}
return 0;
}
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/conio.h/textattr/
· short form /3.1/textattr/