Browse code

Refactor into tty_moveup

John Hawthorn authored on 17/08/2014 03:33:24
Showing 3 changed files

  • fzy.c index 96b810e..e44154b 100644
  • tty.c index a96aafc..be3e388 100644
  • tty.h index fa32203..a339a71 100644
... ...
@@ -94,7 +94,7 @@ void clear(tty_t *tty){
94 94
 	while(line++ < NUMLINES + 1){
95 95
 		tty_newline(tty);
96 96
 	}
97
-	fprintf(tty->fout, "%c%c%iA", 0x1b, '[', line-1);
97
+	tty_moveup(tty, line-1);
98 98
 	tty_setcol(tty, 0);
99 99
 }
100 100
 
... ...
@@ -137,7 +137,7 @@ void draw(tty_t *tty){
137 137
 		draw_match(tty, choices[choices_sorted[i]], i == current_selection);
138 138
 		line++;
139 139
 	}
140
-	fprintf(tty->fout, "%c%c%iA", 0x1b, '[', line + 1);
140
+	tty_moveup(tty, line + 1);
141 141
 	tty_setcol(tty, strlen(prompt) + strlen(search) + 1);
142 142
 	fflush(tty->fout);
143 143
 }
... ...
@@ -67,6 +67,10 @@ void tty_setcol(tty_t *tty, int col){
67 67
 	tty_printf(tty, "%c%c%iG", 0x1b, '[', col);
68 68
 }
69 69
 
70
+void tty_moveup(tty_t *tty, int i){
71
+	tty_printf(tty, "%c%c%iA", 0x1b, '[', i);
72
+}
73
+
70 74
 void tty_printf(tty_t *tty, const char *fmt, ...){
71 75
 	va_list args;
72 76
 	va_start(args, fmt);
... ...
@@ -34,6 +34,7 @@ void tty_setnormal(tty_t *tty);
34 34
  */
35 35
 void tty_newline(tty_t *tty);
36 36
 
37
+void tty_moveup(tty_t *tty, int i);
37 38
 void tty_setcol(tty_t *tty, int col);
38 39
 
39 40
 void tty_printf(tty_t *tty, const char *fmt, ...);