summaryrefslogtreecommitdiff
path: root/fzy.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2014-08-19 19:35:45 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2014-08-19 19:42:48 -0700
commit4ba1c827e80b5a4cc9168fd9a85907006addc183 (patch)
tree829c38ab03192bf6116b1b3e66b6f365e9879c20 /fzy.c
parent4f0a193f41ca40da1f83ecf06bd58f6e9d0c9892 (diff)
Flag to show scores of matches
Diffstat (limited to 'fzy.c')
-rw-r--r--fzy.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/fzy.c b/fzy.c
index b015e99..d36f82b 100644
--- a/fzy.c
+++ b/fzy.c
@@ -8,6 +8,8 @@
#include "fzy.h"
#include "tty.h"
+int flag_show_scores = 0;
+
#define INITIAL_CAPACITY 1
int choices_capacity = 0;
int choices_n = 0;
@@ -136,7 +138,10 @@ void draw(tty_t *tty){
tty_newline(tty);
for(size_t i = start; i < start + NUMLINES; i++){
if(i < choices_available){
- draw_match(tty, choices[choices_sorted[i]], i == current_selection);
+ size_t choice_idx = choices_sorted[i];
+ if(flag_show_scores)
+ tty_printf(tty, "(%5.2f) ", choices_score[choice_idx]);
+ draw_match(tty, choices[choice_idx], i == current_selection);
}else{
tty_newline(tty);
}
@@ -218,6 +223,7 @@ void run(tty_t *tty){
static const char *usage_str = ""
"USAGE: fzy [OPTION]...\n"
+" -s, --show-scores show the scores of each match\n"
" -h, --help display this help and exit\n"
" -v, --version output version information and exit\n";
@@ -227,6 +233,7 @@ void usage(const char *argv0){
}
static struct option longopts[] = {
+ { "show-scores", no_argument, NULL, 's' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
@@ -235,11 +242,14 @@ static struct option longopts[] = {
int main(int argc, char *argv[]){
char c;
- while((c = getopt_long(argc, argv, "vh", longopts, NULL)) != -1){
+ while((c = getopt_long(argc, argv, "vhs", longopts, NULL)) != -1){
switch(c){
case 'v':
printf("%s " VERSION " (c) 2014 John Hawthorn\n", argv[0]);
exit(EXIT_SUCCESS);
+ case 's':
+ flag_show_scores = 1;
+ break;
case 'h':
default:
usage(argv[0]);