summaryrefslogtreecommitdiff
path: root/gramscii.c
diff options
context:
space:
mode:
Diffstat (limited to 'gramscii.c')
-rw-r--r--gramscii.c28
1 files changed, 18 insertions, 10 deletions
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;
}