Compare commits
32 Commits
689565f732
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a31f452ea | ||
|
|
daf43daa00 | ||
|
|
cf03a230b6 | ||
|
|
87bfdd1b86 | ||
|
|
20fee198ae | ||
|
|
632904fd89 | ||
|
|
dd5307b411 | ||
|
|
41933eb6d0 | ||
|
|
0a45d1e3e8 | ||
|
|
d33ac88de2 | ||
|
|
e42d55e66a | ||
|
|
f6380ddeda | ||
|
|
905f6e8588 | ||
|
|
095cf7b357 | ||
|
|
9f7ed73885 | ||
|
|
41af25e0b1 | ||
|
|
f807fe56b5 | ||
|
|
adb10b6d5d | ||
|
|
c692a1a992 | ||
|
|
8c80a6e3da | ||
|
|
1aa66c82fb | ||
|
|
f5d0c8bc85 | ||
|
|
9e8bd3c022 | ||
|
|
f40cc91cce | ||
|
|
a5483335c5 | ||
|
|
a7d4a6322c | ||
|
|
749dba1ce8 | ||
|
|
ac0b644bcb | ||
|
|
b4acda1aa6 | ||
|
|
b7124cbb1d | ||
|
|
adac32fcc1 | ||
|
|
dcb47d420b |
47
backend.c
47
backend.c
@@ -100,13 +100,13 @@ char* parse_cmd(const char *cmd, file *f){
|
|||||||
pos = out;
|
pos = out;
|
||||||
if (offset) {
|
if (offset) {
|
||||||
memcpy(pos, cmd, offset - cmd);
|
memcpy(pos, cmd, offset - cmd);
|
||||||
pos += offset - cmd + 1;
|
pos += offset - cmd;
|
||||||
} else {
|
} else {
|
||||||
memcpy(pos, cmd, strlen(cmd));
|
memcpy(pos, cmd, strlen(cmd));
|
||||||
pos += strlen(cmd) + 1;
|
pos += strlen(cmd) + 1;
|
||||||
}
|
|
||||||
pos[-1] = ' ';
|
pos[-1] = ' ';
|
||||||
pos[0] = '\'';
|
}
|
||||||
|
*pos = '\'';
|
||||||
pos++;
|
pos++;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
@@ -124,12 +124,47 @@ char* parse_cmd(const char *cmd, file *f){
|
|||||||
|
|
||||||
if (offset) {
|
if (offset) {
|
||||||
pos[1]= ' ';
|
pos[1]= ' ';
|
||||||
memcpy(pos + 1, offset+1, strlen(offset+1));
|
memcpy(pos + 1, offset+1, strlen(offset)+1);
|
||||||
pos[strlen(offset+1)] = '\0';
|
pos[strlen(offset)+1] = '\0';
|
||||||
} else {
|
} else {
|
||||||
pos[1] = '\0';
|
pos[1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
}
|
||||||
|
char* parse_path(char *path){
|
||||||
|
int count = 0;
|
||||||
|
char *out;
|
||||||
|
char *pos;
|
||||||
|
unsigned long i = 0;
|
||||||
|
while(path[i]) {
|
||||||
|
if (path[i] == '\'') {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
out = malloc((strlen(path)+(count*3)) + 4);
|
||||||
|
|
||||||
|
pos = out;
|
||||||
|
pos++;
|
||||||
|
|
||||||
|
out[0] = '\'';
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while(path[i]) {
|
||||||
|
if (path[i] == '\'') {
|
||||||
|
*pos++ = '\'';
|
||||||
|
*pos++ = '\\';
|
||||||
|
*pos++ = '\'';
|
||||||
|
}
|
||||||
|
*pos = path[i];
|
||||||
|
pos++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
pos[0] = '\'';
|
||||||
|
pos[1]= ' ';
|
||||||
|
pos[2] = '\0';
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|||||||
3
colors.c
3
colors.c
@@ -102,8 +102,7 @@ void colors_init() {
|
|||||||
while (getline(&line, &size, dircolors) != -1) {
|
while (getline(&line, &size, dircolors) != -1) {
|
||||||
fg = 7;
|
fg = 7;
|
||||||
bg = 0;
|
bg = 0;
|
||||||
if (line[0] == '.') {
|
if (line[0] == '.' && (extension = strtok(line, " ")) != NULL) {
|
||||||
extension = strtok(line, " ");
|
|
||||||
colors[i].file_extension = malloc(strlen(extension)+1);
|
colors[i].file_extension = malloc(strlen(extension)+1);
|
||||||
memcpy(colors[i].file_extension, extension, strlen(extension)+1);
|
memcpy(colors[i].file_extension, extension, strlen(extension)+1);
|
||||||
|
|
||||||
|
|||||||
46
config.h
46
config.h
@@ -4,6 +4,7 @@
|
|||||||
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
|
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
|
||||||
#define SETTINGS_COMMAND_REPLACE_STR "^" /* if a command in any cmd inside this fle contains this string, it will be replaced with the hovered/selected file name
|
#define SETTINGS_COMMAND_REPLACE_STR "^" /* if a command in any cmd inside this fle contains this string, it will be replaced with the hovered/selected file name
|
||||||
* as of right now, this character cannot be escaped; i.e ``command\^ --arg`` will parse into ``command\path_of_hovered_file --arg``*/
|
* as of right now, this character cannot be escaped; i.e ``command\^ --arg`` will parse into ``command\path_of_hovered_file --arg``*/
|
||||||
|
#define SETTINGS_COMMAND_FORK '@' /* commands starting with this character will be forked into a new non blokcing detached process */
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
#ifndef CONFIG_GUARD
|
#ifndef CONFIG_GUARD
|
||||||
@@ -13,6 +14,11 @@
|
|||||||
#include "interactions.h"
|
#include "interactions.h"
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
static const char clipboard_cmd[] = "echo ^ | xsel -ib --trim"; /*used in yank_text*/
|
||||||
|
static const char rename_cmd[] = "mv"; /* as used in rename_hovered, makedir and makefile */
|
||||||
|
static const char makefile_cmd[] = "touch"; /*as of now both only do ``rename_cmd new_name``*/
|
||||||
|
static const char makedir_cmd[] = "mkdir";
|
||||||
|
|
||||||
static const mimetype mimetype_default_cmd[] = {
|
static const mimetype mimetype_default_cmd[] = {
|
||||||
/* mimetype shell command
|
/* mimetype shell command
|
||||||
* ^ substring of "file --mime-type -b ./hovered"
|
* ^ substring of "file --mime-type -b ./hovered"
|
||||||
@@ -22,20 +28,20 @@ static const mimetype mimetype_default_cmd[] = {
|
|||||||
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
|
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
|
||||||
* we need to define "gif" before "image" */
|
* we need to define "gif" before "image" */
|
||||||
{ "text", "$EDITOR" },
|
{ "text", "$EDITOR" },
|
||||||
{ "avif", "nohup mpv ^ >/dev/null 2>&1 &" },
|
{ "avif", "@ mpv" },
|
||||||
{ "gif", "nohup mpv --loop-file=\"inf\" ^ >/dev/null 2>&1 &" },
|
{ "gif", "@ mpv --loop-file=\"inf\"" },
|
||||||
{ "image", "feh ^ >/dev/null 2>&1 &" },
|
{ "image", "@ feh" },
|
||||||
{ "video", "nohup mpv ^ >/dev/null 2>&1 &" },
|
{ "video", "@ mpv" },
|
||||||
{ "audio", "mpv" },
|
{ "audio", "mpv" },
|
||||||
{ "pdf", "zathura" },
|
{ "pdf", "@ zathura" },
|
||||||
};
|
};
|
||||||
static const extension file_extension_default_cmd[] = {
|
static const extension file_extension_default_cmd[] = {
|
||||||
/* extension shell command
|
/* extension shell command
|
||||||
* similar to mimetype_default_cmd, however it searches for exact string matches
|
* similar to mimetype_default_cmd, however it searches for exact string matches
|
||||||
* and is checked before mimetype_default_cmd */
|
* and is checked before mimetype_default_cmd */
|
||||||
{ ".exe", "wine"},
|
{ ".exe", "wine"},
|
||||||
{ ".cbz", "mcomix ^ &"},
|
{ ".cbz", "@ mcomix"},
|
||||||
{ ".cbr", "mcomix ^ &"},
|
{ ".cbr", "@ mcomix"},
|
||||||
{ ".json", "$EDITOR"},
|
{ ".json", "$EDITOR"},
|
||||||
{ ".csv", "$EDITOR"},
|
{ ".csv", "$EDITOR"},
|
||||||
{ ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */
|
{ ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */
|
||||||
@@ -62,12 +68,12 @@ static const binding key_binding[] = {
|
|||||||
{ "n", move_up, NULL, "move up" },
|
{ "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 */
|
{ "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 */
|
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* execute shell cmd on file, accounts for SETTINGS_COMMAND_FORK */
|
||||||
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||||
{ "dD", 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 */
|
* this means that it does not delete the hovered files if files are already selected */
|
||||||
{ "yn", yank_text, "name", "yank filename of hovered file" },
|
{ "yn", yank_file_name, NULL, "yank filename of hovered file" },
|
||||||
{ "yp", yank_text, "path", "yank path of hovered file" },
|
{ "yp", yank_file_path, NULL, "yank path of hovered file" },
|
||||||
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
||||||
{ "dd", yank_file, "cut", "cut file/directory" },
|
{ "dd", yank_file, "cut", "cut file/directory" },
|
||||||
{ "pp", paste, NULL, "paste" },
|
{ "pp", paste, NULL, "paste" },
|
||||||
@@ -113,13 +119,12 @@ static const binding key_binding[] = {
|
|||||||
|
|
||||||
static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this defines the maximum size unit, deleting everything except B results in all sizes being displayed in byte */
|
static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this defines the maximum size unit, deleting everything except B results in all sizes being displayed in byte */
|
||||||
|
|
||||||
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
|
|
||||||
static const char ui_btm_text_storage_left[] = "total free";
|
static const char ui_btm_text_storage_left[] = "total free";
|
||||||
static const char ui_btm_current_dir_size[] = "sum of dir,";
|
static const char ui_btm_current_dir_size[] = "sum of dir,";
|
||||||
static const char ui_open_with_text_0[] = "open"; /*ui_open_with_text_0 \"selected_file\" ui_open_with_text_1*/
|
static const char ui_open_with_text[] = "open "SETTINGS_COMMAND_REPLACE_STR" with:";
|
||||||
static const char ui_open_with_text_1[] = "with:";
|
static const char ui_rename_text[] = "rename "SETTINGS_COMMAND_REPLACE_STR" to:";
|
||||||
static const char ui_rename_text_0[] = "rename"; /*ui_rename_text_0 \"selected_file\" ui_rename_text_1*/
|
static const char ui_makefile_text[] = "makedir:";
|
||||||
static const char ui_rename_text_1[] = "to:";
|
static const char ui_makedir_text[] = "makefile:";
|
||||||
static const char ui_delete_text[] = "delete:";
|
static const char ui_delete_text[] = "delete:";
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
@@ -129,6 +134,9 @@ static const unsigned long file_extension_default_count = sizeof(file_extension_
|
|||||||
static const char size_unit_count = (sizeof(size_unit) / sizeof(size_unit[0])) - 1;
|
static const char size_unit_count = (sizeof(size_unit) / sizeof(size_unit[0])) - 1;
|
||||||
#else
|
#else
|
||||||
static const char clipboard_cmd[];
|
static const char clipboard_cmd[];
|
||||||
|
static const char rename_cmd[];
|
||||||
|
static const char makefile_cmd[];
|
||||||
|
static const char makedir_cmd[];
|
||||||
static const mimetype mimetype_default_cmd[];
|
static const mimetype mimetype_default_cmd[];
|
||||||
static const extension file_extension_default_cmd[];
|
static const extension file_extension_default_cmd[];
|
||||||
static const binding key_binding[];
|
static const binding key_binding[];
|
||||||
@@ -137,10 +145,10 @@ static const unsigned long mimetype_default_count;
|
|||||||
static const unsigned long file_extension_default_count;
|
static const unsigned long file_extension_default_count;
|
||||||
static const char size_unit[];
|
static const char size_unit[];
|
||||||
static const char size_unit_count;
|
static const char size_unit_count;
|
||||||
static const char ui_open_with_text_0[];
|
static const char ui_open_with_text[];
|
||||||
static const char ui_open_with_text_1[];
|
static const char ui_makedir_text[];
|
||||||
static const char ui_rename_text_0[];
|
static const char ui_makefile_text[];
|
||||||
static const char ui_rename_text_1[];
|
static const char ui_rename_text[];
|
||||||
static const char ui_delete_text[];
|
static const char ui_delete_text[];
|
||||||
#endif
|
#endif
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ typedef struct Yank {
|
|||||||
} yank;
|
} yank;
|
||||||
typedef struct Linked_dir {
|
typedef struct Linked_dir {
|
||||||
char *path;
|
char *path;
|
||||||
unsigned long selected_file_current;
|
unsigned long index;
|
||||||
struct Linked_dir *next;
|
struct Linked_dir *next;
|
||||||
} linked_dir;
|
} linked_dir;
|
||||||
|
|
||||||
|
|||||||
140
dir.c
140
dir.c
@@ -17,25 +17,25 @@ extern unsigned int settings;
|
|||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
extern unsigned int terminal_height;
|
extern unsigned int terminal_height;
|
||||||
extern volatile unsigned long selected_file_current;
|
extern char *global_path;
|
||||||
extern volatile unsigned long selected_file_last;
|
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
int (*order_func)() = sort_natural;
|
int (*order_func)() = sort_natural;
|
||||||
linked_dir *visited_dirs;
|
linked_dir *list_beginning;
|
||||||
linked_dir *current_dir;
|
linked_dir *current_linked_dir;
|
||||||
|
|
||||||
|
|
||||||
unsigned long get_dir_size(char *path){
|
unsigned long get_dir_size(char *path){
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
unsigned long entry_count = 0;
|
unsigned long entry_count = 0;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
if (dir && file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
if (dir) {
|
||||||
|
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||||
while ((entry=readdir(dir))) {
|
while ((entry=readdir(dir))) {
|
||||||
entry_count++;
|
entry_count++;
|
||||||
}
|
}
|
||||||
/* removes files "." and ".." */
|
/* removes files "." and ".." */
|
||||||
entry_count -= 2;
|
entry_count -= 2;
|
||||||
} else if (dir) {
|
} else {
|
||||||
while ((entry=readdir(dir))) {
|
while ((entry=readdir(dir))) {
|
||||||
if (entry->d_name[0] != '.') {
|
if (entry->d_name[0] != '.') {
|
||||||
entry_count++;
|
entry_count++;
|
||||||
@@ -43,6 +43,7 @@ unsigned long get_dir_size(char *path){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
}
|
||||||
return entry_count;
|
return entry_count;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -54,6 +55,8 @@ void get_dir_content(char *path, dir *dir){
|
|||||||
} else {
|
} else {
|
||||||
scandir(path, &entry, skip_hidden_files, NULL);
|
scandir(path, &entry, skip_hidden_files, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *full_path = NULL;
|
char *full_path = NULL;
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < dir->file_count; i++ ) {
|
for (i = 0; i < dir->file_count; i++ ) {
|
||||||
@@ -201,7 +204,7 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
|||||||
} while (file_size > 1 && size_index < size_unit_count);
|
} while (file_size > 1 && size_index < size_unit_count);
|
||||||
size_char = size_unit[(unsigned)size_index];
|
size_char = size_unit[(unsigned)size_index];
|
||||||
|
|
||||||
if (dir->file_list[i].file_type &= FILE_TYPE_DIR) {
|
if (dir->file_list[i].file_type & FILE_TYPE_DIR) {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%ld", dir->file_list[i].file_size) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%ld", dir->file_list[i].file_size) + 1);
|
||||||
} else if (size_char =='B') {
|
} else if (size_char =='B') {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
||||||
@@ -267,7 +270,7 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (dir->file_list[i].file_type &= FILE_TYPE_DIR) {
|
if (dir->file_list[i].file_type & FILE_TYPE_DIR) {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir->file_list[i].file_size);
|
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir->file_list[i].file_size);
|
||||||
}else if (size_char =='B') {
|
}else if (size_char =='B') {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
||||||
@@ -294,66 +297,81 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void dir_changed(){
|
||||||
|
|
||||||
char update_selected_file(){
|
|
||||||
char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed file */
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (selected_file_current >= mid_file_count) {
|
|
||||||
selected_file_current = mid_file_count-1;
|
|
||||||
}
|
|
||||||
if (selected_file_current != selected_file_last && selected_file_last <= mid_file_count) {
|
|
||||||
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
|
||||||
ret = 1;
|
|
||||||
} else {
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
mid_dir.current_dir.status |= FILE_STATUS_HOVER;
|
|
||||||
selected_file_last = selected_file_current;
|
|
||||||
*/
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
void dir_set_selected_file_current(unsigned long selected_file_current){
|
|
||||||
/*
|
|
||||||
if (mid_content->file_name) {
|
|
||||||
current_dir->selected_file_current = selected_file_current;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long dir_get_selected_file_current(){
|
|
||||||
|
|
||||||
/*
|
|
||||||
current_dir = visited_dirs;
|
|
||||||
if (mid_content->file_name[0] == '\0') {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
char hit = 0;
|
|
||||||
char *path = getcwd(NULL, 0);
|
char *path = getcwd(NULL, 0);
|
||||||
while(current_dir->next != NULL) {
|
current_linked_dir = list_beginning;
|
||||||
if (strcmp(path, current_dir->path) == 0) {
|
while (current_linked_dir->next != NULL) {
|
||||||
hit = 1;
|
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
current_dir = current_dir->next;
|
|
||||||
}
|
|
||||||
if (hit == 0) {
|
|
||||||
current_dir->next = malloc(sizeof(linked_dir));
|
|
||||||
current_dir->next->next = NULL;
|
|
||||||
current_dir->next->path = path;
|
|
||||||
return 0;
|
|
||||||
} else {
|
} else {
|
||||||
free(path);
|
current_linked_dir = current_linked_dir->next;
|
||||||
return current_dir->selected_file_current;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||||
|
} else {
|
||||||
|
/**/
|
||||||
|
|
||||||
|
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||||
|
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
||||||
|
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
||||||
|
current_linked_dir->next->next = NULL;
|
||||||
|
current_linked_dir->next->index = 0;
|
||||||
|
|
||||||
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void change_dir(char *new_path){
|
||||||
|
|
||||||
|
char *old_path = getcwd(NULL, 0);
|
||||||
|
current_linked_dir = list_beginning;
|
||||||
|
while (current_linked_dir->next != NULL) {
|
||||||
|
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||||
|
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
chdir(new_path);
|
||||||
|
char *new_path_real = getcwd(NULL, 0);
|
||||||
|
|
||||||
|
current_linked_dir = list_beginning;
|
||||||
|
while (current_linked_dir->next != NULL) {
|
||||||
|
if(strcmp(current_linked_dir->path, new_path_real) == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(current_linked_dir->path, new_path_real) != 0) {
|
||||||
|
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
|
current_linked_dir->path = malloc(strlen(new_path_real)+1);
|
||||||
|
memcpy(current_linked_dir->path, new_path_real, strlen(new_path_real)+1);
|
||||||
|
current_linked_dir->next = NULL;
|
||||||
|
current_linked_dir->index = 0;
|
||||||
|
/*TODO(2026-05-25T22:49:30)
|
||||||
|
*handle if new_path == "..", should this case be true, focus the index on which the old_path falls on*/
|
||||||
|
}
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||||
|
|
||||||
|
free(old_path);
|
||||||
|
free(new_path_real);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void dir_init(){
|
void dir_init(){
|
||||||
visited_dirs = malloc(sizeof(linked_dir));
|
list_beginning = malloc(sizeof(linked_dir));
|
||||||
visited_dirs->path = getcwd(NULL, 0);
|
list_beginning->path = getcwd(NULL, 0);
|
||||||
visited_dirs->selected_file_current = 0;
|
list_beginning->index = 0;
|
||||||
visited_dirs->next = NULL;
|
list_beginning->next = NULL;
|
||||||
current_dir = visited_dirs;
|
current_linked_dir = list_beginning;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
312
interactions.c
312
interactions.c
@@ -12,28 +12,18 @@
|
|||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
|
|
||||||
|
|
||||||
extern volatile unsigned long selected_file_current;
|
|
||||||
extern volatile unsigned long selected_file_last;
|
|
||||||
|
|
||||||
extern unsigned int file_modifiers;
|
|
||||||
extern pthread_mutex_t mutex_selection;
|
|
||||||
extern pthread_mutex_t mutex_rgt;
|
|
||||||
extern pthread_mutex_t mutex_mid;
|
extern pthread_mutex_t mutex_mid;
|
||||||
extern pthread_mutex_t mutex_btm;
|
extern pthread_mutex_t mutex_render;
|
||||||
extern pthread_cond_t cond_rgt;
|
extern WINDOW *win_b;
|
||||||
extern pthread_cond_t cond_mid;
|
extern WINDOW *win_m;
|
||||||
extern dir mid_dir;
|
extern dir mid_dir;
|
||||||
|
|
||||||
extern unsigned int terminal_height;
|
extern unsigned int terminal_height;
|
||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
|
|
||||||
extern WINDOW *win_b;
|
|
||||||
|
|
||||||
extern char *rgt_buffer;
|
|
||||||
extern char *btm_buffer;
|
|
||||||
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
extern char *start_path;
|
extern char *start_path;
|
||||||
|
extern char *global_path;
|
||||||
extern char *input;
|
extern char *input;
|
||||||
|
|
||||||
extern time_t seed;
|
extern time_t seed;
|
||||||
@@ -43,9 +33,6 @@ unsigned int input_pass;
|
|||||||
unsigned long parsed_input_number;
|
unsigned long parsed_input_number;
|
||||||
yank yank_files = { 0 };
|
yank yank_files = { 0 };
|
||||||
|
|
||||||
extern void render_pass();
|
|
||||||
extern int (*order_func)();
|
|
||||||
|
|
||||||
|
|
||||||
#define TODO noraw(); \
|
#define TODO noraw(); \
|
||||||
endwin();\
|
endwin();\
|
||||||
@@ -146,7 +133,7 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
|||||||
} else if (ch == 127) { /* backspace */
|
} else if (ch == 127) { /* backspace */
|
||||||
if (pass > 0) {
|
if (pass > 0) {
|
||||||
pass--;
|
pass--;
|
||||||
mvwdelch(win, y, pass);
|
mvwdelch(win, y, x + pass);
|
||||||
}
|
}
|
||||||
} else if (ch == 27) { /* esc key */
|
} else if (ch == 27) { /* esc key */
|
||||||
err = 1;
|
err = 1;
|
||||||
@@ -170,29 +157,34 @@ void update(){
|
|||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
|
||||||
}
|
}
|
||||||
void select_all(){
|
void select_all(){
|
||||||
TODO;
|
unsigned long i;
|
||||||
|
for (i = 0; i < mid_dir.file_count; i++) {
|
||||||
|
mid_dir.file_list[i].status ^= FILE_STATUS_SELECTED;
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void move_down(unsigned long passes){
|
void move_down(unsigned long passes){
|
||||||
|
|
||||||
/*bounds checking happens within thread_mid*/
|
|
||||||
mid_dir.current_file += passes;
|
mid_dir.current_file += passes;
|
||||||
|
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
|
||||||
|
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||||
|
}
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void move_up(unsigned long passes){
|
void move_up(unsigned long passes){
|
||||||
|
|
||||||
/*bounds checking happens within thread_mid*/
|
|
||||||
mid_dir.current_file -= passes;
|
mid_dir.current_file -= passes;
|
||||||
|
if (mid_dir.current_file < mid_dir.file_list) {
|
||||||
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
|
}
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void move_left(unsigned long passes){
|
void move_left(unsigned long passes){
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
for (i = 0; i < passes; i++) {
|
for (i = 0; i < passes; i++) {
|
||||||
if (chdir("..") != 0) {
|
change_dir("..");
|
||||||
/* TODO(2025-07-09T00:30:05) fix */
|
|
||||||
FAIL("move_left", "unhandled error of chdir");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
|
|
||||||
@@ -200,15 +192,15 @@ void move_left(unsigned long passes){
|
|||||||
void move_right(){
|
void move_right(){
|
||||||
|
|
||||||
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||||
if (chdir(mid_dir.current_file->file_name) != 0) {
|
change_dir(mid_dir.current_file->file_name);
|
||||||
/* TODO(2026-05-05T20:12:14) fix */
|
|
||||||
FAIL("move_right", "unhandled error of chdir");
|
|
||||||
}
|
|
||||||
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
||||||
|
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
|
||||||
|
if (system(cmd)) {
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
char *mime = get_mimetype(mid_dir.current_file);
|
char *mime = get_mimetype(mid_dir.current_file);
|
||||||
char *extension = mid_dir.current_file->file_name;
|
char *extension = mid_dir.current_file->file_name;
|
||||||
char *cmd;
|
char *cmd = NULL;
|
||||||
while (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
while (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
||||||
if (*extension == '.') {
|
if (*extension == '.') {
|
||||||
break;
|
break;
|
||||||
@@ -216,13 +208,23 @@ void move_right(){
|
|||||||
extension++;
|
extension++;
|
||||||
}
|
}
|
||||||
|
|
||||||
long i;
|
unsigned long i;
|
||||||
if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
||||||
for (i = 0; i < file_extension_default_count; i++) {
|
for (i = 0; i < file_extension_default_count; i++) {
|
||||||
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
|
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
|
||||||
|
if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||||
|
cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file);
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid == 0 && setsid()) {
|
||||||
|
system(cmd);
|
||||||
|
status = STATUS_QUIT_PROGRAM;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
|
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
|
||||||
if (system(cmd)) {
|
if (system(cmd)) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
status |= STATUS_MOVE_RIGHT_MATCH;
|
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||||
update();
|
update();
|
||||||
break;
|
break;
|
||||||
@@ -231,10 +233,21 @@ void move_right(){
|
|||||||
}
|
}
|
||||||
if (!(status & STATUS_MOVE_RIGHT_MATCH)) {
|
if (!(status & STATUS_MOVE_RIGHT_MATCH)) {
|
||||||
for (i = 0; i < mimetype_default_count; i++) {
|
for (i = 0; i < mimetype_default_count; i++) {
|
||||||
if (strstr(mimetype_default_cmd[i].mimetype, mime) == 0) {
|
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||||
|
if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||||
|
cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file);
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid == 0 && setsid()) {
|
||||||
|
system(cmd);
|
||||||
|
status = STATUS_QUIT_PROGRAM;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
|
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
|
||||||
if (system(cmd)) {
|
if (system(cmd)) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||||
update();
|
update();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -251,8 +264,13 @@ void toggle_hidden_files(){
|
|||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void toggle_selection(){
|
void toggle_selection(unsigned long passes){
|
||||||
TODO;
|
unsigned long i;
|
||||||
|
for (i = 0; i < passes; i++) {
|
||||||
|
mid_dir.current_file->status ^= FILE_STATUS_SELECTED;
|
||||||
|
move_down(1);
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void jump_bottom(){
|
void jump_bottom(){
|
||||||
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||||
@@ -263,22 +281,93 @@ void jump_top(){
|
|||||||
status |= (STATUS_RUN_BACKEND);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void open_with(){
|
void open_with(){
|
||||||
TODO;
|
wclear(win_b);
|
||||||
|
char *cmd;
|
||||||
|
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||||
|
char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file);
|
||||||
|
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||||
|
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) {
|
||||||
|
if (str[0] == SETTINGS_COMMAND_FORK) {
|
||||||
|
cmd = parse_cmd(str+1, mid_dir.current_file);
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid == 0 && setsid()) {
|
||||||
|
system(cmd);
|
||||||
|
status = STATUS_QUIT_PROGRAM;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd = parse_cmd(str, mid_dir.current_file);
|
||||||
|
if (system(cmd)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(cmd);
|
||||||
|
}
|
||||||
|
free(parsed_ui_text);
|
||||||
|
free(str);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||||
|
|
||||||
}
|
}
|
||||||
void rename_hovered(){
|
void rename_hovered(){
|
||||||
TODO;
|
wclear(win_b);
|
||||||
|
file tmp;
|
||||||
|
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
|
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
|
||||||
|
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||||
|
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, tmp.file_name) == 0) {
|
||||||
|
char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file);
|
||||||
|
char *cmd1 = parse_cmd(cmd0, &tmp);
|
||||||
|
system(cmd1);
|
||||||
|
free(cmd0);
|
||||||
|
free(cmd1);
|
||||||
|
}
|
||||||
|
free(parsed_ui_text);
|
||||||
|
free(tmp.file_name);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
|
|
||||||
}
|
}
|
||||||
void delete(){
|
void delete(){
|
||||||
TODO;
|
TODO;
|
||||||
}
|
}
|
||||||
void makedir(){
|
void makedir(){
|
||||||
TODO;
|
wclear(win_b);
|
||||||
|
file tmp;
|
||||||
|
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
|
mvwprintw(win_b, 0, 0, ui_makedir_text);
|
||||||
|
if (read_string(win_b, 0, strlen(ui_makedir_text)+1, tmp.file_name) == 0) {
|
||||||
|
char *cmd = parse_cmd(makedir_cmd, &tmp);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
}
|
||||||
|
free(tmp.file_name);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void makefile(){
|
void makefile(){
|
||||||
TODO;
|
wclear(win_b);
|
||||||
|
file tmp;
|
||||||
|
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
|
mvwprintw(win_b, 0, 0, ui_makefile_text);
|
||||||
|
if (read_string(win_b, 0, strlen(ui_makefile_text)+1, tmp.file_name) == 0) {
|
||||||
|
char *cmd = parse_cmd(makefile_cmd, &tmp);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
}
|
||||||
|
free(tmp.file_name);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void enter_shell(unsigned long passes, int index){
|
void enter_shell(unsigned long passes, int index){
|
||||||
TODO;
|
(void)passes; /*remove compiler warning*/
|
||||||
|
|
||||||
|
endwin();\
|
||||||
|
echo();\
|
||||||
|
curs_set(1);\
|
||||||
|
if (system(key_binding[index].black_magic)) {
|
||||||
|
}
|
||||||
|
initscr(); /* start ncurses */
|
||||||
|
noecho(); /* hide keyboard input */
|
||||||
|
curs_set(0);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
|
|
||||||
}
|
}
|
||||||
void not_implemented(unsigned long passes, int index){
|
void not_implemented(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
@@ -289,7 +378,33 @@ void not_implemented(unsigned long passes, int index){
|
|||||||
TODO;
|
TODO;
|
||||||
}
|
}
|
||||||
void jump_to_dir(unsigned long passes, int index){
|
void jump_to_dir(unsigned long passes, int index){
|
||||||
TODO;
|
(void)passes;
|
||||||
|
|
||||||
|
unsigned long len;
|
||||||
|
char *c = strchr(key_binding[index].black_magic, '/');
|
||||||
|
if (c) {
|
||||||
|
len = c - (char*)key_binding[index].black_magic;
|
||||||
|
} else {
|
||||||
|
len = strlen(key_binding[index].black_magic);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *to_env = malloc(len + 1);
|
||||||
|
memcpy(to_env, key_binding[index].black_magic, len);
|
||||||
|
to_env[len] = '\0';
|
||||||
|
char *env = getenv(to_env + 1); /*+1 to remove the '$' prefix, freeing env always segfaults*/
|
||||||
|
|
||||||
|
if (env) {
|
||||||
|
char *path = malloc(strlen(key_binding[index].black_magic) + strlen(env) + 1);
|
||||||
|
memcpy(path, env, strlen(env));
|
||||||
|
memcpy(path + strlen(env), key_binding[index].black_magic + len, strlen(key_binding[index].black_magic)+1);
|
||||||
|
change_dir(path);
|
||||||
|
free(path);
|
||||||
|
} else {
|
||||||
|
change_dir(key_binding[index].black_magic);
|
||||||
|
}
|
||||||
|
free(to_env);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
|
||||||
}
|
}
|
||||||
void order_by(unsigned long passes, int index){
|
void order_by(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
@@ -300,10 +415,34 @@ void order_by(unsigned long passes, int index){
|
|||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void cmd_on_selected(unsigned long passes, int index){
|
void cmd_on_selected(unsigned long passes, int index){
|
||||||
TODO;
|
(void)passes;
|
||||||
|
|
||||||
|
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||||
}
|
}
|
||||||
void yank_text(unsigned long passes, int index){
|
void yank_file_name(){
|
||||||
TODO;
|
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
|
}
|
||||||
|
void yank_file_path(){
|
||||||
|
file *tmp = malloc(sizeof(file));
|
||||||
|
tmp->file_name = malloc(strlen(global_path)+1+strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
memcpy(tmp->file_name, global_path, strlen(global_path));
|
||||||
|
memcpy(tmp->file_name+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
tmp->file_name[strlen(global_path)] = '/'; /*no +1 is needed*/
|
||||||
|
char *cmd = parse_cmd(clipboard_cmd, tmp);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
free(tmp->file_name);
|
||||||
|
free(tmp);
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void yank_file(unsigned long passes, int index){
|
void yank_file(unsigned long passes, int index){
|
||||||
TODO;
|
TODO;
|
||||||
@@ -312,13 +451,94 @@ void paste(){
|
|||||||
TODO;
|
TODO;
|
||||||
}
|
}
|
||||||
void search(){
|
void search(){
|
||||||
TODO;
|
echo();
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < terminal_width -1; i++) {
|
||||||
|
mvwaddch(win_b, 0, i, ' ');
|
||||||
|
}
|
||||||
|
mvwaddch(win_b, 0, 0, '/');
|
||||||
|
memset(search_buffer, 0, INPUT_BUFFER_SIZE);
|
||||||
|
|
||||||
|
curs_set(1);
|
||||||
|
echo();
|
||||||
|
|
||||||
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
|
|
||||||
|
unsigned int pass = 0;
|
||||||
|
char ch;
|
||||||
|
char err = 0;
|
||||||
|
|
||||||
|
wmove(win_b, 0, 1);
|
||||||
|
while(1) {
|
||||||
|
ch = wgetch(win_b);
|
||||||
|
if (ch == '\n') {
|
||||||
|
err = 0;
|
||||||
|
break;
|
||||||
|
} else if (ch == '\t') { /* tab */
|
||||||
|
memcpy(search_buffer + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
||||||
|
mvwaddstr(win_b, 0, pass+1, mid_dir.current_file->file_name);
|
||||||
|
pass += strlen(mid_dir.current_file->file_name);
|
||||||
|
} else if (ch == 127) { /* backspace */
|
||||||
|
if (pass > 0) {
|
||||||
|
pass--;
|
||||||
|
mvwdelch(win_b, 0, pass+1);
|
||||||
|
}
|
||||||
|
} else if (ch == 27) { /* esc key */
|
||||||
|
err = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ch) {
|
||||||
|
mvwaddch(win_b, 0, pass+1, ch);
|
||||||
|
search_buffer[pass] = ch;
|
||||||
|
pass++;
|
||||||
|
|
||||||
|
unsigned long index = (mid_dir.current_file - mid_dir.file_list);
|
||||||
|
unsigned long x = getmaxx(win_b);
|
||||||
|
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
|
||||||
|
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
|
|
||||||
|
/* re-render current dir */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
|
||||||
|
werase(win_m);
|
||||||
|
print_dir(win_m, 1, &mid_dir);
|
||||||
|
|
||||||
|
wnoutrefresh(win_m);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
search_buffer[pass] = '\0';
|
||||||
|
|
||||||
|
noecho();
|
||||||
|
curs_set(0);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
|
|
||||||
}
|
}
|
||||||
void search_next(){
|
void search_next(){
|
||||||
TODO;
|
long index = (mid_dir.current_file - mid_dir.file_list) + 1;
|
||||||
|
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
|
||||||
|
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void search_previous(){
|
void search_previous(){
|
||||||
TODO;
|
long index = (mid_dir.current_file - mid_dir.file_list) - 1;
|
||||||
|
for (; &mid_dir.file_list[index] >= mid_dir.file_list; index--) {
|
||||||
|
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void jmp_file_index(){
|
void jmp_file_index(){
|
||||||
TODO;
|
TODO;
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ void not_implemented(unsigned long passes, int index);
|
|||||||
void jump_to_dir(unsigned long passes, int index);
|
void jump_to_dir(unsigned long passes, int index);
|
||||||
void order_by(unsigned long passes, int index);
|
void order_by(unsigned long passes, int index);
|
||||||
void cmd_on_selected(unsigned long passes, int index);
|
void cmd_on_selected(unsigned long passes, int index);
|
||||||
void yank_text(unsigned long passes, int index);
|
void yank_file_name();
|
||||||
|
void yank_file_path();
|
||||||
void yank_file(unsigned long passes, int index);
|
void yank_file(unsigned long passes, int index);
|
||||||
void paste();
|
void paste();
|
||||||
void search();
|
void search();
|
||||||
|
|||||||
55
main.c
55
main.c
@@ -19,9 +19,8 @@ unsigned int terminal_width;
|
|||||||
unsigned int temp_heigth = 0; /*used for screen refresh*/
|
unsigned int temp_heigth = 0; /*used for screen refresh*/
|
||||||
unsigned int temp_width = 0;
|
unsigned int temp_width = 0;
|
||||||
unsigned int settings;
|
unsigned int settings;
|
||||||
unsigned int file_modifiers;
|
unsigned int file_modifiers = 0;
|
||||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY) & ~STATUS_UPDATE_SCREEN_RESIZE;
|
||||||
char *start_path;
|
|
||||||
char *global_path;
|
char *global_path;
|
||||||
time_t seed;
|
time_t seed;
|
||||||
|
|
||||||
@@ -36,10 +35,8 @@ extern pthread_mutex_t mutex_btm;
|
|||||||
extern pthread_mutex_t mutex_lft;
|
extern pthread_mutex_t mutex_lft;
|
||||||
extern pthread_mutex_t mutex_mid;
|
extern pthread_mutex_t mutex_mid;
|
||||||
extern pthread_mutex_t mutex_rgt;
|
extern pthread_mutex_t mutex_rgt;
|
||||||
extern volatile char render_queue[5];
|
|
||||||
|
|
||||||
char *input; /*used in user_interactions*/
|
char *input; /*used in user_interactions*/
|
||||||
char *terminal_width_empty_line; /* used in user_interactions */
|
|
||||||
|
|
||||||
void render_pass();
|
void render_pass();
|
||||||
void init();
|
void init();
|
||||||
@@ -66,7 +63,6 @@ int main(){
|
|||||||
pthread_t thread_m;
|
pthread_t thread_m;
|
||||||
pthread_t thread_r;
|
pthread_t thread_r;
|
||||||
|
|
||||||
terminal_width_empty_line = malloc(terminal_width);
|
|
||||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||||
time_t t;
|
time_t t;
|
||||||
time_t dt;
|
time_t dt;
|
||||||
@@ -79,19 +75,12 @@ int main(){
|
|||||||
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
||||||
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
||||||
|
|
||||||
|
|
||||||
/* running through all once manually in order to get an as fast as possible first render on the screen */
|
|
||||||
pthread_cond_signal(&cond_top);
|
|
||||||
pthread_cond_signal(&cond_mid);
|
|
||||||
pthread_cond_signal(&cond_lft);
|
|
||||||
render_pass();
|
|
||||||
timeout(SETTINGS_CURSES_TIMEOUT);
|
timeout(SETTINGS_CURSES_TIMEOUT);
|
||||||
|
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||||
|
|
||||||
user_interactions();
|
|
||||||
if (status & STATUS_RUN_BACKEND) {
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
free(global_path);
|
free(global_path);
|
||||||
global_path = getcwd(NULL, 0);
|
global_path = getcwd(NULL, 0);
|
||||||
@@ -108,6 +97,7 @@ int main(){
|
|||||||
temp_width = terminal_width;
|
temp_width = terminal_width;
|
||||||
temp_heigth = terminal_height;
|
temp_heigth = terminal_height;
|
||||||
}
|
}
|
||||||
|
user_interactions();
|
||||||
render_pass();
|
render_pass();
|
||||||
|
|
||||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||||
@@ -123,7 +113,6 @@ int main(){
|
|||||||
ueberzug_close();
|
ueberzug_close();
|
||||||
#endif
|
#endif
|
||||||
threading_free();
|
threading_free();
|
||||||
free(start_path);
|
|
||||||
|
|
||||||
delwin(win_l);
|
delwin(win_l);
|
||||||
delwin(win_m);
|
delwin(win_m);
|
||||||
@@ -160,43 +149,10 @@ void render_pass(){
|
|||||||
mvwin(win_b, terminal_height-1, 0);
|
mvwin(win_b, terminal_height-1, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
/* render_queue is modified both by this and its associated thread without mutexes, this is intentional.
|
if (pthread_mutex_lock(&mutex_render) == 0 || status & STATUS_UPDATE_SCREEN_MASK) {
|
||||||
* reason being that since rendering is done in the same thread as the logic,
|
|
||||||
* using mutexes actually slows this down more than the result of an unknown state.
|
|
||||||
* an unknown state may be an incomplete render, which in my tests wont crash, or one too many renders.
|
|
||||||
* both of these chances are non distructive.
|
|
||||||
* doing rendering async is done because
|
|
||||||
* A: its funny
|
|
||||||
* B: previous render pipelines may have caused win_r to lack behind
|
|
||||||
* C: slowdown as a result of too many renders */
|
|
||||||
if (render_queue[RENDER_QUEUE_TOP] || status & (STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)) {
|
|
||||||
wnoutrefresh(win_t);
|
|
||||||
render_queue[RENDER_QUEUE_TOP] = 0;
|
|
||||||
status |= STATUS_UPDATE_ASYNC_REFRESH;
|
|
||||||
}
|
|
||||||
if (render_queue[RENDER_QUEUE_LFT] || status & (STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)) {
|
|
||||||
wnoutrefresh(win_l);
|
|
||||||
render_queue[RENDER_QUEUE_LFT] = 0;
|
|
||||||
status |= STATUS_UPDATE_ASYNC_REFRESH;
|
|
||||||
}
|
|
||||||
if (render_queue[RENDER_QUEUE_MID] || status & (STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)) {
|
|
||||||
wnoutrefresh(win_m);
|
|
||||||
render_queue[RENDER_QUEUE_MID] = 0;
|
|
||||||
status |= STATUS_UPDATE_ASYNC_REFRESH;
|
|
||||||
}
|
|
||||||
if (render_queue[RENDER_QUEUE_RGT] || status & (STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)) {
|
|
||||||
wnoutrefresh(win_r);
|
|
||||||
render_queue[RENDER_QUEUE_RGT] = 0;
|
|
||||||
status |= STATUS_UPDATE_ASYNC_REFRESH;
|
|
||||||
}
|
|
||||||
if (render_queue[RENDER_QUEUE_BTM] || status & (STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)) {
|
|
||||||
wnoutrefresh(win_b);
|
|
||||||
render_queue[RENDER_QUEUE_BTM] = 0;
|
|
||||||
status |= STATUS_UPDATE_ASYNC_REFRESH;
|
|
||||||
}
|
|
||||||
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
|
||||||
doupdate();
|
doupdate();
|
||||||
status &= ~STATUS_UPDATE_SCREEN_MASK;
|
status &= ~STATUS_UPDATE_SCREEN_MASK;
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
||||||
@@ -214,7 +170,6 @@ void init() {
|
|||||||
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
||||||
input = malloc(INPUT_BUFFER_SIZE); /* size of input buffer, out of bounds access will not be accounted for */
|
input = malloc(INPUT_BUFFER_SIZE); /* size of input buffer, out of bounds access will not be accounted for */
|
||||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
|
||||||
if (getuid() == 0) {
|
if (getuid() == 0) {
|
||||||
status |= STATUS_USER_ROOT;
|
status |= STATUS_USER_ROOT;
|
||||||
}
|
}
|
||||||
|
|||||||
96
threading.c
96
threading.c
@@ -18,7 +18,7 @@ pthread_mutex_t mutex_btm;
|
|||||||
pthread_mutex_t mutex_lft;
|
pthread_mutex_t mutex_lft;
|
||||||
pthread_mutex_t mutex_mid;
|
pthread_mutex_t mutex_mid;
|
||||||
pthread_mutex_t mutex_rgt;
|
pthread_mutex_t mutex_rgt;
|
||||||
pthread_mutex_t mutex_selection;
|
pthread_mutex_t mutex_render;
|
||||||
pthread_cond_t cond_mid;
|
pthread_cond_t cond_mid;
|
||||||
pthread_cond_t cond_rgt;
|
pthread_cond_t cond_rgt;
|
||||||
pthread_cond_t cond_lft;
|
pthread_cond_t cond_lft;
|
||||||
@@ -46,7 +46,6 @@ unsigned long top_width;
|
|||||||
|
|
||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
volatile char render_queue[RENDER_QUEUE_BTM+1];
|
|
||||||
extern char *global_path;
|
extern char *global_path;
|
||||||
|
|
||||||
unsigned int btm_status;
|
unsigned int btm_status;
|
||||||
@@ -62,18 +61,18 @@ void *thread_mid(){
|
|||||||
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
pthread_cond_wait(&cond_mid, &mutex_mid);
|
pthread_cond_wait(&cond_mid, &mutex_mid);
|
||||||
unsigned int local_status = status;
|
|
||||||
|
|
||||||
if (global_path == NULL) {
|
if (global_path == NULL) {
|
||||||
mid_dir.current_file = NULL;
|
mid_dir.current_file = NULL;
|
||||||
mid_dir.file_count = 0;
|
mid_dir.file_count = 0;
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char *path = malloc(strlen(global_path)+1);
|
char *path = malloc(strlen(global_path)+1);
|
||||||
memcpy(path, global_path, strlen(global_path)+1);
|
memcpy(path, global_path, strlen(global_path)+1);
|
||||||
|
|
||||||
|
|
||||||
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
long index = mid_dir.current_file - mid_dir.file_list;
|
long index = mid_dir.current_file - mid_dir.file_list;
|
||||||
|
|
||||||
tmp = mid_dir;
|
tmp = mid_dir;
|
||||||
@@ -88,6 +87,11 @@ void *thread_mid(){
|
|||||||
mid_dir.current_file = NULL;
|
mid_dir.current_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long i;
|
||||||
|
for(i = 0; i < mid_dir.file_count && i < tmp.file_count; i++) {
|
||||||
|
mid_dir.file_list[i].status = tmp.file_list[i].status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,26 +102,29 @@ void *thread_mid(){
|
|||||||
mid_dir.current_file = mid_dir.file_list;
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
|
pthread_cond_signal(&cond_top);
|
||||||
|
pthread_cond_signal(&cond_btm);
|
||||||
|
pthread_cond_signal(&cond_rgt);
|
||||||
|
|
||||||
|
|
||||||
/* rendering */
|
/* rendering */
|
||||||
render_queue[RENDER_QUEUE_MID] = 0;
|
pthread_mutex_lock(&mutex_render);
|
||||||
werase(win_m);
|
werase(win_m);
|
||||||
if (mid_dir.file_count == 0) {
|
if (mid_dir.file_count == 0) {
|
||||||
mvwaddstr(win_m, 0, 0, "empty");
|
mvwaddstr(win_m, 0, 0, "empty");
|
||||||
} else {
|
} else {
|
||||||
print_dir(win_m, 1, &mid_dir);
|
print_dir(win_m, 1, &mid_dir);
|
||||||
}
|
}
|
||||||
render_queue[RENDER_QUEUE_MID] = 1;
|
wnoutrefresh(win_m);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
pthread_cond_signal(&cond_rgt);
|
|
||||||
pthread_cond_signal(&cond_top);
|
|
||||||
pthread_cond_signal(&cond_btm);
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
|
||||||
|
|
||||||
|
|
||||||
btm_status = local_status;
|
|
||||||
|
|
||||||
|
|
||||||
long i;
|
|
||||||
|
unsigned long i;
|
||||||
for (i = 0; i < tmp.file_count; i++) {
|
for (i = 0; i < tmp.file_count; i++) {
|
||||||
free(tmp.file_list[i].file_name);
|
free(tmp.file_list[i].file_name);
|
||||||
}
|
}
|
||||||
@@ -133,7 +140,6 @@ void *thread_lft(){
|
|||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_lft);
|
pthread_mutex_lock(&mutex_lft);
|
||||||
pthread_cond_wait(&cond_lft, &mutex_lft);
|
pthread_cond_wait(&cond_lft, &mutex_lft);
|
||||||
unsigned int local_status = status;
|
|
||||||
|
|
||||||
if (global_path == NULL) {
|
if (global_path == NULL) {
|
||||||
lft_dir.current_file = NULL;
|
lft_dir.current_file = NULL;
|
||||||
@@ -144,13 +150,12 @@ void *thread_lft(){
|
|||||||
char *path = malloc(strlen(global_path)+1);
|
char *path = malloc(strlen(global_path)+1);
|
||||||
memcpy(path, global_path, strlen(global_path)+1);
|
memcpy(path, global_path, strlen(global_path)+1);
|
||||||
|
|
||||||
render_queue[RENDER_QUEUE_LFT] = 0;
|
|
||||||
if (strcmp(path, "/") != 0) {
|
if (strcmp(path, "/") != 0) {
|
||||||
path[strrchr(path, '/')-path+1] = '\0';
|
path[strrchr(path, '/')-path+1] = '\0';
|
||||||
path[strrchr(path, '/')-path] = '\0';
|
path[strrchr(path, '/')-path] = '\0';
|
||||||
path[0] = '/';
|
path[0] = '/';
|
||||||
|
|
||||||
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < lft_dir.file_count; i++) {
|
for (i = 0; i < lft_dir.file_count; i++) {
|
||||||
free(lft_dir.file_list[i].file_name);
|
free(lft_dir.file_list[i].file_name);
|
||||||
@@ -171,14 +176,15 @@ void *thread_lft(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* rendering */
|
/* rendering */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
werase(win_l);
|
werase(win_l);
|
||||||
print_dir(win_l, 0, &lft_dir);
|
print_dir(win_l, 0, &lft_dir);
|
||||||
render_queue[RENDER_QUEUE_LFT] = 1;
|
wnoutrefresh(win_l);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
|
|
||||||
@@ -209,10 +215,10 @@ void *thread_rgt(){
|
|||||||
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
render_queue[RENDER_QUEUE_RGT] = 0;
|
|
||||||
werase(win_r);
|
|
||||||
if (rgt_dir.current_file->permissions & S_IRUSR) {
|
if (rgt_dir.current_file->permissions & S_IRUSR) {
|
||||||
if (rgt_dir.current_file->file_type &= FILE_TYPE_DIR) {
|
if (rgt_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
#endif
|
#endif
|
||||||
@@ -226,25 +232,32 @@ void *thread_rgt(){
|
|||||||
} else { /* the hovered dir is empty */
|
} else { /* the hovered dir is empty */
|
||||||
rgt_dir.current_file = NULL;
|
rgt_dir.current_file = NULL;
|
||||||
}
|
}
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
werase(win_r);
|
||||||
print_dir(win_r, 0, &rgt_dir);
|
print_dir(win_r, 0, &rgt_dir);
|
||||||
|
wnoutrefresh(win_r);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
|
||||||
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && rgt_dir.file_count > 0) {
|
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && rgt_dir.file_count > 0) {
|
||||||
|
|
||||||
free(rgt_buffer);
|
free(rgt_buffer);
|
||||||
rgt_buffer = preview_file(rgt_dir.current_file);
|
rgt_buffer = preview_file(rgt_dir.current_file);
|
||||||
rgt_dir.current_file->file_type |= FILE_TYPE_OPEN_FILE;
|
rgt_dir.current_file->file_type |= FILE_TYPE_OPEN_FILE;
|
||||||
if (rgt_dir.current_file->file_type == FILE_TYPE_OPEN_FILE) {
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
werase(win_r);
|
||||||
|
if (rgt_dir.current_file->file_type & FILE_TYPE_OPEN_FILE) {
|
||||||
mvwaddnstr(win_r, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
mvwaddnstr(win_r, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
||||||
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
|
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
|
||||||
mvwaddstr(win_r, 0, 0, "not accessible");
|
mvwaddstr(win_r, 0, 0, "not accessible");
|
||||||
}
|
}
|
||||||
|
wnoutrefresh(win_r);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render_queue[RENDER_QUEUE_RGT] = 1;
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
long i;
|
unsigned long i;
|
||||||
for (i = 0; i < tmp.file_count; i++) {
|
for (i = 0; i < tmp.file_count; i++) {
|
||||||
free(tmp.file_list[i].file_name);
|
free(tmp.file_list[i].file_name);
|
||||||
}
|
}
|
||||||
@@ -263,7 +276,6 @@ void *thread_top(){
|
|||||||
pthread_cond_wait(&cond_top, &mutex_top);
|
pthread_cond_wait(&cond_top, &mutex_top);
|
||||||
|
|
||||||
|
|
||||||
render_queue[RENDER_QUEUE_TOP] = 0;
|
|
||||||
free(top_buffer);
|
free(top_buffer);
|
||||||
|
|
||||||
if(global_path == NULL) {
|
if(global_path == NULL) {
|
||||||
@@ -273,23 +285,27 @@ void *thread_top(){
|
|||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
top_buffer = malloc(strlen(global_path)+1);
|
|
||||||
memcpy(top_buffer, global_path, strlen(global_path)+1);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
|
|
||||||
|
top_buffer = malloc(strlen(global_path)+1 + strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
memcpy(top_buffer, global_path, strlen(global_path));
|
||||||
|
memcpy(top_buffer + strlen(global_path) + 1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
top_buffer[strlen(global_path)] = '/';
|
||||||
top_width = strlen(top_buffer);
|
top_width = strlen(top_buffer);
|
||||||
|
|
||||||
|
|
||||||
/* rendering */
|
/* rendering */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
werase(win_t);
|
werase(win_t);
|
||||||
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
|
||||||
wattron(win_t, COLOR_PAIR(COLOR_PATH));
|
wattron(win_t, COLOR_PAIR(COLOR_PATH));
|
||||||
mvwaddstr(win_t, 0, 0, top_buffer);
|
mvwaddnstr(win_t, 0, 0, top_buffer, strlen(global_path)+1);
|
||||||
mvwaddch(win_t, 0, strlen(top_buffer), '/');
|
|
||||||
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
|
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
|
||||||
if (mid_dir.file_count != 0 && !(mid_dir.current_file == NULL)) {
|
mvwaddstr(win_t, 0, strlen(global_path)+1, top_buffer+strlen(global_path)+1);
|
||||||
mvwaddstr(win_t, 0, strlen(top_buffer)+1, mid_dir.current_file->file_name);
|
wnoutrefresh(win_t);
|
||||||
}
|
pthread_mutex_unlock(&mutex_render);
|
||||||
}
|
|
||||||
render_queue[RENDER_QUEUE_TOP] = 1;
|
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
@@ -305,11 +321,9 @@ void *thread_btm(){
|
|||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
pthread_cond_wait(&cond_btm, &mutex_btm);
|
pthread_cond_wait(&cond_btm, &mutex_btm);
|
||||||
unsigned int local_status = btm_status;
|
|
||||||
|
|
||||||
render_queue[RENDER_QUEUE_BTM] = 0;
|
|
||||||
|
|
||||||
if (local_status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
|
if (status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
|
||||||
/*{{{ parse storage info; the fold of shame*/
|
/*{{{ parse storage info; the fold of shame*/
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
@@ -405,11 +419,13 @@ void *thread_btm(){
|
|||||||
|
|
||||||
|
|
||||||
/* rendering */
|
/* rendering */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||||
mvwprintw(win_b, 0, 0, "%s", btm_buffer);
|
mvwprintw(win_b, 0, 0, "%s", btm_buffer);
|
||||||
}
|
}
|
||||||
render_queue[RENDER_QUEUE_BTM] = 1;
|
wnoutrefresh(win_b);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
/*the printing of all possible inputs are done in user_interactions */
|
/*the printing of all possible inputs are done in user_interactions */
|
||||||
|
|
||||||
@@ -434,7 +450,7 @@ void threading_init(){
|
|||||||
pthread_mutex_init(&mutex_lft, NULL);
|
pthread_mutex_init(&mutex_lft, NULL);
|
||||||
pthread_mutex_init(&mutex_btm, NULL);
|
pthread_mutex_init(&mutex_btm, NULL);
|
||||||
pthread_mutex_init(&mutex_rgt, NULL);
|
pthread_mutex_init(&mutex_rgt, NULL);
|
||||||
pthread_mutex_init(&mutex_selection, NULL);
|
pthread_mutex_init(&mutex_render, NULL);
|
||||||
pthread_cond_init(&cond_rgt, NULL);
|
pthread_cond_init(&cond_rgt, NULL);
|
||||||
pthread_cond_init(&cond_lft, NULL);
|
pthread_cond_init(&cond_lft, NULL);
|
||||||
pthread_cond_init(&cond_mid, NULL);
|
pthread_cond_init(&cond_mid, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user