1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-21 10:20:15 -04:00

search file function now does file previews

This commit is contained in:
nova
2025-08-24 20:09:32 +02:00
parent 4a9c38d034
commit a05c3ecd96
3 changed files with 13 additions and 5 deletions

9
dir.c
View File

@@ -313,18 +313,23 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
free(bg); free(bg);
} }
void update_selected_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 */ if (mid_content->file_name[0] == '\0') { /* only happens if the current path is either empty or inaccessible */
return; 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;
} }
if (selected_file_current != selected_file_last) { if (selected_file_current != selected_file_last) {
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER; mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
ret = 1;
} else {
ret = 0;
} }
mid_content[selected_file_current].status |= FILE_STATUS_HOVER; mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
selected_file_last = selected_file_current; selected_file_last = selected_file_current;
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[0] != '\0') {

2
dir.h
View File

@@ -6,7 +6,7 @@
unsigned long get_dir_size(char *path); unsigned long get_dir_size(char *path);
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content); void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content); void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
void update_selected_file(); char update_selected_file();
void dir_set_selected_file_current(unsigned long selected_file_current); void dir_set_selected_file_current(unsigned long selected_file_current);
unsigned long dir_get_selected_file_current(); unsigned long dir_get_selected_file_current();
void dir_init(); void dir_init();

View File

@@ -17,6 +17,7 @@ extern unsigned int file_modifiers;
extern pthread_mutex_t mutex_selection; extern pthread_mutex_t mutex_selection;
extern pthread_mutex_t mutex_rgt; extern pthread_mutex_t mutex_rgt;
extern pthread_mutex_t mutex_mid; extern pthread_mutex_t mutex_mid;
extern pthread_cond_t cond_rgt;
extern file *mid_content; extern file *mid_content;
extern file *lft_content; extern file *lft_content;
extern file *rgt_content; extern file *rgt_content;
@@ -807,11 +808,13 @@ void search(){
for (i = 0; i < mid_file_count; i++) { for (i = 0; i < mid_file_count; i++) {
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) { if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
selected_file_current = i; selected_file_current = i;
update_selected_file(); if (update_selected_file()) {
pthread_cond_signal(&cond_rgt);
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
render_pass();
break; break;
} }
render_pass();
} }
} }
} }