Browse code

termios should be reset on successful exit.

Still needs to be fixed on an exit due to ^C

Thanks @rtandy

John Hawthorn authored on 19/10/2014 23:19:24
Showing 3 changed files

  • fzy.c index 6eee30f..7663b71 100644
  • tty.c index ec32fd7..6939eb9 100644
  • tty.h index 1f3a4f7..76c5d03 100644
... ...
@@ -157,7 +157,7 @@ void run(tty_t *tty, choices_t *choices){
157 157
 			clear(tty);
158 158
 
159 159
 			/* ttyout should be flushed before outputting on stdout */
160
-			fclose(tty->fout);
160
+			tty_close(tty);
161 161
 
162 162
 			emit(choices);
163 163
 		}else if(ch == 27){ /* ESC */
... ...
@@ -12,6 +12,12 @@ void tty_reset(tty_t *tty){
12 12
 	tcsetattr(tty->fdin, TCSANOW, &tty->original_termios);
13 13
 }
14 14
 
15
+void tty_close(tty_t *tty){
16
+	tty_reset(tty);
17
+	fclose(tty->fout);
18
+	close(tty->fdin);
19
+}
20
+
15 21
 void tty_init(tty_t *tty, const char *tty_filename){
16 22
 	tty->fdin = open(tty_filename, O_RDONLY);
17 23
 	tty->fout = fopen(tty_filename, "w");
... ...
@@ -13,6 +13,7 @@ typedef struct{
13 13
 } tty_t;
14 14
 
15 15
 void tty_reset(tty_t *tty);
16
+void tty_close(tty_t *tty);
16 17
 void tty_init(tty_t *tty, const char *tty_filename);
17 18
 void tty_getwinsz(tty_t *tty);
18 19
 char tty_getchar(tty_t *tty);