diff options
author | KatolaZ <katolaz@freaknet.org> | 2019-08-12 09:02:50 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2019-08-12 09:02:50 +0100 |
commit | 0522ef659553292f546fb1f3af43cfd2f4b07bb2 (patch) | |
tree | af5c439fa02a4afdd5f887e86180b39857d9c5f0 /gramscii.c | |
parent | a46183e96042cf751199f0a06d437a599f7f5bf8 (diff) |
fix read of command scripts and script-mode
Diffstat (limited to 'gramscii.c')
-rw-r--r-- | gramscii.c | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -35,11 +35,12 @@ char *argv0; void cleanup(int s){ - if (!silent) + if (!script){ printf("\033[;H\033[2J"); + tcsetattr(0, TCSANOW, &t1); + } else dump_lines(screen, stdout); - tcsetattr(0, TCSANOW, &t1); fflush(stdout); exit(s); } @@ -53,11 +54,12 @@ void init(){ signal(SIGTERM, cleanup); signal(SIGQUIT, cleanup); - tcgetattr(0, &t1); - t2 = t1; - t2.c_lflag &= ~(ICANON | ECHO); - tcsetattr(0, TCSANOW, &t2); - + if (!script){ + tcgetattr(0, &t1); + t2 = t1; + t2.c_lflag &= ~(ICANON | ECHO); + tcsetattr(0, TCSANOW, &t2); + } init_screen(); x = 0; y = 0; @@ -72,9 +74,12 @@ void init(){ void commands(FILE *fc){ - char c; + int c; while((c=fgetc(fc))!=EOF){ if (!change_style(c) && !move_around(c, fc, 1)){ +#ifdef DEBUG + fprintf(stderr, "got command: %c\n", c); +#endif switch(c){ case 'i': mode = TEXT; @@ -156,7 +161,7 @@ int main(int argc, char *argv[]){ ARGBEGIN { case 's': - silent = 1; + script = 1; break; case 'h': /* FALLTHROUGH */ default: @@ -171,12 +176,15 @@ int main(int argc, char *argv[]){ } else { commands(fc); + fflush(fc); fclose(fc); redraw(); } argv++; argc--; } - commands(stdin); + if (!script) + commands(stdin); + cleanup(0); return 0; } |