fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 1eb761585ee53188bc5cadaefcfdef567863ba40 parent 7484324060109d6a2d4052ba1672bbf746ac03b8 Author: John Hawthorn <john.hawthorn@gmail.com> Date: Sun, 21 Sep 2014 14:40:36 -0700 Store string in result instead of position Diffstat:
| M | choices.c | | | 12 | ++++++------ |
| M | choices.h | | | 6 | +++--- |
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/choices.c b/choices.c @@ -7,8 +7,8 @@ #define INITIAL_CAPACITY 1 static int cmpchoice(const void *_idx1, const void *_idx2) { - const struct scored_position *a = _idx1; - const struct scored_position *b = _idx2; + const struct scored_result *a = _idx1; + const struct scored_result *b = _idx2; if(a->score == b->score) return 0; @@ -65,7 +65,7 @@ size_t choices_available(choices_t *c){ void choices_search(choices_t *c, const char *search){ choices_reset_search(c); - c->results = malloc(c->size * sizeof(struct scored_position)); + c->results = malloc(c->size * sizeof(struct scored_result)); if(!c->results){ fprintf(stderr, "Error: Can't allocate memory\n"); abort(); @@ -73,18 +73,18 @@ void choices_search(choices_t *c, const char *search){ for(size_t i = 0; i < c->size; i++){ if(has_match(search, c->strings[i])){ - c->results[c->available].position = i; + c->results[c->available].str = c->strings[i]; c->results[c->available].score = match(search, c->strings[i]); c->available++; } } - qsort(c->results, c->available, sizeof(struct scored_position), cmpchoice); + qsort(c->results, c->available, sizeof(struct scored_result), cmpchoice); } const char *choices_get(choices_t *c, size_t n){ if(n < c->available){ - return c->strings[c->results[n].position]; + return c->results[n].str; }else{ return NULL; } diff --git a/choices.h b/choices.h @@ -1,9 +1,9 @@ #ifndef CHOICES_H #define CHOICES_H CHOICES_H -struct scored_position { - size_t position; +struct scored_result { double score; + const char *str; }; typedef struct { @@ -11,7 +11,7 @@ typedef struct { size_t size; const char **strings; - struct scored_position *results; + struct scored_result *results; size_t available; size_t selection;