Working with color
If a terminal supports color, you can use the color manipulation subroutines to include color in your curses program.
Before manipulating colors, test whether a terminal supports color. To do this, you can use either the has_colors subroutine or the can_change_color subroutine. The can_change_color subroutine also checks to see if a program can change the terminal's color definitions. Neither of these subroutines requires an argument.
Subroutine | Description |
---|---|
can_change_color | Checks to see if the terminal supports colors and changing of the color definition |
has_colors | Checks that the terminal supports colors |
start_color | Initializes the eight basic colors and two global variables, COLORS and COLOR_PAIRS |
After you have determined that the terminal supports color, call the start_color subroutine before you call other color subroutines. It is a good practice to call this subroutine immediately after the initscr subroutine and after a successful color test. The COLORS global variable defines the maximum number of colors that the terminal supports. The COLOR_PAIRS global variable defines the maximum number of color pairs that the terminal supports.