// hascolors - does the terminal have colors? if so, try to // change a color #include #include #include #include typedef void (*call)(void); void withcolor(void) { attron(COLOR_PAIR(1)); printw("has colors"); attroff(COLOR_PAIR(1)); } void withoutcolor(void) { attron(A_BOLD); printw("no colors"); attroff(A_BOLD); } int main(void) { call fn; int status; setlocale(LC_ALL, ""); initscr(); if (has_colors()) { start_color(); init_color(COLOR_RED, 0, 800, 0); init_pair(1, COLOR_RED, COLOR_BLACK); fn = withcolor; status = 0; } else { fn = withoutcolor; status = 1; } fn(); getch(); // wait for "any" key... endwin(); exit(status); }