Compare commits

...

2 Commits

Author SHA1 Message Date
nova
5fcf23914d additions to the config 2025-08-05 21:15:24 +02:00
nova
d3126fbc20 fixed some stabillity issues and memory leaks 2025-08-05 20:55:36 +02:00
5 changed files with 84 additions and 65 deletions

View File

@@ -167,7 +167,7 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
if (*dir_file_count > 9) {
offset_front = (snprintf(NULL, 0, "%ld", *dir_file_count)) + 1;
}
if (selected_file_current > (terminal_height/3)*2) {
if (selected_file_current > (terminal_height/3)*2 && *dir_file_count > terminal_height - 2) {
if (selected_file_current + (terminal_height/3) >= *dir_file_count) {
offset_vertical = *dir_file_count - terminal_height+2;
} else {
@@ -247,9 +247,9 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
}
mvwaddstr(win, i-offset_vertical, 0, bg);
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
if(print_info) {
mvwprintw(win, i-offset_vertical, 0, "%ld", i);
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
free(file_name);
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {

View File

@@ -15,13 +15,18 @@ static const mimetype mimetype_default_cmd[] = {
{ "gif", "mpv --loop-file=\"inf\"" },
{ "image", "feh" },
{ "video", "mpv" },
{ "audio", "mpv" }
{ "audio", "mpv" },
{ "pdf", "zathura" },
};
static const extension file_extension_default_cmd[] = {
/* extension shell command
* similar to mimetype_default_cmd, however it searches for exact string matches
* and is checked before mimetype_default_cmd */
{ ".exe", "wine"},
{ ".cbz", "mcomix"},
{ ".cbr", "mcomix"},
{ ".json", "$EDITOR"},
{ ".csv", "$EDITOR"},
};
static const binding key_binding[] = {
/*key action blackmagic comment*/
@@ -42,7 +47,7 @@ static const binding key_binding[] = {
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
{ "d", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
* this means that it does not delete the hovered files if files are already selected */
{ "G", jump_bottom, NULL, "jump to last file in dir" },
@@ -75,6 +80,7 @@ static const binding key_binding[] = {
{ "mf", makefile, NULL, "create file" },
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
{ "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace/delete key */
};
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);

View File

@@ -20,7 +20,7 @@ char* get_mimetype(char *path){
cmd[cmd_len + path_len + 1] = '\0';
FILE *cmd_open = popen(cmd, "r");
char *line;
char *line = NULL;
size_t size = 0;
if (getline(&line, &size, cmd_open) != -1){
pclose(cmd_open);
@@ -30,18 +30,18 @@ char* get_mimetype(char *path){
return "unknown";
}
}
char* preview_file(file *file_current){
char* preview_file(char *file_name, unsigned long file_size){
/* this calls "file" on path */
char *file_buffer;
char *mime = get_mimetype(file_current->file_name);
char *mime = get_mimetype(file_name);
if (strstr(mime, "text")) {
file_buffer = text(file_current->file_name, &file_current->file_size);
file_buffer = text(file_name, &file_size);
} else {
file_buffer = generic(file_current->file_name);
file_buffer = generic(file_name);
}
free(mime);
return file_buffer;
@@ -63,7 +63,7 @@ char* generic(char *path){
cmd = concat(cmd, "\"");
FILE *cmd_open = popen(cmd, "r");
char *line;
char *line = NULL;
size_t size = 0;
if (getline(&line, &size, cmd_open) != -1) {
pclose(cmd_open);

View File

@@ -1,5 +1,5 @@
#include "file_previews.c"
#include "defines.h"
char* preview_file(file *file_current);
char* preview_file(char *file_name, unsigned long file_size);
char* get_mimetype(char *path);

View File

@@ -30,8 +30,8 @@ char *top_buffer; /* current path */
volatile file *file_current;
unsigned long rgt_file_count;
unsigned long mid_file_count;
unsigned long rgt_file_count = 0;
unsigned long mid_file_count = 0;
unsigned long lft_file_count;
unsigned long top_width;
@@ -56,6 +56,10 @@ void *thread_mid(void *data){
if (status & STATUS_RELOAD_DIRECTORY) {
unsigned long i = 0;
for (i = 0; i < mid_file_count; i++) {
free(mid_content[i].file_name);
}
free(mid_content);
mid_file_count = get_dir_size(path);
if (mid_file_count > 0) {
@@ -104,8 +108,9 @@ void *thread_mid(void *data){
selected_file_last = selected_file_current;
free(file_current->file_name);
file_current->file_name = malloc(strlen(mid_content[selected_file_current].file_name));
file_current->file_name = malloc(strlen(mid_content[selected_file_current].file_name)+1);
strcpy(file_current->file_name, mid_content[selected_file_current].file_name);
file_current->file_name[strlen(mid_content[selected_file_current].file_name)] = '\0';
file_current->file_size = mid_content[selected_file_current].file_size;
file_current->file_type = mid_content[selected_file_current].file_type;
file_current->color_pair = mid_content[selected_file_current].color_pair;
@@ -167,42 +172,50 @@ void *thread_rgt(void *data){
pthread_mutex_lock(&mutex_selection);
free(rgt_content);
rgt_content = malloc(sizeof(file));
rgt_content->file_name = malloc(strlen(file_current->file_name));
strcpy(rgt_content->file_name, file_current->file_name);
rgt_content->file_size = file_current->file_size;
rgt_content->file_type = file_current->file_type;
rgt_content->status = file_current->status;
char *path = malloc(strlen(file_current->file_name) + 1);
strcpy(path, file_current->file_name);
unsigned char file_current_type = file_current->file_type;
unsigned long file_current_size = file_current->file_size;
char file_current_status = file_current->status;
pthread_mutex_unlock(&mutex_selection);
if (rgt_content->file_type == FILE_TYPE_DIR || rgt_content->file_type == FILE_TYPE_SYMLINK) {
char *path = malloc(strlen(rgt_content[0].file_name) + 1);
strcpy(path, rgt_content[0].file_name);
if (file_current_type == FILE_TYPE_DIR || file_current_type == FILE_TYPE_SYMLINK) {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
free(rgt_content[i].file_name);
}
free(rgt_content);
rgt_file_count = get_dir_size(path);
rgt_content = malloc(rgt_file_count * sizeof(file));
memset(rgt_content, ' ', rgt_file_count * sizeof(file));
memset(rgt_content, '\0', rgt_file_count * sizeof(file));
get_dir_content(path, &rgt_file_count, rgt_content);
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
free(path);
free(rgt_buffer);
rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0';
} else {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
free(rgt_content[i].file_name);
}
free(rgt_content);
rgt_file_count = 0;
rgt_content = malloc(sizeof(file));
free(rgt_buffer);
if (rgt_content->status & FILE_STATUS_DIR_EMPTY) {
if (file_current_status & FILE_STATUS_DIR_EMPTY) {
rgt_buffer = "empty dir";
} else {
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
rgt_content->status = FILE_STATUS_HOVER;
rgt_buffer = preview_file(rgt_content);
rgt_buffer = preview_file(path, file_current_size);
}
}
free(path);
pthread_mutex_unlock(&mutex_rgt);
pthread_exit(0);