improvenments to the string input loop
This commit is contained in:
@ -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,18 +121,28 @@ 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;
|
||||
} 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';
|
||||
|
||||
timeout(10);
|
||||
@ -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) {
|
||||
|
Reference in New Issue
Block a user