| ... | ... |
@@ -142,6 +142,15 @@ static void action_exit(tty_interface_t *state) {
|
| 142 | 142 |
state->exit = EXIT_FAILURE; |
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 |
+static void append_search(tty_interface_t *state, char ch) {
|
|
| 146 |
+ char *search = state->search; |
|
| 147 |
+ size_t search_size = strlen(search); |
|
| 148 |
+ if (search_size < SEARCH_SIZE_MAX) {
|
|
| 149 |
+ search[search_size++] = ch; |
|
| 150 |
+ search[search_size] = '\0'; |
|
| 151 |
+ } |
|
| 152 |
+} |
|
| 153 |
+ |
|
| 145 | 154 |
#define KEY_CTRL(key) ((key) - ('@'))
|
| 146 | 155 |
#define KEY_DEL 127 |
| 147 | 156 |
#define KEY_ESC 27 |
| ... | ... |
@@ -174,18 +183,13 @@ void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices, |
| 174 | 183 |
|
| 175 | 184 |
int tty_interface_run(tty_interface_t *state) {
|
| 176 | 185 |
tty_t *tty = state->tty; |
| 177 |
- char *search = state->search; |
|
| 178 | 186 |
|
| 179 | 187 |
char ch; |
| 180 | 188 |
while (state->exit < 0) {
|
| 181 | 189 |
draw(state); |
| 182 | 190 |
ch = tty_getchar(tty); |
| 183 |
- size_t search_size = strlen(search); |
|
| 184 | 191 |
if (isprint(ch)) {
|
| 185 |
- if (search_size < SEARCH_SIZE_MAX) {
|
|
| 186 |
- search[search_size++] = ch; |
|
| 187 |
- search[search_size] = '\0'; |
|
| 188 |
- } |
|
| 192 |
+ append_search(state, ch); |
|
| 189 | 193 |
} else if (ch == KEY_DEL || ch == KEY_CTRL('H')) { /* DEL || Backspace (C-H) */
|
| 190 | 194 |
action_del_char(state); |
| 191 | 195 |
} else if (ch == KEY_CTRL('U')) { /* C-U */
|