Source Code File 03-05_colorful
03-05_colorful.c
#include <ncurses.h>
int main()
{
initscr();
start_color();
init_pair(1,COLOR_BLACK,COLOR_RED);
init_pair(2,COLOR_YELLOW,COLOR_BLACK);
attrset(COLOR_PAIR(1)); /* black on red */
addstr("I am Mr. Black!\n");
attrset(COLOR_PAIR(2)); /* yellow on black */
addstr("I am Mr. Yellow!\n");
attrset(COLOR_PAIR(1) | A_BOLD); /* +bold */
addstr("I'm feeling bold!\n");
attrset(COLOR_PAIR(2) | A_BOLD);; /* +bold */
addstr("Me too!");
refresh();
getch();
endwin();
return 0;
}
Output Screenshot

Notes
* As I wrote in the eBook, the color applied doesn't fill the rest of the line.
Copyright © 1997-2025 by QPBC.
All rights reserved
