Browse code

Define number of lines as a macro

John Hawthorn authored on 04/08/2014 05:03:07
Showing 1 changed files

  • fzy.c index dd25cde..ae07202 100644
... ...
@@ -82,13 +82,15 @@ void run_search(char *needle){
82 82
 	qsort(choices_sorted, choices_available, sizeof(size_t), cmpchoice);
83 83
 }
84 84
 
85
+#define NUMLINES 10
86
+
85 87
 int search_size;
86 88
 char search[4096] = {0};
87 89
 
88 90
 void clear(tty_t *tty){
89 91
 	fprintf(tty->fout, "%c%c0G", 0x1b, '[');
90 92
 	int line = 0;
91
-	while(line++ < 10 + 1){
93
+	while(line++ < NUMLINES + 1){
92 94
 		fprintf(tty->fout, "%c%cK\n", 0x1b, '[');
93 95
 	}
94 96
 	fprintf(tty->fout, "%c%c%iA", 0x1b, '[', line-1);
... ...
@@ -121,7 +123,7 @@ void draw(tty_t *tty){
121 123
 	const char *prompt = "> ";
122 124
 	clear(tty);
123 125
 	fprintf(tty->fout, "%s%s\n", prompt, search);
124
-	for(size_t i = 0; line < 10 && i < choices_available; i++){
126
+	for(size_t i = 0; line < NUMLINES && i < choices_available; i++){
125 127
 		if(i == current_selection)
126 128
 			fprintf(tty->fout, "%c%c7m", 0x1b, '[');
127 129
 		draw_match(tty, choices[choices_sorted[i]], i == current_selection);
... ...
@@ -173,9 +175,9 @@ void run(tty_t *tty){
173 175
 				search[search_size] = '\0';
174 176
 			run_search(search);
175 177
 		}else if(ch == 14){ /* C-N */
176
-			current_selection = (current_selection + 1) % 10;
178
+			current_selection = (current_selection + 1) % NUMLINES;
177 179
 		}else if(ch == 16){ /* C-P */
178
-			current_selection = (current_selection + 9) % 10;
180
+			current_selection = (current_selection + NUMLINES - 1) % NUMLINES;
179 181
 		}else if(ch == 10){ /* Enter */
180 182
 			clear(tty);
181 183
 			emit(tty);