|
CS256 - Fundamentals of Structured Programming
|
Displaying ./code/curses/example2.c
#include <curses.h>
#include <string.h>
// Compile:
// gcc -o example2 example2.c -lncurses
int main(void)
{
initscr();
// Enable coloring:
start_color();
// Define a color pair:
init_pair(1, COLOR_RED, COLOR_WHITE);
char mesg[] = "Hello, world!";
int len = strlen(mesg);
// Use attron to enable attributes like color and underlining and italics:
attron(COLOR_PAIR(1) | A_UNDERLINE | A_ITALIC);
mvprintw(LINES/2, COLS/2-len/2,"%s", mesg);
// Just remove the color and italics, the message below should still be underlined:
attroff(COLOR_PAIR(1) | A_ITALIC);
refresh();
move(LINES-1,0);
printw("Press any key to exit.");
getch();
endwin();
return 0;
}
|