From 217884d9204dfd4ebdfcc17f19ef72ab7e4762bf Mon Sep 17 00:00:00 2001 From: nova Date: Sun, 7 Dec 2025 14:36:33 +0100 Subject: [PATCH] multiple small changes --- dir.c | 19 +++++++++---------- interactions.c | 15 ++++++++++----- main.c | 1 - threading.c | 3 ++- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/dir.c b/dir.c index 1ba95bd..f07920c 100644 --- a/dir.c +++ b/dir.c @@ -83,11 +83,7 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten dir_content[i].file_size = file->st_size; dir_content[i].permissions = file->st_mode; - if (S_ISDIR(file->st_mode)) { - dir_content[i].file_type = FILE_TYPE_DIR; - dir_content[i].color_pair = COLOR_DIR; - dir_content[i].file_size = get_dir_size(full_path); - } else if (S_ISLNK(file->st_mode)) { + if (S_ISLNK(file->st_mode)) { stat(full_path, file); if (S_ISDIR(file->st_mode)) { dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK; @@ -97,6 +93,10 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK; dir_content[i].color_pair = COLOR_SYMLINK; } + } else if (S_ISDIR(file->st_mode)) { + dir_content[i].file_type = FILE_TYPE_DIR; + dir_content[i].color_pair = COLOR_DIR; + dir_content[i].file_size = get_dir_size(full_path); } else if (file->st_mode & S_IXUSR) { dir_content[i].file_type = FILE_TYPE_EXEC; dir_content[i].color_pair = COLOR_EXEC; @@ -327,9 +327,6 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file char update_selected_file(){ char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed file */ - if (mid_content->file_name[0] == '\0') { /* only happens if the current path is either empty or inaccessible */ - return ret; - } if (selected_file_current >= mid_file_count) { selected_file_current = mid_file_count-1; } @@ -344,7 +341,7 @@ char update_selected_file(){ return ret; } void dir_set_selected_file_current(unsigned long selected_file_current){ - if (mid_content->file_name[0] != '\0') { + if (mid_content->file_name) { current_dir->selected_file_current = selected_file_current; } } @@ -384,7 +381,9 @@ void dir_init(){ } void recursive_delete(file current_file){ - if (current_file.file_type & FILE_TYPE_DIR) { + if (S_ISLNK(current_file.permissions)) { + remove(current_file.file_name); + } else if (current_file.file_type & FILE_TYPE_DIR ) { unsigned int file_modifiers_tmp = file_modifiers; file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES; unsigned long current_file_count = get_dir_size(current_file.file_name); diff --git a/interactions.c b/interactions.c index 3d91a1a..df8fcae 100644 --- a/interactions.c +++ b/interactions.c @@ -181,7 +181,7 @@ void move_down(unsigned long passes){ selected_file_current += passes; update_selected_file(); - dir_set_selected_file_current(selected_file_current); + current_dir->selected_file_current = selected_file_current; status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0); pthread_mutex_unlock(&mutex_selection); @@ -198,7 +198,8 @@ void move_up(unsigned long passes){ } update_selected_file(); - dir_set_selected_file_current(selected_file_current); + current_dir->selected_file_current = selected_file_current; + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); pthread_mutex_unlock(&mutex_selection); @@ -294,7 +295,7 @@ void jump_bottom(){ pthread_mutex_lock(&mutex_selection); selected_file_current = 0 - 1; update_selected_file(); - dir_set_selected_file_current(selected_file_current); + current_dir->selected_file_current = selected_file_current; status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); pthread_mutex_unlock(&mutex_selection); } @@ -302,7 +303,7 @@ void jump_top(){ pthread_mutex_lock(&mutex_selection); selected_file_current = 0; update_selected_file(); - dir_set_selected_file_current(selected_file_current); + current_dir->selected_file_current = selected_file_current; status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); pthread_mutex_unlock(&mutex_selection); } @@ -341,9 +342,11 @@ void open_with(){ images_clear(); #endif + endwin(); if (system(cmd) == -1) { FAIL("open_with", "creating subcommand failed unhandled"); } + initscr(); } status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); @@ -683,6 +686,7 @@ void cmd_on_selected(unsigned long passes, int index){ /* the second loop is used to add "./", wich is not being printed" */ char *cmd = malloc(sizeof(char)); /* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */ + endwin(); if (hits) { for (i = 0; i < mid_file_count; i++) { if (mid_content[i].status & FILE_STATUS_SELECTED) { @@ -708,6 +712,7 @@ void cmd_on_selected(unsigned long passes, int index){ } /*system(cmd);*/ free(cmd); + initscr(); } free(btm_buffer); @@ -892,7 +897,7 @@ void search(){ curs_set(0); - dir_set_selected_file_current(selected_file_current); + current_dir->selected_file_current = selected_file_current; update_selected_file(); diff --git a/main.c b/main.c index ff9fe9c..632f50b 100644 --- a/main.c +++ b/main.c @@ -37,7 +37,6 @@ char *terminal_width_empty_line; /* used in user_interactions */ void render_pass(); void init(); - int main(){ init(); diff --git a/threading.c b/threading.c index 99ceda0..2286f64 100644 --- a/threading.c +++ b/threading.c @@ -346,7 +346,8 @@ void *thread_btm(){ memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size); - btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-'; + btm_buffer[0] = (S_ISLNK(mid_content[selected_file_current].permissions)) ? 'l': + (S_ISDIR(mid_content[selected_file_current].permissions) ? 'd': '-'); btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-'; btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-'; btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-';