summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-08-12 09:02:50 +0100
committerKatolaZ <katolaz@freaknet.org>2019-08-12 09:02:50 +0100
commit0522ef659553292f546fb1f3af43cfd2f4b07bb2 (patch)
treeaf5c439fa02a4afdd5f887e86180b39857d9c5f0
parenta46183e96042cf751199f0a06d437a599f7f5bf8 (diff)
fix read of command scripts and script-mode
-rw-r--r--TODO2
-rw-r--r--gramscii.14
-rw-r--r--gramscii.c28
-rw-r--r--gramscii.h2
-rw-r--r--lineset.c2
-rw-r--r--screen.c34
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
<katolaz@freaknet.org>. 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<ls.num ;i++){
- fprintf(f, "%d:%s\n", i, ls.l[i].s);
+ fprintf(f, "%s\n", ls.l[i].s);
}
fflush(f);
}
diff --git a/screen.c b/screen.c
index d60abb2..d85ff81 100644
--- a/screen.c
+++ b/screen.c
@@ -58,7 +58,7 @@ char get_mark(char dir){
void status_bar(){
- if (silent)
+ if (script)
return;
printf("\033[%d;1f\033[7m", HEIGHT+1);
printf("%*s", WIDTH-1, "");
@@ -78,7 +78,7 @@ void status_bar(){
char get_key(FILE *fc, char *msg){
- if (silent)
+ if (script)
return 0;
printf("\033[%d;1f\033[7m", HEIGHT+1);
printf("%*s", WIDTH, "");
@@ -92,7 +92,7 @@ char get_key(FILE *fc, char *msg){
void get_string(FILE *fc, char *msg, char *s, int sz){
- if (!silent){
+ if (!script){
printf("\033[%d;1f\033[7m", HEIGHT+1);
printf("%*s", WIDTH, "");
printf("\033[%d;1f\033[7m", HEIGHT+1);
@@ -106,9 +106,10 @@ void get_string(FILE *fc, char *msg, char *s, int sz){
}
fgets(s, sz, fc);
s[strlen(s)-1] = '\0';
- tcsetattr(0, TCSANOW, &t2);
- if (!silent)
+ if (!script){
+ tcsetattr(0, TCSANOW, &t2);
fflush(stdout);
+ }
}
int is_yes(char c){
@@ -119,7 +120,7 @@ int is_yes(char c){
void show_cursor(){
- if (silent)
+ if (script)
return;
printf("\033[%d;%df", y+1, x+1);
fflush(stdout);
@@ -144,7 +145,7 @@ void set_cur(char c){
void draw_xy(int x, int y, char c){
/* FIXME: check if x and y are valid!!!! */
- if (silent)
+ if (script)
return;
printf("\033[%d;%df",y+1,x+1);
putchar(c);
@@ -152,7 +153,7 @@ void draw_xy(int x, int y, char c){
}
void update_current(){
- if (silent)
+ if (script)
return;
printf("\033[%d;%df",y+1,x+1);
putchar(screen.l[y].s[x]);
@@ -226,7 +227,7 @@ void reset_styles(){
void redraw(){
int i;
- if (silent)
+ if (script)
return;
printf("\033[2J\033[1;1H");
for (i=0;i<HEIGHT;i++){
@@ -254,9 +255,9 @@ void go_to(int where){
show_cursor();
}
-void handle_goto(char global){
+void handle_goto(FILE *fc, char global){
char c;
- c=getchar();
+ c=fgetc(fc);
switch(c){
case 'h':
dir = DIR_L;
@@ -348,6 +349,9 @@ int move_around(char c, FILE *fc, char global){
mult += c - '0';
return 0;
}
+#ifdef DEBUG
+ fprintf(stderr, "got char: %c\n", c);
+#endif
switch(c){
case 27: /* control sequence? */
c = get_escape(fc);
@@ -382,11 +386,11 @@ int move_around(char c, FILE *fc, char global){
break;
case 'g':
#ifdef DEBUG
- fprintf(stderr, "before global: step: %d x: %d y: %d\n", step, x, y);
+ fprintf(stderr, "before handle_goto: step: %d x: %d y: %d global: %d\n", step, x, y, global);
#endif
- handle_goto(global);
+ handle_goto(fc, global);
#ifdef DEBUG
- fprintf(stderr, "after global: step: %d x: %d y: %d\n", step, x, y);
+ fprintf(stderr, "after handle_goto: step: %d x: %d y: %d global: %d\n", step, x, y, global);
#endif
break;
default:
@@ -398,7 +402,7 @@ int move_around(char c, FILE *fc, char global){
void set_video(int v){
- if (silent)
+ if (script)
return;
printf("\033[%dm", v);
fflush(stdout);