Browse code

Use score_t instead of double

John Hawthorn authored on 27/06/2016 08:14:44
Showing 3 changed files

... ...
@@ -216,7 +216,7 @@ const char *choices_get(choices_t *c, size_t n) {
216 216
 	}
217 217
 }
218 218
 
219
-double choices_getscore(choices_t *c, size_t n) {
219
+score_t choices_getscore(choices_t *c, size_t n) {
220 220
 	return c->results[n].score;
221 221
 }
222 222
 
... ...
@@ -3,8 +3,10 @@
3 3
 
4 4
 #include <stdio.h>
5 5
 
6
+#include "match.h"
7
+
6 8
 struct scored_result {
7
-	double score;
9
+	score_t score;
8 10
 	const char *str;
9 11
 };
10 12
 
... ...
@@ -31,7 +33,7 @@ void choices_add(choices_t *c, const char *choice);
31 33
 size_t choices_available(choices_t *c);
32 34
 void choices_search(choices_t *c, const char *search);
33 35
 const char *choices_get(choices_t *c, size_t n);
34
-double choices_getscore(choices_t *c, size_t n);
36
+score_t choices_getscore(choices_t *c, size_t n);
35 37
 void choices_prev(choices_t *c);
36 38
 void choices_next(choices_t *c);
37 39
 
... ...
@@ -30,12 +30,17 @@ static void draw_match(tty_interface_t *state, const char *choice, int selected)
30 30
 	for (int i = 0; i < n + 1; i++)
31 31
 		positions[i] = -1;
32 32
 
33
-	double score = match_positions(search, choice, &positions[0]);
33
+	score_t score = match_positions(search, choice, &positions[0]);
34 34
 
35 35
 	size_t maxwidth = tty_getwidth(tty);
36 36
 
37
-	if (options->show_scores)
38
-		tty_printf(tty, "(%5.2f) ", score);
37
+	if (options->show_scores) {
38
+		if (score == SCORE_MIN) {
39
+			tty_printf(tty, "(     ) ");
40
+		} else {
41
+			tty_printf(tty, "(%5.2f) ", score);
42
+		}
43
+	}
39 44
 
40 45
 	if (selected)
41 46
 		tty_setinvert(tty);