From 81e216e0da3d289da85e68e3d7369ca881e9c3bb Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 20 Jun 2016 00:23:43 -0700 Subject: Extract append_search method --- src/tty_interface.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/tty_interface.c') diff --git a/src/tty_interface.c b/src/tty_interface.c index 797e45f..b6968a0 100644 --- a/src/tty_interface.c +++ b/src/tty_interface.c @@ -142,6 +142,15 @@ static void action_exit(tty_interface_t *state) { state->exit = EXIT_FAILURE; } +static void append_search(tty_interface_t *state, char ch) { + char *search = state->search; + size_t search_size = strlen(search); + if (search_size < SEARCH_SIZE_MAX) { + search[search_size++] = ch; + search[search_size] = '\0'; + } +} + #define KEY_CTRL(key) ((key) - ('@')) #define KEY_DEL 127 #define KEY_ESC 27 @@ -174,18 +183,13 @@ void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices, int tty_interface_run(tty_interface_t *state) { tty_t *tty = state->tty; - char *search = state->search; char ch; while (state->exit < 0) { draw(state); ch = tty_getchar(tty); - size_t search_size = strlen(search); if (isprint(ch)) { - if (search_size < SEARCH_SIZE_MAX) { - search[search_size++] = ch; - search[search_size] = '\0'; - } + append_search(state, ch); } else if (ch == KEY_DEL || ch == KEY_CTRL('H')) { /* DEL || Backspace (C-H) */ action_del_char(state); } else if (ch == KEY_CTRL('U')) { /* C-U */ -- cgit v1.2.3