summaryrefslogtreecommitdiff
path: root/src/tty_interface.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2016-06-20 00:23:43 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2016-06-22 18:32:08 -0700
commit81e216e0da3d289da85e68e3d7369ca881e9c3bb (patch)
treed484e3313a5d7a77d1754c72ae1e6a12e1f6389c /src/tty_interface.c
parent5ab6a38712fb3a691b9e7a232959350063bf71b5 (diff)
Extract append_search method
Diffstat (limited to 'src/tty_interface.c')
-rw-r--r--src/tty_interface.c16
1 files changed, 10 insertions, 6 deletions
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 */