Added color mode
This commit is contained in:
31
nclock.c
31
nclock.c
@@ -28,6 +28,21 @@ int main(int argc, char **argv) {
|
||||
sa.sa_handler = handle_winch;
|
||||
sigaction(SIGWINCH, &sa, NULL);
|
||||
|
||||
|
||||
start_color(); //Enables multi color mode
|
||||
|
||||
/* Initialize custom color pairs */
|
||||
/* Color pair index must be > 0 */
|
||||
/* init_pair(index, foreground color, background color); */
|
||||
/* Color pairs are called by attron(COLOR_PAIR(1)); */
|
||||
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
||||
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||
init_pair(3, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(4, COLOR_YELLOW, COLOR_BLACK);
|
||||
|
||||
|
||||
|
||||
|
||||
//Define the state struct
|
||||
state s = {0};
|
||||
|
||||
@@ -47,18 +62,22 @@ void initState(state *s) {
|
||||
}
|
||||
|
||||
void drawNumber(int starty, int startx, int num) {
|
||||
static int currentColor = 0;
|
||||
if (++currentColor > 4) {
|
||||
currentColor = 1;
|
||||
}
|
||||
int i, j, numarr[2];
|
||||
for (i = 0; i < 2; i++) {
|
||||
numarr[i] = num % 10;
|
||||
num /= 10;
|
||||
}
|
||||
|
||||
enColor(currentColor);
|
||||
for (j = 0; j < 2; j++) {
|
||||
for (i = 0; i < 5; i++) {
|
||||
mvprintw(starty + i, startx + (6 * j), number[numarr[1 - j]][i]);
|
||||
}
|
||||
}
|
||||
|
||||
disColor(currentColor);
|
||||
}
|
||||
|
||||
void drawColon(int starty, int startx) {
|
||||
@@ -96,3 +115,11 @@ void draw(state *s) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void enColor(int color) {
|
||||
attron(COLOR_PAIR(color));
|
||||
}
|
||||
|
||||
void disColor(int color) {
|
||||
attroff(COLOR_PAIR(color));
|
||||
}
|
||||
|
Reference in New Issue
Block a user