From f59d5d1b62b1c2b2f505acc535c798e7c47974df Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 Nov 2020 11:33:20 +0100 Subject: Add support for restricting search/output to specific fields. --- src/tty_interface.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/tty_interface.c') diff --git a/src/tty_interface.c b/src/tty_interface.c index 343dde8..305c0eb 100644 --- a/src/tty_interface.c +++ b/src/tty_interface.c @@ -103,7 +103,7 @@ static void draw(tty_interface_t *state) { for (size_t i = start; i < start + num_lines; i++) { tty_printf(tty, "\n"); tty_clearline(tty); - const char *choice = choices_get(choices, i); + const char *choice = choices_get_search(choices, i); if (choice) { draw_match(state, choice, i == choices->selection); } @@ -140,10 +140,11 @@ static void action_emit(tty_interface_t *state) { /* ttyout should be flushed before outputting on stdout */ tty_close(state->tty); - const char *selection = choices_get(state->choices, state->choices->selection); + char *selection = choices_get_output(state->choices, state->choices->selection); if (selection) { /* output the selected result */ printf("%s\n", selection); + free(selection); } else { /* No match, output the query instead */ printf("%s\n", state->search); @@ -237,9 +238,9 @@ static void action_pagedown(tty_interface_t *state) { static void action_autocomplete(tty_interface_t *state) { update_state(state); - const char *current_selection = choices_get(state->choices, state->choices->selection); + const char *current_selection = choices_get_search(state->choices, state->choices->selection); if (current_selection) { - strncpy(state->search, choices_get(state->choices, state->choices->selection), SEARCH_SIZE_MAX); + strncpy(state->search, choices_get_search(state->choices, state->choices->selection), SEARCH_SIZE_MAX); state->cursor = strlen(state->search); } } -- cgit v1.2.3