From c29870998e3e91174ab94621f859c28885b7fb7d Mon Sep 17 00:00:00 2001 From: nova Date: Sun, 22 Jun 2025 02:06:36 +0200 Subject: [PATCH] improvenments to the string input loop --- interactions.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/interactions.c b/interactions.c index beedc55..5f0c9b2 100644 --- a/interactions.c +++ b/interactions.c @@ -26,7 +26,7 @@ extern char *btm_buffer; extern unsigned int status; void open_with_pass_2(); void rename_hovered_pass_2(); -int read_string(char *str); +int read_string(WINDOW *win, int y, int x, char *str); void user_interactions(char *input, WINDOW *win_b) { void (*func_ptr)(); @@ -112,8 +112,8 @@ void jump_top(){ pthread_mutex_unlock(&mutex_selection); } -int read_string(char *str){ - echo(); +int read_string(WINDOW *win, int y, int x, char *str){ + noecho(); curs_set(1); timeout(-1); /* negative numbers block until enter is pressed */ @@ -121,17 +121,27 @@ int read_string(char *str){ unsigned int pass = 0; char ch; char err = 0; + + wmove(win, y, x); while(1) { - ch = getch(); + /*ch = mvwgetch(win, y, x + pass);*/ + ch = wgetch(win); if (ch == '\n') { err = 0; break; } else if (ch == 27) { /* esc key */ err = 1; break; - } - str[pass] = ch; - pass++; + } else if (ch == 127) { /* backspace */ + if (pass > 0) { + pass--; + mvwdelch(win, y, pass); + } + } else { + mvwaddch(win, y, x +pass, ch); + str[pass] = ch; + pass++; + } } str[pass] = '\0'; @@ -157,7 +167,7 @@ void open_with_pass_2(WINDOW *win_b){ /* TODO(2025-06-22T01:24:36) fix fixed buffer size */ char *str = malloc(255); memset(str, ' ', 255); - int err = read_string(str); + int err = read_string(win_b, local_height - 1, 0 , str); if (!err) { @@ -178,7 +188,7 @@ void open_with_pass_2(WINDOW *win_b){ free(str); } -void rename_hovered(WINDOW *win_b){ +void rename_hovered(){ btm_buffer = concat("rename \"", file_current.file_name); btm_buffer = concat(btm_buffer, "\" to:"); @@ -195,7 +205,7 @@ void rename_hovered_pass_2(WINDOW *win_b){ /* TODO(2025-06-22T01:24:30) fix fixed buffer size */ char *str = malloc(255); memset(str, ' ', 255); - int err = read_string(str); + int err = read_string(win_b, local_height - 1, 0, str); if (!err) {