1
0
mirror of https://gittea.dev/nova/th.git synced 2026-01-30 16:50:10 -05:00

multiple small changes

This commit is contained in:
nova
2025-12-07 14:36:33 +01:00
parent 3a891388ed
commit 217884d920
4 changed files with 21 additions and 17 deletions

19
dir.c
View File

@@ -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].file_size = file->st_size;
dir_content[i].permissions = file->st_mode; dir_content[i].permissions = file->st_mode;
if (S_ISDIR(file->st_mode)) { if (S_ISLNK(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)) {
stat(full_path, file); stat(full_path, file);
if (S_ISDIR(file->st_mode)) { if (S_ISDIR(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK; 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].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
dir_content[i].color_pair = COLOR_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) { } else if (file->st_mode & S_IXUSR) {
dir_content[i].file_type = FILE_TYPE_EXEC; dir_content[i].file_type = FILE_TYPE_EXEC;
dir_content[i].color_pair = COLOR_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 update_selected_file(){
char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed 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) { if (selected_file_current >= mid_file_count) {
selected_file_current = mid_file_count-1; selected_file_current = mid_file_count-1;
} }
@@ -344,7 +341,7 @@ char update_selected_file(){
return ret; return ret;
} }
void dir_set_selected_file_current(unsigned long selected_file_current){ 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; current_dir->selected_file_current = selected_file_current;
} }
} }
@@ -384,7 +381,9 @@ void dir_init(){
} }
void recursive_delete(file current_file){ 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; unsigned int file_modifiers_tmp = file_modifiers;
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES; file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
unsigned long current_file_count = get_dir_size(current_file.file_name); unsigned long current_file_count = get_dir_size(current_file.file_name);

View File

@@ -181,7 +181,7 @@ void move_down(unsigned long passes){
selected_file_current += passes; selected_file_current += passes;
update_selected_file(); 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); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
pthread_mutex_unlock(&mutex_selection); pthread_mutex_unlock(&mutex_selection);
@@ -198,7 +198,8 @@ void move_up(unsigned long passes){
} }
update_selected_file(); 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); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection); pthread_mutex_unlock(&mutex_selection);
@@ -294,7 +295,7 @@ void jump_bottom(){
pthread_mutex_lock(&mutex_selection); pthread_mutex_lock(&mutex_selection);
selected_file_current = 0 - 1; selected_file_current = 0 - 1;
update_selected_file(); 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); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection); pthread_mutex_unlock(&mutex_selection);
} }
@@ -302,7 +303,7 @@ void jump_top(){
pthread_mutex_lock(&mutex_selection); pthread_mutex_lock(&mutex_selection);
selected_file_current = 0; selected_file_current = 0;
update_selected_file(); 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); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection); pthread_mutex_unlock(&mutex_selection);
} }
@@ -341,9 +342,11 @@ void open_with(){
images_clear(); images_clear();
#endif #endif
endwin();
if (system(cmd) == -1) { if (system(cmd) == -1) {
FAIL("open_with", "creating subcommand failed unhandled"); FAIL("open_with", "creating subcommand failed unhandled");
} }
initscr();
} }
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); 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" */ /* the second loop is used to add "./", wich is not being printed" */
char *cmd = malloc(sizeof(char)); 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 */ /* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
endwin();
if (hits) { if (hits) {
for (i = 0; i < mid_file_count; i++) { for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) { if (mid_content[i].status & FILE_STATUS_SELECTED) {
@@ -708,6 +712,7 @@ void cmd_on_selected(unsigned long passes, int index){
} }
/*system(cmd);*/ /*system(cmd);*/
free(cmd); free(cmd);
initscr();
} }
free(btm_buffer); free(btm_buffer);
@@ -892,7 +897,7 @@ void search(){
curs_set(0); curs_set(0);
dir_set_selected_file_current(selected_file_current); current_dir->selected_file_current = selected_file_current;
update_selected_file(); update_selected_file();

1
main.c
View File

@@ -37,7 +37,6 @@ char *terminal_width_empty_line; /* used in user_interactions */
void render_pass(); void render_pass();
void init(); void init();
int main(){ int main(){
init(); init();

View File

@@ -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); 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[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-'; btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-';
btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-'; btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-';