The following is an excerpt from beginning Linux programming.
-Lncurses option added during compilation
# Include <unistd. h>
# Include <stdlib. h>
# Include <stdio. h>
# Include <curses. h>
Int main ()
{
Int I;
Initscr ();
If (! Has_colors ())
{
Endwin ();
Fprintf (stderr, "error-no color support on this terminal \ n ");
Exit (1 );
}
If (start_color ()! = OK)
{
Endwin ();
Fprintf (stderr, "error-cocould not initialize colors \ n ");
Exit (2 );
}
Clear ();
Mvprintw (5, 5, "There are % d colors, and % d color_pairs available", colors, color_pairs );
Refresh ();
Init_pair (1, color_red, color_black );
Init_pair (2, color_red, color_green );
Init_pair (3, color_green, color_red );
For (I = 1; I <= 3; ++ I)
{
Attroff (a_bold );
Attrset (color_pair (I ));
Mvprintw (5 + I, 5, "color pair % d", I );
Attrset (color_pair (I) | a_bold );
Mvprintw (5 + I, 25, "bold color pair % d", I );
Refresh ();
Sleep (1 );
}
Endwin ();
Exit (0 );
}