logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/cs256su21code/jul27/color.c

#include <curses.h>
#include <string.h>

//compile: gcc -o color color.c -lncurses

int main(void)
{
  int fg, bg;

  initscr();
  start_color();
  // Define all the foreground and background combinations:
  for(fg=0; fg < 8; fg++)
    for(bg=0; bg < 8; bg++)
      init_pair( (fg*8 + bg), fg, bg );

  clear();

  move(2, 20);
  // Draw the background color numbers across the top:
  for(bg=0; bg < 8; bg++) {
    printw("%3d", bg);
  }
  move(3, 19);
  // Draws a line under the top numbers:
  addch(ACS_ULCORNER);
  for(bg=0; bg < 8; bg++) {
    addch(ACS_HLINE);
    addch(ACS_HLINE);
    addch(ACS_HLINE);
  }

  // For every foreground color (one each row):
  for(fg=0; fg < 8; fg++) {
    attrset(A_NORMAL);
    mvprintw(4+fg,16, "%2d ", fg);
    addch(ACS_VLINE);
    // All the background colors for each foreground color (columns):
    for(bg=0; bg < 8; bg++) {
      attrset(COLOR_PAIR(fg*8 + bg));
      addch('x'|A_DIM);
      addch('x');
      addch('x'|A_BOLD);
    }
  }
  attrset(A_NORMAL);

  getch();
  endwin();
  return 0;
}