From 0522ef659553292f546fb1f3af43cfd2f4b07bb2 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 12 Aug 2019 09:02:50 +0100 Subject: fix read of command scripts and script-mode --- TODO | 2 +- gramscii.1 | 4 ---- gramscii.c | 28 ++++++++++++++++++---------- gramscii.h | 2 +- lineset.c | 2 +- screen.c | 34 +++++++++++++++++++--------------- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/TODO b/TODO index 7c93df8..54225d6 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ + optimize redraws (redraw only the modified rectangle) -- fix bug in reading commands from files - add screen geometry option (-g 25x80?) - maybe move "text" mode to "t" - implement ellipse @@ -15,6 +14,7 @@ - allow scrolling (both vertical and horizontal) - catch SIGWINCH and react appropriately (after scrolling is enabled) +* fix bug in reading commands from files * fix bug in visual crop * read file at point * read output of command (!) diff --git a/gramscii.1 b/gramscii.1 index 029c6fe..90a14db 100644 --- a/gramscii.1 +++ b/gramscii.1 @@ -575,10 +575,6 @@ would automatically save the screen into "filename". gramscii currently manages only a fixed screen of the same size of the screen where it starts from. This will be changed in a future release to support scrolling and "virtual" screens of any (reasonable) size. -.PP -There is currently a bug with files read before accepting commands: the -result of the commands read from the files is not show immediately, and not -shown correctly. .SH AUTHORS gramscii is written and maintained by Vincenzo "KatolaZ" Nicosia . You can use, copy, modify, and redistribute diff --git a/gramscii.c b/gramscii.c index ba4d7e2..8d453f7 100644 --- a/gramscii.c +++ b/gramscii.c @@ -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; } diff --git a/gramscii.h b/gramscii.h index 6419961..0bad4f2 100644 --- a/gramscii.h +++ b/gramscii.h @@ -129,7 +129,7 @@ char modified; /* set to 1 if screen modified since last save */ char fname[256]; -char silent; /* set to 1 in script-mode */ +char script; /* set to 1 in script-mode */ char autoend; /* set to 1 in auto-arrow mode */ /* Used by draw_arrow to identify the bounding box */ diff --git a/lineset.c b/lineset.c index 7a244e5..4710c59 100644 --- a/lineset.c +++ b/lineset.c @@ -62,7 +62,7 @@ void ensure_num_lines(lineset_t *ls, int n){ void dump_lines(lineset_t ls, FILE *f){ int i; for (i=0; i