diff options
-rw-r--r-- | src/fzy.c | 4 | ||||
-rw-r--r-- | src/options.h | 5 | ||||
-rw-r--r-- | src/tty_interface.c | 15 | ||||
-rw-r--r-- | src/tty_interface.h | 11 |
4 files changed, 31 insertions, 4 deletions
@@ -46,7 +46,9 @@ int main(int argc, char *argv[]) { if (options.num_lines + 1 > tty_getheight(&tty)) options.num_lines = tty_getheight(&tty) - 1; - tty_interface_run(&tty, &choices, &options); + tty_interface_t tty_interface; + tty_interface_init(&tty_interface, &tty, &choices, &options); + tty_interface_run(&tty_interface); } choices_destroy(&choices); diff --git a/src/options.h b/src/options.h index e19e292..1f461bc 100644 --- a/src/options.h +++ b/src/options.h @@ -1,3 +1,6 @@ +#ifndef OPTIONS_H +#define OPTIONS_H OPTIONS_H + typedef struct { int benchmark; const char *filter; @@ -10,3 +13,5 @@ typedef struct { } options_t; void options_parse(options_t *options, int argc, char *argv[]); + +#endif diff --git a/src/tty_interface.c b/src/tty_interface.c index 69c3ab1..38b0dc0 100644 --- a/src/tty_interface.c +++ b/src/tty_interface.c @@ -94,9 +94,20 @@ static void emit(choices_t *choices) { #define KEY_DEL 127 #define KEY_ESC 27 -void tty_interface_run(tty_t *tty, choices_t *choices, options_t *options) { +void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices, options_t *options) { + state->tty = tty; + state->choices = choices; + state->options = options; + if (options->init_search) - strncpy(search, options->init_search, SEARCH_SIZE_MAX); + strncpy(state->search, options->init_search, SEARCH_SIZE_MAX); +} + +void tty_interface_run(tty_interface_t *state) { + tty_t *tty = state->tty; + choices_t *choices = state->choices; + options_t *options = state->options; + char *search = state->search; choices_search(choices, search); char ch; diff --git a/src/tty_interface.h b/src/tty_interface.h index e1240c3..4122271 100644 --- a/src/tty_interface.h +++ b/src/tty_interface.h @@ -7,6 +7,15 @@ #define SEARCH_SIZE_MAX 4096 -void tty_interface_run(tty_t *tty, choices_t *choices, options_t *options); +typedef struct { + tty_t *tty; + choices_t *choices; + options_t *options; + + char search[SEARCH_SIZE_MAX + 1]; +} tty_interface_t; + +void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices, options_t *options); +void tty_interface_run(tty_interface_t *state); #endif |