Browse code

Avoid full clear before redraw

Instead of clearing the existing text before redrawing, clear as we draw
using tty_newline (CSI-K). This looks smoother when scrolling under
xterm and probably other terminals.

John Hawthorn authored on 17/08/2014 03:39:06
Showing 1 changed files

  • fzy.c index fa3e50f..28cc6ce 100644
... ...
@@ -120,7 +120,7 @@ void draw_match(tty_t *tty, const char *choice, int selected){
120 120
 		}
121 121
 		tty_printf(tty, "%c", choice[i]);
122 122
 	}
123
-	tty_printf(tty, "\n");
123
+	tty_newline(tty);
124 124
 	tty_setnormal(tty);
125 125
 }
126 126
 
... ...
@@ -131,10 +131,15 @@ void draw(tty_t *tty){
131 131
 	}
132 132
 	int line = 0;
133 133
 	const char *prompt = "> ";
134
-	clear(tty);
135
-	tty_printf(tty, "%s%s\n", prompt, search);
136
-	for(size_t i = start; line < NUMLINES && i < choices_available; i++){
137
-		draw_match(tty, choices[choices_sorted[i]], i == current_selection);
134
+	tty_setcol(tty, 0);
135
+	tty_printf(tty, "%s%s", prompt, search);
136
+	tty_newline(tty);
137
+	for(size_t i = start; line < NUMLINES; i++){
138
+		if(i < choices_available){
139
+			draw_match(tty, choices[choices_sorted[i]], i == current_selection);
140
+		}else{
141
+			tty_newline(tty);
142
+		}
138 143
 		line++;
139 144
 	}
140 145
 	tty_moveup(tty, line + 1);