Skip to content

Instantly share code, notes, and snippets.

@jwodder
Created June 26, 2014 23:25
Show Gist options
  • Save jwodder/33d7017e6255d13c5037 to your computer and use it in GitHub Desktop.
Save jwodder/33d7017e6255d13c5037 to your computer and use it in GitHub Desktop.
curses color spectrum
#include <curses.h>
int main(void) {
initscr();
noecho();
cbreak();
start_color();
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_BLUE, COLOR_BLACK);
init_pair(4, COLOR_CYAN, COLOR_BLACK);
init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
init_pair(6, COLOR_YELLOW, COLOR_BLACK);
init_pair(7, COLOR_BLACK, COLOR_WHITE);
init_pair(8, COLOR_BLACK, COLOR_RED);
init_pair(9, COLOR_BLACK, COLOR_GREEN);
init_pair(10, COLOR_BLACK, COLOR_BLUE);
init_pair(11, COLOR_BLACK, COLOR_CYAN);
init_pair(12, COLOR_BLACK, COLOR_MAGENTA);
init_pair(13, COLOR_BLACK, COLOR_YELLOW);
printw("White"); attron(A_BOLD); printw(" Bold\n");
attrset(COLOR_PAIR(1));
printw("Red"); attron(A_BOLD); printw(" Bold\n");
attrset(COLOR_PAIR(2));
printw("Green"); attron(A_BOLD); printw(" Bold\n");
attrset(COLOR_PAIR(3));
printw("Blue"); attron(A_BOLD); printw(" Bold\n");
attrset(COLOR_PAIR(4));
printw("Cyan"); attron(A_BOLD); printw(" Bold\n");
attrset(COLOR_PAIR(5));
printw("Magenta"); attron(A_BOLD); printw(" Bold\n");
attrset(COLOR_PAIR(6));
printw("Yellow"); attron(A_BOLD); printw(" Bold\n");
attrset(COLOR_PAIR(7));
printw("White background\n");
attrset(COLOR_PAIR(8));
printw("Red background\n");
attrset(COLOR_PAIR(9));
printw("Green background\n");
attrset(COLOR_PAIR(10));
printw("Blue background\n");
attrset(COLOR_PAIR(11));
printw("Cyan background\n");
attrset(COLOR_PAIR(12));
printw("Magenta background\n");
attrset(COLOR_PAIR(13));
printw("Yellow background\n");
getch();
endwin();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment