added file previev

This commit is contained in:
nova
2025-06-02 22:53:08 +02:00
parent f7c1d34e05
commit 0053c7cb88
6 changed files with 73 additions and 28 deletions

View File

@ -1,5 +1,6 @@
#include <curses.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -34,7 +35,6 @@ extern unsigned long selected_file_last;
void *thread_mid(void *data){
pthread_mutex_lock(&mutex_mid);
free(mid_content);
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
@ -45,10 +45,13 @@ void *thread_mid(void *data){
} else {
mid_file_count = (unsigned long)get_dir_size(path);
mid_content = malloc(mid_file_count * sizeof(file));
memset(mid_content, ' ', mid_file_count * sizeof(file));
get_dir_content(path, &mid_file_count, mid_content);
if (status & STATUS_RELOAD_DIRECTORY) {
free(mid_content);
mid_file_count = (unsigned long)get_dir_size(path);
mid_content = malloc(mid_file_count * sizeof(file));
memset(mid_content, ' ', mid_file_count * sizeof(file));
get_dir_content(path, &mid_file_count, mid_content);
}
pthread_mutex_lock(&mutex_selection);
@ -70,7 +73,6 @@ void *thread_mid(void *data){
void *thread_lft(void *data){
pthread_mutex_lock(&mutex_lft);
free(lft_content);
char *path;
@ -84,10 +86,13 @@ void *thread_lft(void *data){
path[strrchr(path, '/')-path] = '\0';
path[0] = '/';
lft_file_count = (unsigned long)get_dir_size(path);
lft_content = malloc(lft_file_count * sizeof(file));
memset(lft_content, ' ', lft_file_count * sizeof(file));
get_dir_content(path, &lft_file_count, lft_content);
if (status & STATUS_RELOAD_DIRECTORY) {
free(lft_content);
lft_file_count = (unsigned long)get_dir_size(path);
lft_content = malloc(lft_file_count * sizeof(file));
memset(lft_content, ' ', lft_file_count * sizeof(file));
get_dir_content(path, &lft_file_count, lft_content);
}
}
free(path);
@ -97,8 +102,37 @@ void *thread_lft(void *data){
}
void *thread_rgt(void *data){
pthread_mutex_lock(&mutex_rgt);
pthread_mutex_lock(&mutex_mid);
char *path = mid_content[selected_file_current].file_name;
pthread_mutex_unlock(&mutex_mid);
if (mid_content[selected_file_current].file_type == FILE_TYPE_DIR || mid_content[selected_file_current].file_type == FILE_TYPE_SYMLINK) {
free(rgt_content);
rgt_file_count = (unsigned long)get_dir_size(path);
rgt_content = malloc(rgt_file_count * sizeof(file));
memset(rgt_content, ' ', rgt_file_count * sizeof(file));
get_dir_content(path, &rgt_file_count, rgt_content);
} else if (mid_content[selected_file_current].file_type == FILE_TYPE_REGULAR) {
FILE *fp = fopen(mid_content[selected_file_current].file_name, "r");
unsigned long file_size = ftell(fp);
rewind(fp);
free(rgt_content);
rgt_content = malloc(sizeof(file));
rgt_content[0].file_name = malloc(file_size);
fgets(rgt_content[0].file_name, file_size, fp);
rgt_content[0].file_size_bytes = file_size;
rgt_content[0].file_type = FILE_TYPE_REGULAR;
rgt_content[0].file_name_width = file_size;
rgt_content[0].color_pair = 0;
rgt_content[0].status = 0;
fclose(fp);
}
pthread_mutex_unlock(&mutex_rgt);
pthread_exit(NULL);
}
void *thread_top(void *data){