Skip to content

Commit

Permalink
Merge pull request #103 from kdkasad/master
Browse files Browse the repository at this point in the history
Add option to choose tty
  • Loading branch information
abishekvashok authored May 31, 2020
2 parents b06ac1d + 2451dca commit 1faae51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmatrix.1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Screen update delay 0 - 9, default 4
.I "\-C color"
Use this color for matrix (default green).
Valid colors are green, red, blue, white, yellow, cyan, magenta and black.
.I "\-t tty"
Set tty to use
.SS KEYSTROKES
The following keystrokes are available during execution (unavailable in
\-s mode)
Expand Down
23 changes: 21 additions & 2 deletions cmatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Expand Down Expand Up @@ -146,6 +147,7 @@ void usage(void) {
printf(" -r: rainbow mode\n");
printf(" -m: lambda mode\n");
printf(" -k: Characters change while scorlling. (Works without -o opt.)\n");
printf(" -t [tty]: Set tty to use\n");
}

void version(void) {
Expand Down Expand Up @@ -289,13 +291,14 @@ int main(int argc, char *argv[]) {
int pause = 0;
int classic = 0;
int changes = 0;
char *tty = NULL;

srand((unsigned) time(NULL));
setlocale(LC_ALL, "");

/* Many thanks to morph- ([email protected]) for this getopt patch */
opterr = 0;
while ((optchr = getopt(argc, argv, "abBcfhlLnrosmxkVu:C:")) != EOF) {
while ((optchr = getopt(argc, argv, "abBcfhlLnrosmxkVu:C:t:")) != EOF) {
switch (optchr) {
case 's':
screensaver = 1;
Expand Down Expand Up @@ -374,14 +377,30 @@ int main(int argc, char *argv[]) {
case 'k':
changes = 1;
break;
case 't':
tty = optarg;
break;
}
}

if (force && strcmp("linux", getenv("TERM"))) {
/* setenv is much more safe to use than putenv */
setenv("TERM", "linux", 1);
}
initscr();
if (tty) {
FILE *ftty = fopen(tty, "r+");
if (!ftty) {
fprintf(stderr, "cmatrix: error: '%s' couldn't be opened: %s.\n",
tty, strerror(errno));
exit(EXIT_FAILURE);
}
SCREEN *ttyscr;
ttyscr = newterm(NULL, ftty, ftty);
if (ttyscr == NULL)
exit(EXIT_FAILURE);
set_term(ttyscr);
} else
initscr();
savetty();
nonl();
cbreak();
Expand Down

0 comments on commit 1faae51

Please sign in to comment.