| ... | ... |
@@ -46,7 +46,9 @@ int main(int argc, char *argv[]) {
|
| 46 | 46 |
if (options.num_lines + 1 > tty_getheight(&tty)) |
| 47 | 47 |
options.num_lines = tty_getheight(&tty) - 1; |
| 48 | 48 |
|
| 49 |
- tty_interface_run(&tty, &choices, &options); |
|
| 49 |
+ tty_interface_t tty_interface; |
|
| 50 |
+ tty_interface_init(&tty_interface, &tty, &choices, &options); |
|
| 51 |
+ tty_interface_run(&tty_interface); |
|
| 50 | 52 |
} |
| 51 | 53 |
|
| 52 | 54 |
choices_destroy(&choices); |
| ... | ... |
@@ -94,9 +94,20 @@ static void emit(choices_t *choices) {
|
| 94 | 94 |
#define KEY_DEL 127 |
| 95 | 95 |
#define KEY_ESC 27 |
| 96 | 96 |
|
| 97 |
-void tty_interface_run(tty_t *tty, choices_t *choices, options_t *options) {
|
|
| 97 |
+void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices, options_t *options) {
|
|
| 98 |
+ state->tty = tty; |
|
| 99 |
+ state->choices = choices; |
|
| 100 |
+ state->options = options; |
|
| 101 |
+ |
|
| 98 | 102 |
if (options->init_search) |
| 99 |
- strncpy(search, options->init_search, SEARCH_SIZE_MAX); |
|
| 103 |
+ strncpy(state->search, options->init_search, SEARCH_SIZE_MAX); |
|
| 104 |
+} |
|
| 105 |
+ |
|
| 106 |
+void tty_interface_run(tty_interface_t *state) {
|
|
| 107 |
+ tty_t *tty = state->tty; |
|
| 108 |
+ choices_t *choices = state->choices; |
|
| 109 |
+ options_t *options = state->options; |
|
| 110 |
+ char *search = state->search; |
|
| 100 | 111 |
|
| 101 | 112 |
choices_search(choices, search); |
| 102 | 113 |
char ch; |
| ... | ... |
@@ -7,6 +7,15 @@ |
| 7 | 7 |
|
| 8 | 8 |
#define SEARCH_SIZE_MAX 4096 |
| 9 | 9 |
|
| 10 |
-void tty_interface_run(tty_t *tty, choices_t *choices, options_t *options); |
|
| 10 |
+typedef struct {
|
|
| 11 |
+ tty_t *tty; |
|
| 12 |
+ choices_t *choices; |
|
| 13 |
+ options_t *options; |
|
| 14 |
+ |
|
| 15 |
+ char search[SEARCH_SIZE_MAX + 1]; |
|
| 16 |
+} tty_interface_t; |
|
| 17 |
+ |
|
| 18 |
+void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices, options_t *options); |
|
| 19 |
+void tty_interface_run(tty_interface_t *state); |
|
| 11 | 20 |
|
| 12 | 21 |
#endif |