summaryrefslogtreecommitdiff
path: root/src/tty_interface.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-11-24 11:33:20 +0100
committerAnton Khirnov <anton@khirnov.net>2020-11-24 14:51:13 +0100
commitf59d5d1b62b1c2b2f505acc535c798e7c47974df (patch)
tree4712dc4ccd48c6fbc3b2406aa48c29e3bf359171 /src/tty_interface.c
parent395a2534aca4a704da7501c5e79268420e41d174 (diff)
Add support for restricting search/output to specific fields.fields
Diffstat (limited to 'src/tty_interface.c')
-rw-r--r--src/tty_interface.c9
1 files changed, 5 insertions, 4 deletions
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);
}
}