propper input handling

This commit is contained in:
nova
2025-07-03 00:58:31 +02:00
parent 0a6509310d
commit f320449572
4 changed files with 74 additions and 27 deletions

View File

@ -2,6 +2,7 @@
#include <pthread.h>
#include <dirent.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include "defines.h"
@ -31,14 +32,43 @@ extern unsigned long mid_file_count;
extern unsigned int status;
int read_string(WINDOW *win, int y, int x, char *str);
unsigned int timeout_time = 0;
extern char *input;
unsigned int input_pass;
int parsed_input_number;
void user_interactions(char *input, WINDOW *win_b) {
void (*func_ptr)();
void user_interactions() {
char ch;
move(terminal_height, terminal_width);
ch = getch();
if(ch != ERR) {
timeout(10); /* blocking timeout of getch() */
mvaddch(terminal_height-1, (terminal_width/3)*2 +input_pass, ch);
input[input_pass] = ch;
input_pass++;
}
void (*func_ptr)(int);
unsigned long i = 0;
unsigned int j = 0;
for (i = 0; i < binding_count; i++) {
if (*input == key_binding[i].key[0]) {
if (strstr(input, key_binding[i].key)) {
parsed_input_number = 0;
while((*input >= '0') && (*input <= '9')) {
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
input++;
}
func_ptr = key_binding[i].func;
func_ptr();
func_ptr(parsed_input_number);
memset(input, 0, 255);
input_pass = 0;
timeout(100); /* blocking timeout of getch() */
}
}
}
@ -54,23 +84,38 @@ void toggle_selection(){
pthread_mutex_unlock(&mutex_mid);
pthread_mutex_unlock(&mutex_selection);
}
void move_down(){
void move_down(int passes){
pthread_mutex_lock(&mutex_selection);
if (passes == 0) {
passes++;
}
/*capping the maximum file is done inside thread_mid */
selected_file_current++;
selected_file_current += passes;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
}
void move_up(){
void move_up(int passes){
pthread_mutex_lock(&mutex_selection);
if (selected_file_current != 0) {
selected_file_current--;
if (passes == 0) {
passes++;
}
int i;
for (i = 0; i < passes; i++) {
if (selected_file_current != 0) {
selected_file_current--;
}
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
}
void move_right(){
chdir("..");
void move_right(int passes){
if (passes == 0) {
passes++;
}
int i;
for (i = 0; i < passes; i++) {
chdir("..");
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void move_left(){
@ -118,7 +163,6 @@ void jump_top(){
}
int read_string(WINDOW *win, int y, int x, char *str){
noecho();
curs_set(1);
timeout(-1); /* negative numbers block until enter is pressed */
@ -151,7 +195,6 @@ int read_string(WINDOW *win, int y, int x, char *str){
str[pass] = '\0';
timeout(10);
noecho();
curs_set(0);
return err;
@ -311,3 +354,8 @@ void delete(){
}
}
void makedir(){
mkdir("mk", 755); /*magic number from default permissions as created by mkdir*/
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
}