|
Next: 8.12 Cursor and Window Up: 8 Character Cell Graphics Previous: 8.10 Updating the Terminal
8.11 Video Attributes and ColorAttributes are special terminal capabilities used when printing characters to the screen. Characters can be printed bold, underlined, blinking, etc. In ncurses you have the ability to turn attributes on or off to get better looking output. Possible attributes are listed in the following table.
Ncurses defines eight colors you can use on a terminal with color support. First, initialize the color data structures with start_color(), then check the terminal capabilities with has_colors(). start_color() will initialize COLORS, the maximum colors the terminal supports, and COLOR_PAIR, the maximum number of color pairs you can define.
The attributes can be combined with the OR operator ' COLORPAIRS-1 COLORS-1.
int color_content(color, r, g, b) And how to combine attributes and colors? Some terminals, as the console in Linux, have colors and some not (xterm, vs100 etc). The following code should solve the problem:
First, the function CheckColor initializes the colors with start_color(), then the function has_colors() will return TRUE if the current terminal has colors. We check this and call init_pair(...) to combine foreground and background colors and wattrset(...) to set these pairs for the specified window. Alternatively, we can use wattrset(...) alone to set attributes if we have a black and white terminal. To get colors in an xterm the best way I found out is to use the ansi_xterm with the patched terminfo entries from the Midnight Commander. Just get the sources of ansi_xterm and Midnight Commander (mc-x.x.tar.gz). Then compile the ansi_xterm and use tic with xterm.ti and vt100.ti from the mc-x.x.tar.gz archive. Execute ansi_xterm and test it out.
next up previous contents Next: 8.12 Cursor and Window Up: 8 Character Cell Graphics Previous: 8.10 Updating the Terminal Converted on: Fri Mar 29 14:43:04 EST 1996 |
|||||||||||||||||
With any suggestions or questions please feel free to contact us |