Compare commits
2 Commits
47357e039d
...
5fcf23914d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fcf23914d | ||
|
|
d3126fbc20 |
@@ -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) {
|
||||
|
||||
84
config.h
84
config.h
@@ -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*/
|
||||
@@ -30,51 +35,52 @@ static const binding key_binding[] = {
|
||||
* not possible: gg, ggg
|
||||
* trying to use ggg will always fail as it will execute gg first instead, resetting the input buffer, thus never reaching ggg */
|
||||
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
|
||||
{ "q", quit_program, NULL, "quit" },
|
||||
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
||||
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||
{ "/", not_implemented, NULL, "search" },
|
||||
{ "q", quit_program, NULL, "quit" },
|
||||
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
||||
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||
{ "/", not_implemented, NULL, "search" },
|
||||
|
||||
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
|
||||
{ "t", move_down, NULL, "move down" },
|
||||
{ "n", move_up, NULL, "move up" },
|
||||
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
|
||||
{ "t", move_down, NULL, "move down" },
|
||||
{ "n", move_up, NULL, "move up" },
|
||||
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||
|
||||
{ "\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
|
||||
* this means that it does not delete the hovered files if files are already selected */
|
||||
{ "\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 */
|
||||
{ "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" },
|
||||
{ "gg", jump_top, NULL, "jump to first file in dir" },
|
||||
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
||||
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
|
||||
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
||||
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
||||
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
|
||||
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
||||
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
||||
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
||||
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
||||
{ "gg", jump_top, NULL, "jump to first file in dir" },
|
||||
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
||||
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
|
||||
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
||||
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
||||
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
|
||||
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
||||
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
||||
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
||||
|
||||
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
||||
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
||||
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
|
||||
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
|
||||
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
|
||||
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
|
||||
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
||||
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
||||
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
|
||||
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
|
||||
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
|
||||
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
|
||||
|
||||
{ "on", order_by, sort_natural, "order natural" },
|
||||
{ "or", not_implemented, "", "order reverse" },
|
||||
{ "oe", not_implemented, "", "order extension" },
|
||||
{ "os", order_by, sort_size, "order size" },
|
||||
{ "ot", order_by, sort_type, "order type" },
|
||||
{ "oz", order_by, sort_random, "order random" },
|
||||
{ "oa", order_by, sort_alpha, "order alphabetically" },
|
||||
{ "on", order_by, sort_natural, "order natural" },
|
||||
{ "or", not_implemented, "", "order reverse" },
|
||||
{ "oe", not_implemented, "", "order extension" },
|
||||
{ "os", order_by, sort_size, "order size" },
|
||||
{ "ot", order_by, sort_type, "order type" },
|
||||
{ "oz", order_by, sort_random, "order random" },
|
||||
{ "oa", order_by, sort_alpha, "order alphabetically" },
|
||||
|
||||
{ "mk", makedir, NULL, "create directory" },
|
||||
{ "mf", makefile, NULL, "create file" },
|
||||
{ "mk", makedir, NULL, "create directory" },
|
||||
{ "mf", makefile, NULL, "create file" },
|
||||
|
||||
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
|
||||
{ "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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
47
threading.c
47
threading.c
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user