/* * Show text with different colors. * * Most functions are from "mylib" library, though some are from "ncurses" * library (and "man 3x foobar" gives more info on foobar()). */ #include #include #include #include #include "mylib.h" typedef struct { short color; char *name; } color_and_name_t; int main(void) { ncurses_start(); start_color(); add_to_row(stdscr, 2); color_and_name_t colors[] = { { COLOR_BLACK, "COLOR_BLACK" }, { COLOR_RED, "COLOR_RED" }, { COLOR_GREEN, "COLOR_GREEN" }, { COLOR_YELLOW, "COLOR_YELLOW" }, { COLOR_BLUE, "COLOR_BLUE" }, { COLOR_MAGENTA, "COLOR_MAGENTA" }, { COLOR_CYAN, "COLOR_CYAN" } }; for (short i = 0; i < sizeof(colors)/sizeof(colors[0]); ++i) { init_pair(i+1, colors[i].color, COLOR_WHITE); } for (short i = 0; i < sizeof(colors)/sizeof(colors[0]); ++i) { show_with_attrib(stdscr, COLOR_PAIR(i+1), colors[i].name); add_to_row(stdscr, 2); } refresh(); any_key_to_exit(stdscr); ncurses_end(); return EXIT_SUCCESS; }