From 5287c77648cc13be501681a1b531780dea03a2d1 Mon Sep 17 00:00:00 2001 From: nova Date: Sun, 9 Nov 2025 17:40:56 +0100 Subject: [PATCH] varrious small changes --- config.h | 5 +++-- interactions.c | 35 +++++++++-------------------------- main.c | 40 ++++++++++++++++++---------------------- 3 files changed, 30 insertions(+), 50 deletions(-) diff --git a/config.h b/config.h index 62cd060..48a330b 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,7 @@ #define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */ -#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching */ -#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds of how often the directory should be reload */ +#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching; depends on ueberzug */ +#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds between automatic refresh of dir contents */ +#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */ /* {{{ */ #ifndef CONFIG_GUARD diff --git a/interactions.c b/interactions.c index ab246ce..1b6f6e5 100644 --- a/interactions.c +++ b/interactions.c @@ -64,53 +64,42 @@ void user_interactions() { char ch; unsigned long i; unsigned long binding_matches = 0; - static char binding_pass = 0; ch = getch(); if(ch != ERR) { - timeout(10); /* blocking timeout of getch() */ input[input_pass] = ch; input_pass++; if (ch == 27) { /* esc key */ - memset(input, ' ', terminal_width); - mvaddstr(terminal_height-1, (terminal_width/3)*2, input); memset(input, 0, INPUT_BUFFER_SIZE); input_pass = 0; - timeout(100); /* blocking timeout of getch() */ } - binding_pass = 0; status |= STATUS_UPDATE_SCREEN_0; - } else { - timeout(100); } - mvaddstr(terminal_height-1, (terminal_width/3)*2, input); - void (*func_ptr)(int, int); unsigned long number_length = 0; - if (!binding_pass) { - parsed_input_number = 0; - while((*input >= '0') && (*input <= '9')) { - parsed_input_number = (parsed_input_number * 10) + (*input - '0'); - input++; - number_length++; - } - input -= number_length; - binding_pass = 1; + parsed_input_number = 0; + while((*input >= '0') && (*input <= '9')) { + parsed_input_number = (parsed_input_number * 10) + (*input - '0'); + input++; + number_length++; } + input -= number_length; char cmp_len = strlen(input); if(strlen(input) < 1) { - cmp_len++; + cmp_len = 1; } for (i = 0; i < binding_count; i++) { if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) { if (strcmp(input + number_length, key_binding[i].key) == 0) { func_ptr = key_binding[i].func; func_ptr(parsed_input_number, i); + + timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */ } else { binding_matches++; mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t"); @@ -127,10 +116,8 @@ void user_interactions() { } else if (number_length != strlen(input)) { memset(input, 0, INPUT_BUFFER_SIZE); input_pass = 0; - binding_pass = 0; number_length = 0; binding_matches = 0; - timeout(100); /* blocking timeout of getch() */ } } int read_string(WINDOW *win, int y, int x, char *str){ @@ -169,7 +156,6 @@ int read_string(WINDOW *win, int y, int x, char *str){ } str[pass] = '\0'; - timeout(100); curs_set(0); return err; @@ -487,7 +473,6 @@ void delete(){ free(file_str); } - timeout(10); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); pthread_mutex_unlock(&mutex_btm); @@ -719,7 +704,6 @@ void cmd_on_selected(unsigned long passes, int index){ free(btm_buffer); btm_buffer = btm_buffer_tmp; - timeout(10); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); if (hits) { @@ -900,7 +884,6 @@ void search(){ } search_buffer[pass] = '\0'; - timeout(10); curs_set(0); dir_set_selected_file_current(selected_file_current); diff --git a/main.c b/main.c index 88e14ad..7677adc 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,7 @@ #include #include "defines.h" +#include "config.h" #include "threading.h" #include "window.c" #include "colors.h" @@ -58,7 +59,6 @@ int main(){ pthread_t thread_m; pthread_t thread_r; - char threading = 0; terminal_width_empty_line = malloc(terminal_width); #if SETTINGS_RELOAD_DIR_DELTA != 0 time_t t; @@ -71,7 +71,17 @@ int main(){ pthread_create(&thread_m, NULL, thread_mid, &status); /*current_content slash win_m*/ pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/ pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/ - + + + /* running through all once manually in order to get an as fast as possible first render on the screen */ + pthread_cond_signal(&cond_top); + pthread_cond_signal(&cond_mid); + pthread_cond_signal(&cond_lft); + user_interactions(); + render_pass(); + timeout(SETTINGS_CURSES_TIMEOUT); + + while(!(status & STATUS_QUIT_PROGRAM)){ getmaxyx(stdscr, terminal_height, terminal_width); @@ -80,21 +90,17 @@ int main(){ temp_width = terminal_width; temp_heigth = terminal_height; } - if (threading) { - status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME); - threading = 0; - } if (status & STATUS_RUN_BACKEND) { pthread_cond_signal(&cond_top); pthread_cond_signal(&cond_mid); pthread_cond_signal(&cond_lft); status &= ~(STATUS_RUN_BACKEND); status |= STATUS_UPDATE_SCREEN_0; - threading = 1; + } else { + status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME); } user_interactions(); - render_pass(); #if SETTINGS_RELOAD_DIR_DELTA != 0 @@ -112,16 +118,6 @@ int main(){ threading_free(); free(start_path); - /* - if (threading) { - pthread_join(thread_l, NULL); - pthread_join(thread_r, NULL); - pthread_join(thread_m, NULL); - pthread_join(thread_t, NULL); - pthread_join(thread_b, NULL); - } - */ - delwin(win_l); delwin(win_m); delwin(win_r); @@ -143,9 +139,6 @@ void render_pass(){ status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL; } - /*TODO: check if deallocation of window and reallocation is faster than this or not */ - - wresize(win_t, 1, terminal_width); wresize(win_l, terminal_height-2, terminal_width/8); wresize(win_m, terminal_height-2, (terminal_width/2)-(terminal_width/8)); @@ -183,7 +176,10 @@ void init() { setlocale(LC_ALL, ""); initscr(); /* start ncurses */ noecho(); /* hide keyboard input */ - timeout(0); /* blocking timeout of getch() */ + timeout(10); /* blocking timeout of getch(), using 10 rather than SETTINGS_CURSES_TIMEOUT to cause a faster first render + regardless on SETTINGS_CURSES_TIMEOUT, 10 was taken arbitrary. + if the blocking is too low, the first render happens delayed, however even this delay causes a quicker than + (compute time of threads) + timeout */ curs_set(0); /*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/