Skip to content

Commit

Permalink
Adds rainbow mode and fixes screen resize bug
Browse files Browse the repository at this point in the history
Fixes window resize problem, earlier when the terminal window was
resized to a size lesser than 3, a null pointer exception was invoked.

Rainbow mode support gives users the choice of displaying the
matrix in different colors using the -r option.

Signed-off-by: Abishek V Ashok <[email protected]>
  • Loading branch information
Onur Berk Töre authored and abishekvashok committed Aug 5, 2017
1 parent 6525abe commit 6ce59e9
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion cmatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void usage(void) {
printf(" -V: Print version information and exit\n");
printf(" -u delay (0 - 10, default 4): Screen update delay\n");
printf(" -C [color]: Use this color for matrix (default green)\n");
printf(" -r: rainbow mode\n");
}

void version(void) {
Expand Down Expand Up @@ -235,6 +236,13 @@ void handle_sigwinch(int s) {
COLS = win.ws_col;
LINES = win.ws_row;

if(LINES <10){
LINES = 10;
}
if(COLS <10){
COLS = 10;
}

#ifdef HAVE_RESIZETERM
resizeterm(LINES, COLS);
#ifdef HAVE_WRESIZE
Expand Down Expand Up @@ -264,16 +272,21 @@ int main(int argc, char *argv[]) {
int update = 4;
int highnum = 0;
int mcolor = COLOR_GREEN;
int rainbow = 0;
int randnum = 0;
int randmin = 0;
int pause = 0;

char *oldtermname;
char *syscmd = NULL;

time_t t;
srand((unsigned) time(&t));


/* Many thanks to morph- ([email protected]) for this getopt patch */
opterr = 0;
while ((optchr = getopt(argc, argv, "abBfhlnosxVu:C:")) != EOF) {
while ((optchr = getopt(argc, argv, "abBfhlnrosxVu:C:")) != EOF) {
switch (optchr) {
case 's':
screensaver = 1;
Expand Down Expand Up @@ -340,6 +353,9 @@ int main(int argc, char *argv[]) {
case 'V':
version();
exit(0);
case 'r':
rainbow = 1;
break;
}
}

Expand Down Expand Up @@ -424,6 +440,7 @@ if (console) {
var_init();

while (1) {

count++;
if (count > 4) {
count = 1;
Expand Down Expand Up @@ -463,29 +480,40 @@ if (console) {
break;
case '!':
mcolor = COLOR_RED;
rainbow = 0;
break;
case '@':
mcolor = COLOR_GREEN;
rainbow = 0;
break;
case '#':
mcolor = COLOR_YELLOW;
rainbow = 0;
break;
case '$':
mcolor = COLOR_BLUE;
rainbow = 0;
break;
case '%':
mcolor = COLOR_MAGENTA;
rainbow = 0;
break;
case 'r':
rainbow = 1;
break;
case '^':
mcolor = COLOR_CYAN;
rainbow = 0;
break;
case '&':
mcolor = COLOR_WHITE;
rainbow = 0;
break;
case 'p':
case 'P':
pause = (pause == 0)?1:0;
break;

}
}
}
Expand Down Expand Up @@ -628,6 +656,31 @@ if (console) {
attroff(A_ALTCHARSET);
}
} else {

if(rainbow){
int randomColor = rand() % 6;

switch(randomColor){
case 0:
mcolor = COLOR_GREEN;
break;
case 1:
mcolor = COLOR_BLUE;
break;
case 2:
mcolor = COLOR_BLACK;
break;
case 3:
mcolor = COLOR_YELLOW;
break;
case 4:
mcolor = COLOR_CYAN;
break;
case 5:
mcolor = COLOR_MAGENTA;
break;
}
}
attron(COLOR_PAIR(mcolor));
if (matrix[i][j].val == 1) {
if (bold) {
Expand Down

0 comments on commit 6ce59e9

Please sign in to comment.