Compare commits

...

46 Commits

Author SHA1 Message Date
nova 60127a6b9b cleanup 2026-06-16 23:53:35 +02:00
nova 7091c47a2c comment 2026-06-16 23:41:39 +02:00
nova e6318f8d1e wattroff -> wattrset to disable all attributes 2026-06-16 23:37:13 +02:00
nova f6c39ce039 minor changes 2026-06-16 23:28:03 +02:00
nova ef4e49e022 cleanup 2026-06-16 22:52:03 +02:00
nova eafb13d3e2 cleanup 2026-06-16 22:43:33 +02:00
nova f88b86c1f5 cleanup 2026-06-16 22:22:29 +02:00
nova d8b3706f64 fix of incorrect if condition 2026-06-15 20:29:41 +02:00
nova c0299aef8c proper handling of empty dirs (hopefully) 2026-06-15 20:28:39 +02:00
nova 4def2c7cf0 implementation of jmp_file_index 2026-06-14 14:05:04 +02:00
nova 50f7e7c67d implementation of delete 2026-06-14 13:26:46 +02:00
nova 9bdf677a56 implementation of copy_file and paste 2026-06-08 22:05:40 +02:00
nova 5a31f452ea implementation of cmd_on_selected 2026-06-04 20:32:32 +02:00
nova daf43daa00 implementation of jump_to_dir 2026-06-04 20:03:10 +02:00
nova cf03a230b6 implementation of open_with 2026-06-03 23:00:06 +02:00
nova 87bfdd1b86 rename_hovered, adjustments to makefile & makedir and its associated config 2026-06-01 23:46:38 +02:00
nova 20fee198ae some ui stuff 2026-06-01 22:54:24 +02:00
nova 632904fd89 implementation of makedir & makefile 2026-06-01 22:36:38 +02:00
nova dd5307b411 removal of possible NULL argument 2026-05-30 00:41:40 +02:00
nova 41933eb6d0 removal of possible null argument in strlen 2026-05-30 00:12:32 +02:00
nova 0a45d1e3e8 better chdir handling 2026-05-25 23:00:17 +02:00
nova d33ac88de2 implementation of keeping the index of current file in between dir changes 2026-05-25 17:36:39 +02:00
nova e42d55e66a implementation of yank_file_name and yank_file_path 2026-05-25 12:01:43 +02:00
nova f6380ddeda small fix of strlen(offset+1) to strlen(offset)+1 2026-05-25 11:24:58 +02:00
nova 905f6e8588 forgor them last commit 2026-05-25 11:07:42 +02:00
nova 095cf7b357 implementation of all 3 search functions 2026-05-23 15:13:38 +02:00
nova 9f7ed73885 proper forking of spawned processes 2026-05-21 01:11:56 +02:00
nova 41af25e0b1 removal of automatic space in cmd with SETTINGS_COMMAND_REPLACE_STR 2026-05-21 00:09:19 +02:00
nova f807fe56b5 fix of dir->file_list[i].file_type being accidentally overwritten 2026-05-21 00:06:39 +02:00
nova adb10b6d5d (hopefully) finalizing move_right 2026-05-21 00:05:36 +02:00
nova c692a1a992 cleanup 2026-05-15 00:10:23 +02:00
nova 8c80a6e3da fix of an edgecase not unlocknig mutex 2026-05-14 23:52:16 +02:00
nova 1aa66c82fb simplification of thread_top 2026-05-14 23:50:21 +02:00
nova f5d0c8bc85 deletion of unused vars 2026-05-14 23:15:24 +02:00
nova 9e8bd3c022 parse_path 2026-05-14 23:10:06 +02:00
nova f40cc91cce cleanup 2026-05-14 23:06:48 +02:00
nova a5483335c5 reordering of some things 2026-05-14 20:07:37 +02:00
nova a7d4a6322c fix of a very rare edgecase in which thread_top get the wrong mid_dir.current_file->file_name 2026-05-14 19:54:51 +02:00
nova 749dba1ce8 yet another change to the rendering pipeline 2026-05-14 18:50:36 +02:00
nova ac0b644bcb implementation select_all and toggle_selection pt2 2026-05-14 12:17:06 +02:00
nova b4acda1aa6 implementation select_all and toggle_selection 2026-05-14 12:07:24 +02:00
nova b7124cbb1d implementation of enter_shell 2026-05-10 22:09:42 +02:00
nova adac32fcc1 fixing of minor compiler warnings 2026-05-10 21:58:40 +02:00
nova dcb47d420b deletion of now useless functions 2026-05-10 21:56:40 +02:00
nova 689565f732 now each thread can queue its own rendering 2026-05-10 21:44:02 +02:00
nova 58f99eb2cf small correction 2026-05-10 20:11:58 +02:00
12 changed files with 806 additions and 504 deletions
+47 -7
View File
@@ -82,10 +82,15 @@ char* smartstrcasestr(const char *haystack, const char *needle){
char* parse_cmd(const char *cmd, file *f){
char *out;
if (f == NULL) {
out = malloc(strlen(cmd)+1);
memcpy(out, cmd, strlen(cmd)+1);
return out;
}
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
int count = 0;
char *out;
char *pos;
unsigned long i = 0;
while(f->file_name[i]) {
@@ -100,13 +105,13 @@ char* parse_cmd(const char *cmd, file *f){
pos = out;
if (offset) {
memcpy(pos, cmd, offset - cmd);
pos += offset - cmd + 1;
pos += offset - cmd;
} else {
memcpy(pos, cmd, strlen(cmd));
pos += strlen(cmd) + 1;
pos[-1] = ' ';
}
pos[-1] = ' ';
pos[0] = '\'';
*pos = '\'';
pos++;
i = 0;
@@ -124,12 +129,47 @@ char* parse_cmd(const char *cmd, file *f){
if (offset) {
pos[1]= ' ';
memcpy(pos + 1, offset+1, strlen(offset+1));
pos[strlen(offset+1)] = '\0';
memcpy(pos + 1, offset+1, strlen(offset)+1);
pos[strlen(offset)+1] = '\0';
} else {
pos[1] = '\0';
}
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;
}
+1 -4
View File
@@ -9,7 +9,6 @@
unsigned int color_count;
color *colors;
extern unsigned int settings;
extern unsigned int status;
void parse_colors(char *line, short *fg, short *bg){
@@ -31,7 +30,6 @@ void parse_colors(char *line, short *fg, short *bg){
void colors_init() {
if (has_colors()) {
settings |= SETTINGS_HAS_COLOR;
start_color();
color_count = 0;
@@ -102,8 +100,7 @@ void colors_init() {
while (getline(&line, &size, dircolors) != -1) {
fg = 7;
bg = 0;
if (line[0] == '.') {
extension = strtok(line, " ");
if (line[0] == '.' && (extension = strtok(line, " ")) != NULL) {
colors[i].file_extension = malloc(strlen(extension)+1);
memcpy(colors[i].file_extension, extension, strlen(extension)+1);
+38 -23
View File
@@ -4,6 +4,7 @@
#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
* 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
@@ -13,6 +14,14 @@
#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 char copy_cmd[] = "cp -r";
static const char cut_cmd[] = "mv";
static const char del_cmd[] = "rm -r";
static const mimetype mimetype_default_cmd[] = {
/* mimetype shell command
* ^ substring of "file --mime-type -b ./hovered"
@@ -21,21 +30,21 @@ static const mimetype mimetype_default_cmd[] = {
* file --mime-type -b ./image.gif
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
* we need to define "gif" before "image" */
{ "text", "$EDITOR" },
{ "avif", "nohup mpv ^ >/dev/null 2>&1 &" },
{ "gif", "nohup mpv --loop-file=\"inf\" ^ >/dev/null 2>&1 &" },
{ "image", "feh ^ >/dev/null 2>&1 &" },
{ "video", "nohup mpv ^ >/dev/null 2>&1 &" },
{ "audio", "mpv" },
{ "pdf", "zathura" },
{ "text", "$EDITOR" },
{ "avif", "@ mpv" },
{ "gif", "@ mpv --loop-file=\"inf\"" },
{ "image", "@ feh" },
{ "video", "@ 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 ^ &"},
{ ".cbz", "@ mcomix"},
{ ".cbr", "@ mcomix"},
{ ".json", "$EDITOR"},
{ ".csv", "$EDITOR"},
{ ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */
@@ -62,14 +71,14 @@ static const binding key_binding[] = {
{ "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 */
{ "\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 */
{ "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 */
{ "yn", yank_text, "name", "yank filename of hovered file" },
{ "yp", yank_text, "path", "yank path of hovered file" },
{ "yy", yank_file, "copy", "copy/yank file/directory" },
{ "dd", yank_file, "cut", "cut file/directory" },
{ "yn", yank_file_name, NULL, "yank filename of hovered file" },
{ "yp", yank_file_path, NULL, "yank path of hovered file" },
{ "yy", copy_file, COPY_FILE, "copy/yank file/directory" },
{ "dd", copy_file, CUT_FILE, "cut file/directory" },
{ "pp", paste, NULL, "paste" },
{ "G", jump_bottom, NULL, "jump to last file in dir" },
@@ -113,13 +122,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 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_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_1[] = "with:";
static const char ui_rename_text_0[] = "rename"; /*ui_rename_text_0 \"selected_file\" ui_rename_text_1*/
static const char ui_rename_text_1[] = "to:";
static const char ui_open_with_text[] = "open "SETTINGS_COMMAND_REPLACE_STR" with:";
static const char ui_rename_text[] = "rename "SETTINGS_COMMAND_REPLACE_STR" to:";
static const char ui_makefile_text[] = "makedir:";
static const char ui_makedir_text[] = "makefile:";
static const char ui_delete_text[] = "delete:";
/* {{{ */
@@ -129,6 +137,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;
#else
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 extension file_extension_default_cmd[];
static const binding key_binding[];
@@ -137,10 +148,14 @@ static const unsigned long mimetype_default_count;
static const unsigned long file_extension_default_count;
static const char size_unit[];
static const char size_unit_count;
static const char ui_open_with_text_0[];
static const char ui_open_with_text_1[];
static const char ui_rename_text_0[];
static const char ui_rename_text_1[];
static const char ui_open_with_text[];
static const char ui_makedir_text[];
static const char ui_makefile_text[];
static const char ui_rename_text[];
static const char ui_delete_text[];
static const char copy_cmd[];
static const char cut_cmd[];
static const char del_cmd[];
#endif
/* }}} */
+12 -11
View File
@@ -3,11 +3,8 @@
#define STATUS_QUIT_PROGRAM 1
#define STATUS_RUN_BACKEND 2
#define STATUS_RELOAD_DIRECTORY 4
#define STATUS_UPDATE_SCREEN_GENERIC 8
#define STATUS_UPDATE_SCREEN_RESIZE 16
#define STATUS_UPDATE_SCREEN_CLEAR 32
#define STATUS_UPDATE_SCREEN_DIR_CHANGE 64
#define STATUS_UPDATE_SCREEN_MASK (STATUS_UPDATE_SCREEN_GENERIC | STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR | STATUS_UPDATE_SCREEN_DIR_CHANGE)
#define STATUS_UPDATE_SCREEN_RESIZE 8
#define STATUS_UPDATE_SCREEN_CLEAR 16
#define STATUS_USER_ROOT 128
#define STATUS_INPUT_MATCH 256
#define STATUS_DELTA_TIME 512
@@ -15,6 +12,12 @@
#define SETTINGS_HAS_COLOR 1
#define RENDER_QUEUE_TOP 0
#define RENDER_QUEUE_LFT 1
#define RENDER_QUEUE_MID 2
#define RENDER_QUEUE_RGT 3
#define RENDER_QUEUE_BTM 4
#define FILE_MODIFIERS_HIDDEN_FILES 1
#define FILE_MODIFIERS_SORT_BITMASK 126 /* 00000000000000000000000001111110*/
#define FILE_MODIFIERS_SORT_ALPHABETIC 2
@@ -54,9 +57,8 @@
#define FILE_TYPE_SYMLINK 64
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
#define YANK_IS_USED 1
#define YANK_CUT 2
#define YANK_COPY 4
#define COPY_FILE (int*)0x0001
#define CUT_FILE (int*)0x0002
#define BTM_WINDOW_HEIGHT_ON_STR_INTERACTION 5
#define INPUT_BUFFER_SIZE 255
@@ -96,14 +98,13 @@ typedef struct Binding {
char* comment;
} binding;
typedef struct Yank {
char status;
char *path;
int *status; /*pointer to make blackmagic easier, should probably not deref lol*/
char **list;
unsigned long count;
} yank;
typedef struct Linked_dir {
char *path;
unsigned long selected_file_current;
unsigned long index;
struct Linked_dir *next;
} linked_dir;
+105 -123
View File
@@ -17,43 +17,47 @@ extern unsigned int settings;
extern unsigned int file_modifiers;
extern unsigned int color_count;
extern unsigned int terminal_height;
extern volatile unsigned long selected_file_current;
extern volatile unsigned long selected_file_last;
extern char *global_path;
extern color *colors;
int (*order_func)() = sort_natural;
linked_dir *visited_dirs;
linked_dir *current_dir;
linked_dir *list_beginning;
linked_dir *current_linked_dir;
unsigned long get_dir_size(char *path){
DIR *dir = opendir(path);
unsigned long entry_count = 0;
struct dirent *entry;
if (dir && file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
while ((entry=readdir(dir))) {
entry_count++;
}
/* removes files "." and ".." */
entry_count -= 2;
} else if (dir) {
while ((entry=readdir(dir))) {
if (entry->d_name[0] != '.') {
if (dir) {
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
while ((entry=readdir(dir))) {
entry_count++;
}
}
/* removes files "." and ".." */
entry_count -= 2;
} else {
while ((entry=readdir(dir))) {
if (entry->d_name[0] != '.') {
entry_count++;
}
}
}
closedir(dir);
}
closedir(dir);
return entry_count;
}
void get_dir_content(char *path, dir *dir){
struct dirent **entry = NULL;
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
scandir(path, &entry, skip_dot, NULL);
} else {
scandir(path, &entry, skip_hidden_files, NULL);
}
char *full_path = NULL;
unsigned long i = 0;
for (i = 0; i < dir->file_count; i++ ) {
@@ -158,24 +162,24 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
unsigned long offset_vertical = 0;
unsigned long offset_back = 0;
#if SETTINGS_LINE_NUMBERS == 0
unsigned long offset_front = 0;
unsigned long offset_front = 0;
#else
long offset_front = 2;
long offset_front = 2;
#endif
unsigned long selected_file_current = dir->current_file - dir->file_list;
long offset_index = 2; /* only used for the index of the file itself */
if (print_info) {
#if SETTINGS_LINE_NUMBERS != 0
if (dir->file_count > 9) {
#if SETTINGS_LINE_NUMBERS != 0
unsigned long dir_file_count_ = dir->file_count;
while(dir_file_count_ > 9) {
offset_front++;
dir_file_count_ /= 10;
}
#endif
}
#endif
/* scrolling of the directory if too many files are in a dir */
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;
@@ -188,8 +192,6 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
}
for (i = offset_vertical; i < dir->file_count && i < (terminal_height + offset_vertical); i++) {
if (print_info) {
file_size = dir->file_list[i].file_size;
char size_index = -1;
@@ -201,9 +203,9 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
} while (file_size > 1 && size_index < size_unit_count);
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);
} else if (size_char =='B') {
} else if (size_char == size_unit[0]) {
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
} else {
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
@@ -213,28 +215,20 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
}
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
wattron(win, COLOR_PAIR(8)); /* FIFO, as seen in colors.c */
is_selected = 1;
} else {
is_selected = 0;
}
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
wattron(win, COLOR_PAIR(8));
} else {
wattron(win, COLOR_PAIR(dir->file_list[i].color_pair));
is_selected = 0;
}
if (&dir->file_list[i] == dir->current_file) {
wattron(win, A_REVERSE);
unsigned long bg = 0;
for (bg = 0; bg < line_width; bg++) {
mvwaddch(win, i-offset_vertical, bg, ' ');
}
}
} else {
wattroff(win, A_REVERSE);
}
if(print_info) {
#if SETTINGS_LINE_NUMBERS == 2
long i_ = (selected_file_current) - i;
@@ -267,14 +261,14 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
#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);
}else if (size_char =='B') {
}else if (size_char == size_unit[0]) {
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
} else {
mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char);
}
}
}
char *extension = strrchr(dir->file_list[i].file_name, '.');
unsigned long printable_size = offset_back-offset_front-is_selected-2;
@@ -286,107 +280,95 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
}
wattrset(win, 0);
/*
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
wattroff(win, COLOR_PAIR(8));
} else {
wattroff(win, COLOR_PAIR(dir->file_list[i].color_pair));
}
*/
}
}
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);
while(current_dir->next != NULL) {
if (strcmp(path, current_dir->path) == 0) {
hit = 1;
current_linked_dir = list_beginning;
while (current_linked_dir->next != NULL) {
if(strcmp(current_linked_dir->path, path) == 0) {
break;
} else {
current_linked_dir = current_linked_dir->next;
}
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;
if(strcmp(current_linked_dir->path, path) == 0) {
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
} else {
free(path);
return current_dir->selected_file_current;
/**/
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){
const char *old_path = global_path;
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;
}
if (chdir(new_path) != 0) {
/* i have made the decission that this is a case that i do not want to handle
* god may help me if this ever fails, cuz damn thatll be hard to debug
* especially in like 2 years when i even forgot about this possibility */
return;
}
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(new_path_real);
}
void dir_init(){
visited_dirs = malloc(sizeof(linked_dir));
visited_dirs->path = getcwd(NULL, 0);
visited_dirs->selected_file_current = 0;
visited_dirs->next = NULL;
current_dir = visited_dirs;
list_beginning = malloc(sizeof(linked_dir));
list_beginning->path = getcwd(NULL, 0);
list_beginning->index = 0;
list_beginning->next = NULL;
current_linked_dir = list_beginning;
}
void recursive_delete(file current_file){
/*
if (S_ISLNK(current_file.permissions)) {
remove(current_file.file_name);
} else if (current_file.file_type & FILE_TYPE_DIR ) {
unsigned int file_modifiers_tmp = file_modifiers;
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
unsigned long current_file_count = get_dir_size(current_file.file_name);
if (current_file_count != 0) {
file *current_dir = malloc(current_file_count * sizeof(file));
memset(current_dir, '\0', current_file_count * sizeof(file));
get_dir_content(current_file.file_name, &current_file_count, current_dir);
if (chdir(current_file.file_name) != 0) {
return;
}
unsigned long i;
for (i = 0; i < current_file_count; i++) {
recursive_delete(current_dir[i]);
free(current_dir[i].file_name);
}
free(current_dir);
if (chdir("..") != 0) {
return;
}
}
remove(current_file.file_name);
file_modifiers = file_modifiers_tmp;
} else {
remove(current_file.file_name);
}
*/
}
-1
View File
@@ -10,4 +10,3 @@ char update_selected_file();
void dir_set_selected_file_current(unsigned long selected_file_current);
unsigned long dir_get_selected_file_current();
void dir_init();
void recursive_delete(file current_file);
+483 -88
View File
@@ -1,7 +1,6 @@
#include <curses.h>
#include <pthread.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -12,40 +11,25 @@
#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_btm;
extern pthread_cond_t cond_rgt;
extern pthread_cond_t cond_mid;
extern pthread_mutex_t mutex_render;
extern WINDOW *win_b;
extern WINDOW *win_m;
extern dir mid_dir;
extern unsigned int terminal_height;
extern unsigned int terminal_width;
extern WINDOW *win_b;
extern char *rgt_buffer;
extern char *btm_buffer;
extern unsigned int status;
extern char *start_path;
extern char *global_path;
extern char *input;
extern time_t seed;
char search_buffer[INPUT_BUFFER_SIZE];
unsigned int input_pass;
unsigned long parsed_input_number;
yank yank_files = { 0 };
extern void render_pass();
extern int (*order_func)();
#define TODO noraw(); \
endwin();\
@@ -54,15 +38,18 @@ extern int (*order_func)();
printf("TODO: %s at %d in %s \n", __func__, __LINE__, __FILE__);\
exit(1);
void FAIL(char *function, char *str){
printf("ERROR in function %s: %s", function, str);
}
#define skip_if_empty_dir \
if (mid_dir.current_file == NULL) { \
return; \
}
void user_interactions() {
char ch;
unsigned long i;
unsigned long binding_matches = 0;
static unsigned int input_pass;
ch = getch();
@@ -92,6 +79,9 @@ void user_interactions() {
char cmp_len = strlen(input);
if(strlen(input) < 1) {
/* strlen is 0 every iteration nothing is pressed
* should this be input in the strncmp, it always succeeds.
* this results in all possible bindings being printed at all times */
cmp_len = 1;
}
for (i = 0; i < binding_count; i++) {
@@ -134,25 +124,23 @@ int read_string(WINDOW *win, int y, int x, char *str){
wmove(win, y, x);
while(1) {
/*ch = mvwgetch(win, y, x + pass);*/
ch = wgetch(win);
if (ch == '\n') {
err = 0;
break;
} else if (ch == 27) { /* esc key */
err = 1;
break;
} else if (ch == '\t') { /* tab */
memcpy(str + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
mvwaddstr(win, y, x +pass, mid_dir.current_file->file_name);
mvwaddstr(win, y, x + pass, 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, y, pass);
mvwdelch(win, y, x + pass);
}
} else if (ch == 27) { /* esc key */
err = 1;
break;
} else {
mvwaddch(win, y, x +pass, ch);
mvwaddch(win, y, x + pass, ch);
str[pass] = ch;
pass++;
}
@@ -167,48 +155,59 @@ void quit_program(){
status = STATUS_QUIT_PROGRAM;
}
void update(){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_RELOAD_DIRECTORY );
}
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){
/*bounds checking happens within thread_mid*/
mid_dir.current_file += passes;
skip_if_empty_dir;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_GENERIC);
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);
}
void move_up(unsigned long passes){
/*bounds checking happens within thread_mid*/
mid_dir.current_file -= passes;
skip_if_empty_dir;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_GENERIC);
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);
}
void move_left(unsigned long passes){
unsigned long i;
for (i = 0; i < passes; i++) {
if (chdir("..") != 0) {
/* TODO(2025-07-09T00:30:05) fix */
FAIL("move_left", "unhandled error of chdir");
}
change_dir("..");
}
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_GENERIC | STATUS_UPDATE_SCREEN_DIR_CHANGE);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void move_right(){
skip_if_empty_dir
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
if (chdir(mid_dir.current_file->file_name) != 0) {
/* TODO(2026-05-05T20:12:14) fix */
FAIL("move_right", "unhandled error of chdir");
}
change_dir(mid_dir.current_file->file_name);
} 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 {
char *mime = get_mimetype(mid_dir.current_file);
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)) {
if (*extension == '.') {
break;
@@ -216,12 +215,22 @@ void move_right(){
extension++;
}
long i;
unsigned long i;
if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
for (i = 0; i < file_extension_default_count; i++) {
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
if (system(cmd)) {
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);
if (system(cmd)) {
}
}
status |= STATUS_MOVE_RIGHT_MATCH;
update();
@@ -231,10 +240,21 @@ void move_right(){
}
if (!(status & STATUS_MOVE_RIGHT_MATCH)) {
for (i = 0; i < mimetype_default_count; i++) {
if (strstr(mimetype_default_cmd[i].mimetype, mime) == 0) {
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
if (system(cmd)) {
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);
if (system(cmd)) {
}
}
status |= STATUS_MOVE_RIGHT_MATCH;
update();
break;
}
@@ -244,82 +264,457 @@ void move_right(){
free(cmd);
free(mime);
}
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_GENERIC | STATUS_UPDATE_SCREEN_DIR_CHANGE);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void toggle_hidden_files(){
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void toggle_selection(){
TODO;
void toggle_selection(unsigned long passes){
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(){
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_GENERIC);
status |= (STATUS_RUN_BACKEND);
}
void jump_top(){
mid_dir.current_file = mid_dir.file_list;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_GENERIC);
status |= (STATUS_RUN_BACKEND);
}
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(){
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(){
TODO;
void delete(unsigned long passes){
unsigned long i;
unsigned long del_count = 0;
char *cmd;
for (i = 0; i < mid_dir.file_count; i++) {
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
cmd = parse_cmd(del_cmd, &mid_dir.file_list[i]);
system(cmd);
free(cmd);
del_count++;
}
}
if (del_count == 0) {
for (i = 0; i < passes; i++) {
if (&mid_dir.current_file[i] > mid_dir.file_list + mid_dir.file_count) {
break;
}
cmd = parse_cmd(del_cmd, &mid_dir.current_file[i]);
system(cmd);
free(cmd);
}
}
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
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(){
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){
TODO;
}
void not_implemented(unsigned long passes, int index){
(void)passes;
(void)passes; /*remove compiler warning*/
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
TODO;
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 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_CLEAR | STATUS_RELOAD_DIRECTORY );
}
void order_by(unsigned long passes, int index){
(void)passes;
seed = time(NULL);
order_func = key_binding[index].black_magic;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_GENERIC | STATUS_RELOAD_DIRECTORY);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
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){
TODO;
void yank_file_name(){
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);
system(cmd);
free(cmd);
status |= (STATUS_RUN_BACKEND);
}
void yank_file(unsigned long passes, int index){
TODO;
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 paste(){
TODO;
void copy_file(unsigned long passes, int index){
(void)passes;
yank_files.status = key_binding[index].black_magic;
unsigned long i;
unsigned long j = 0;
char *path = malloc(strlen(global_path)+1); /* im at a loss for words, freeing this always segfaults if yank_files.count != 0
if i use global_path directly or getcwd(NULL, 0), it will segfault at the next free on global_path.
what makes this wierder is, regardless of if the yank_files.count != 0 is true or false, both do the same things
so were going to just leak the size of the path */
memcpy(path, global_path, strlen(global_path)+1);
if (yank_files.count != 0) {
for (i = 0; i < yank_files.count; i++) {
free(yank_files.list[i]);
}
free(yank_files.list);
yank_files.count = 0;
}
for (i = 0; i < mid_dir.file_count; i++) {
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
yank_files.count++;
}
}
if (yank_files.count != 0) {
yank_files.list = malloc(yank_files.count * sizeof(char*));
for (i = 0; j < yank_files.count; i++) {
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
char *str = malloc(strlen(path) + 1 + strlen(mid_dir.current_file->file_name)+1);
memcpy(str, path, strlen(path));
memcpy(str+strlen(path)+1, mid_dir.file_list[i].file_name, strlen(mid_dir.file_list[i].file_name)+1);
str[strlen(path)] = '/';
yank_files.list[j] = str;
j++;
}
}
} else {
/*this path is achieved if no file is explicitly selected by the user, thus we assume the user wants the currently hovered file*/
yank_files.list = malloc(1 * sizeof(char*));
char *str = malloc(strlen(path) + 1 + strlen(mid_dir.current_file->file_name)+1);
memcpy(str, path, strlen(path));
memcpy(str+strlen(path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
str[strlen(path)] = '/';
*yank_files.list = str;
yank_files.count = 1;
}
/*free(path);*/
status |= (STATUS_RUN_BACKEND);
}
void paste(unsigned long passes){
unsigned long i;
unsigned long j;
file tmp;
char *cmd;
for (j = 0; j < passes; j++) {
for (i = 0; i < yank_files.count; i++) {
char *file_name = strrchr(yank_files.list[i], '/')+1;
char *dest_file_name = malloc(strlen(file_name)+1);
memcpy(dest_file_name, file_name, strlen(file_name)+1);
tmp.file_name = yank_files.list[i];
while(access(dest_file_name, F_OK) == 0) {
unsigned long len = strlen(dest_file_name);
dest_file_name = realloc(dest_file_name, len+2);
dest_file_name[len] = '_';
dest_file_name[len+1] = 0;
}
if (yank_files.status == COPY_FILE) {
cmd = parse_cmd(copy_cmd, &tmp);
} else if (yank_files.status == CUT_FILE) {
cmd = parse_cmd(cut_cmd, &tmp);
} else {
free(dest_file_name);
continue;
}
tmp.file_name = dest_file_name;
cmd = parse_cmd(cmd, &tmp);
system(cmd);
free(cmd);
free(tmp.file_name);
}
}
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
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;
wmove(win_b, 0, 1);
while(1) {
ch = wgetch(win_b);
if (ch == '\n' || ch == 27 /* esc key */) {
/* unlike the other uses of a read string reimplementation,
* here we do not differentiate between accepting and cancle.
* this is intentional */
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);
}
}
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);
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(){
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(){
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(){
TODO;
char ch;
char err = 0;
char number_buffer[INPUT_BUFFER_SIZE];
char *num = number_buffer;
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 */
wmove(win_b, 0, 1);
while(1) {
ch = wgetch(win_b);
if (ch >= '0' && ch <= '9') {
*num = ch;
num++;
} else if (ch == '\n') {
break;
} else if (ch == 27) { /* esc key */
err = 1;
break;
} else if (ch == 127) { /* backspace */
num--;
if (num < number_buffer) {
num = number_buffer;
}
}
}
*num = 0;
num = number_buffer;
if (err == 0) {
unsigned long parsed_number = 0;
while(*num) {
parsed_number = (parsed_number * 10) + (*num - '0');
num++;
}
mid_dir.current_file = &mid_dir.file_list[parsed_number];
}
noecho();
curs_set(0);
status |= (STATUS_RUN_BACKEND);
}
+3 -2
View File
@@ -26,8 +26,9 @@ void not_implemented(unsigned long passes, int index);
void jump_to_dir(unsigned long passes, int index);
void order_by(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(unsigned long passes, int index);
void yank_file_name();
void yank_file_path();
void copy_file();
void paste();
void search();
void search_next();
+6 -57
View File
@@ -9,7 +9,6 @@
#include "defines.h"
#include "config.h"
#include "threading.h"
#include "window.c"
#include "colors.h"
#include "interactions.h"
@@ -18,10 +17,8 @@ unsigned int terminal_height;
unsigned int terminal_width;
unsigned int temp_heigth = 0; /*used for screen refresh*/
unsigned int temp_width = 0;
unsigned int settings;
unsigned int file_modifiers;
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
char *start_path;
unsigned int file_modifiers = 0;
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_UPDATE_SCREEN_RESIZE | STATUS_RELOAD_DIRECTORY) & ~STATUS_UPDATE_SCREEN_RESIZE;
char *global_path;
time_t seed;
@@ -38,7 +35,6 @@ extern pthread_mutex_t mutex_mid;
extern pthread_mutex_t mutex_rgt;
char *input; /*used in user_interactions*/
char *terminal_width_empty_line; /* used in user_interactions */
void render_pass();
void init();
@@ -65,7 +61,6 @@ int main(){
pthread_t thread_m;
pthread_t thread_r;
terminal_width_empty_line = malloc(terminal_width);
#if SETTINGS_RELOAD_DIR_DELTA != 0
time_t t;
time_t dt;
@@ -78,19 +73,12 @@ int main(){
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
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);
while(!(status & STATUS_QUIT_PROGRAM)){
getmaxyx(stdscr, terminal_height, terminal_width);
user_interactions();
if (status & STATUS_RUN_BACKEND) {
free(global_path);
global_path = getcwd(NULL, 0);
@@ -107,6 +95,7 @@ int main(){
temp_width = terminal_width;
temp_heigth = terminal_height;
}
user_interactions();
render_pass();
#if SETTINGS_RELOAD_DIR_DELTA != 0
@@ -122,7 +111,6 @@ int main(){
ueberzug_close();
#endif
threading_free();
free(start_path);
delwin(win_l);
delwin(win_m);
@@ -141,6 +129,7 @@ void render_pass(){
if (status & STATUS_UPDATE_SCREEN_CLEAR) {
clear();
status &= ~STATUS_UPDATE_SCREEN_CLEAR;
}
if (status & STATUS_UPDATE_SCREEN_RESIZE) {
@@ -158,48 +147,9 @@ void render_pass(){
mvwin(win_b, terminal_height-1, 0);
}
if (status & STATUS_UPDATE_SCREEN_MASK) {
if (pthread_mutex_trylock(&mutex_top) == 0) {
wnoutrefresh(win_t);
pthread_mutex_unlock(&mutex_top);
} else {
mvwaddstr(win_t, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
wnoutrefresh(win_r);
pthread_mutex_unlock(&mutex_rgt);
} else {
mvwaddstr(win_r, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
if (pthread_mutex_lock(&mutex_mid) == 0) {
wnoutrefresh(win_m);
pthread_mutex_unlock(&mutex_mid);
} else {
mvwaddstr(win_m, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
if (pthread_mutex_trylock(&mutex_lft) == 0) {
wnoutrefresh(win_l);
pthread_mutex_unlock(&mutex_lft);
} else {
mvwaddstr(win_l, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
if (pthread_mutex_trylock(&mutex_btm) == 0) {
wnoutrefresh(win_b);
pthread_mutex_unlock(&mutex_btm);
} else {
mvwaddstr(win_b, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
if (pthread_mutex_lock(&mutex_render) == 0) {
doupdate();
status &= ~(STATUS_UPDATE_SCREEN_MASK - STATUS_UPDATE_SCREEN_DIR_CHANGE);
}
if (status & STATUS_UPDATE_SCREEN_DIR_CHANGE) {
status &= ~STATUS_UPDATE_SCREEN_DIR_CHANGE;
status |= STATUS_UPDATE_SCREEN_GENERIC;
pthread_mutex_unlock(&mutex_render);
}
}
/*this function exists for things done at startup (initialization, reading config, etc)*/
@@ -217,7 +167,6 @@ void init() {
/*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 */
memset(input, 0, INPUT_BUFFER_SIZE);
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
if (getuid() == 0) {
status |= STATUS_USER_ROOT;
}
+111 -73
View File
@@ -18,7 +18,7 @@ pthread_mutex_t mutex_btm;
pthread_mutex_t mutex_lft;
pthread_mutex_t mutex_mid;
pthread_mutex_t mutex_rgt;
pthread_mutex_t mutex_selection;
pthread_mutex_t mutex_render;
pthread_cond_t cond_mid;
pthread_cond_t cond_rgt;
pthread_cond_t cond_lft;
@@ -61,17 +61,18 @@ void *thread_mid(){
pthread_mutex_lock(&mutex_mid);
pthread_cond_wait(&cond_mid, &mutex_mid);
unsigned int local_status = status;
if (global_path == NULL) {
mid_dir.current_file = NULL;
mid_dir.file_count = 0;
pthread_mutex_unlock(&mutex_mid);
continue;
}
char *path = malloc(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;
tmp = mid_dir;
@@ -84,34 +85,49 @@ void *thread_mid(){
} else { /* the hovered dir is empty */
mid_dir.current_file = NULL;
mid_dir.file_list = 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;
}
}
if (mid_dir.current_file != NULL) {
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;
}
if (mid_dir.current_file < mid_dir.file_list) {
mid_dir.current_file = mid_dir.file_list;
}
}
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;
}
if (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 */
pthread_mutex_lock(&mutex_render);
werase(win_m);
if (mid_dir.file_count == 0) {
mvwaddstr(win_m, 0, 0, "empty");
} else {
print_dir(win_m, 1, &mid_dir);
}
pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_top);
pthread_cond_signal(&cond_btm);
pthread_mutex_unlock(&mutex_mid);
wnoutrefresh(win_m);
pthread_mutex_unlock(&mutex_render);
btm_status = local_status;
long i;
unsigned long i;
for (i = 0; i < tmp.file_count; i++) {
free(tmp.file_list[i].file_name);
}
@@ -127,7 +143,6 @@ void *thread_lft(){
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_lft);
pthread_cond_wait(&cond_lft, &mutex_lft);
unsigned int local_status = status;
if (global_path == NULL) {
lft_dir.current_file = NULL;
@@ -143,7 +158,7 @@ void *thread_lft(){
path[strrchr(path, '/')-path] = '\0';
path[0] = '/';
if (local_status & STATUS_RELOAD_DIRECTORY) {
if (status & STATUS_RELOAD_DIRECTORY) {
unsigned long i = 0;
for (i = 0; i < lft_dir.file_count; i++) {
free(lft_dir.file_list[i].file_name);
@@ -164,12 +179,15 @@ void *thread_lft(){
}
/* rendering */
pthread_mutex_lock(&mutex_render);
werase(win_l);
print_dir(win_l, 0, &lft_dir);
wnoutrefresh(win_l);
pthread_mutex_unlock(&mutex_render);
pthread_mutex_unlock(&mutex_lft);
free(path);
pthread_mutex_unlock(&mutex_lft);
}
pthread_exit(0);
@@ -189,19 +207,27 @@ void *thread_rgt(){
pthread_mutex_lock(&mutex_mid);
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
if (mid_dir.current_file != NULL) {
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
rgt_dir.file_list = malloc(sizeof(file));
memcpy(rgt_dir.file_list, mid_dir.current_file, sizeof(file));
rgt_dir.file_list->file_name = file_name;
rgt_dir.current_file = rgt_dir.file_list;
rgt_dir.file_count = 1;
rgt_dir.file_list = malloc(sizeof(file));
memcpy(rgt_dir.file_list, mid_dir.current_file, sizeof(file));
rgt_dir.file_list->file_name = file_name;
rgt_dir.current_file = rgt_dir.file_list;
rgt_dir.file_count = 1;
} else {
rgt_dir.current_file = NULL;
rgt_dir.file_list = NULL;
rgt_dir.file_count = 0;
}
pthread_mutex_unlock(&mutex_mid);
if (rgt_dir.current_file->permissions & S_IRUSR) {
if (rgt_dir.current_file->file_type &= FILE_TYPE_DIR) {
if (rgt_dir.current_file != NULL && rgt_dir.current_file->permissions & S_IRUSR) {
if (rgt_dir.current_file->file_type & FILE_TYPE_DIR) {
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
images_clear();
#endif
@@ -215,34 +241,32 @@ void *thread_rgt(){
} else { /* the hovered dir is empty */
rgt_dir.current_file = NULL;
}
pthread_mutex_lock(&mutex_render);
werase(win_r);
print_dir(win_r, 0, &rgt_dir);
wnoutrefresh(win_r);
pthread_mutex_unlock(&mutex_render);
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && mid_dir.file_count > 0) {
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && rgt_dir.file_count > 0) {
free(rgt_buffer);
rgt_buffer = preview_file(rgt_dir.current_file);
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);
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
mvwaddstr(win_r, 0, 0, "not accessible");
}
wnoutrefresh(win_r);
pthread_mutex_unlock(&mutex_render);
}
}
/* rendering */
werase(win_r);
if (!rgt_dir.current_file) {
mvwaddstr(win_r, 0, 0, "not accessible");
}else if (rgt_dir.current_file->file_type == FILE_TYPE_OPEN_FILE) {
mvwaddnstr(win_r, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
mvwaddstr(win_r, 0, 0, "not accessible");
} else {
print_dir(win_r, 0, &rgt_dir);
}
pthread_mutex_unlock(&mutex_rgt);
long i;
unsigned long i;
for (i = 0; i < tmp.file_count; i++) {
free(tmp.file_list[i].file_name);
}
@@ -260,6 +284,7 @@ void *thread_top(){
pthread_mutex_lock(&mutex_top);
pthread_cond_wait(&cond_top, &mutex_top);
free(top_buffer);
if(global_path == NULL) {
@@ -269,22 +294,32 @@ void *thread_top(){
pthread_mutex_unlock(&mutex_top);
continue;
}
top_buffer = malloc(strlen(global_path)+1);
memcpy(top_buffer, global_path, strlen(global_path)+1);
top_width = strlen(top_buffer);
pthread_mutex_lock(&mutex_mid);
if (mid_dir.current_file != NULL) {
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);
top_buffer[strlen(global_path)] = '/';
top_width = strlen(top_buffer);
} else {
top_buffer = malloc(strlen(global_path)+1);
memcpy(top_buffer, global_path, strlen(global_path)+1);
}
pthread_mutex_unlock(&mutex_mid);
/* rendering */
pthread_mutex_lock(&mutex_render);
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));
mvwaddstr(win_t, 0, 0, top_buffer);
mvwaddch(win_t, 0, strlen(top_buffer), '/');
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
if (mid_dir.file_count != 0 && !(mid_dir.current_file == NULL)) {
mvwaddstr(win_t, 0, strlen(top_buffer)+1, mid_dir.current_file->file_name);
}
}
wattron(win_t, COLOR_PAIR(COLOR_PATH));
mvwaddnstr(win_t, 0, 0, top_buffer, strlen(global_path)+1);
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
mvwaddstr(win_t, 0, strlen(global_path)+1, top_buffer+strlen(global_path)+1);
wnoutrefresh(win_t);
pthread_mutex_unlock(&mutex_render);
pthread_mutex_unlock(&mutex_top);
@@ -300,10 +335,9 @@ void *thread_btm(){
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_btm);
pthread_cond_wait(&cond_btm, &mutex_btm);
unsigned int local_status = btm_status;
if (local_status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
if (status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
/*{{{ parse storage info; the fold of shame*/
pthread_mutex_lock(&mutex_mid);
unsigned long i;
@@ -384,27 +418,31 @@ void *thread_btm(){
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
(S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[2] = (mid_dir.current_file->permissions & S_IWUSR) ? 'w' : '-';
btm_buffer[3] = (mid_dir.current_file->permissions & S_IXUSR) ? 'x' : '-';
btm_buffer[4] = (mid_dir.current_file->permissions & S_IRGRP) ? 'r' : '-';
btm_buffer[5] = (mid_dir.current_file->permissions & S_IWGRP) ? 'w' : '-';
btm_buffer[6] = (mid_dir.current_file->permissions & S_IXGRP) ? 'x' : '-';
btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
btm_buffer[8] = (mid_dir.current_file->permissions & S_IWOTH) ? 'w' : '-';
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
if (mid_dir.current_file != NULL) {
btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
(S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[2] = (mid_dir.current_file->permissions & S_IWUSR) ? 'w' : '-';
btm_buffer[3] = (mid_dir.current_file->permissions & S_IXUSR) ? 'x' : '-';
btm_buffer[4] = (mid_dir.current_file->permissions & S_IRGRP) ? 'r' : '-';
btm_buffer[5] = (mid_dir.current_file->permissions & S_IWGRP) ? 'w' : '-';
btm_buffer[6] = (mid_dir.current_file->permissions & S_IXGRP) ? 'x' : '-';
btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
btm_buffer[8] = (mid_dir.current_file->permissions & S_IWOTH) ? 'w' : '-';
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
}
/* rendering */
pthread_mutex_lock(&mutex_render);
werase(win_b);
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
mvwprintw(win_b, 0, 0, "%s", btm_buffer);
}
wnoutrefresh(win_b);
pthread_mutex_unlock(&mutex_render);
pthread_mutex_unlock(&mutex_btm);
/*the printing of the input char is done in user_interactions*/
/*the printing of all possible inputs are done in user_interactions */
@@ -428,7 +466,7 @@ void threading_init(){
pthread_mutex_init(&mutex_lft, NULL);
pthread_mutex_init(&mutex_btm, 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_lft, NULL);
pthread_cond_init(&cond_mid, NULL);
-108
View File
@@ -1,108 +0,0 @@
#include <curses.h>
#include <pthread.h>
#include <unistd.h>
#include "defines.h"
#include "dir.h"
extern unsigned int terminal_height;
extern unsigned int terminal_width;
extern unsigned int status;
extern char *input;
extern unsigned int timeout_time;
extern unsigned int color_count;
extern color *colors;
extern dir rgt_dir;
extern dir mid_dir;
extern dir lft_dir;
extern char *top_buffer;
extern char *rgt_buffer;
extern char *btm_buffer;
extern unsigned long top_width;
extern pthread_mutex_t mutex_top;
extern pthread_mutex_t mutex_btm;
extern pthread_mutex_t mutex_lft;
extern pthread_mutex_t mutex_mid;
extern pthread_mutex_t mutex_rgt;
void window_top(WINDOW *win){
if (pthread_mutex_trylock(&mutex_top) == 0) {
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
wattron(win, COLOR_PAIR(COLOR_PATH));
mvwaddstr(win, 0, 0, top_buffer);
mvwaddch(win, 0, strlen(top_buffer), '/');
wattroff(win, COLOR_PAIR(COLOR_PATH));
if (mid_dir.file_count != 0) {
mvwaddstr(win, 0, strlen(top_buffer)+1, mid_dir.current_file->file_name);
}
}
pthread_mutex_unlock(&mutex_top);
} else {
mvwaddstr(win, 0, terminal_width/2, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
}
void window_btm(WINDOW *win){
if (pthread_mutex_trylock(&mutex_btm) == 0) {
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
mvwprintw(win, 0, 0, "%s", btm_buffer);
}
pthread_mutex_unlock(&mutex_btm);
/*the printing of the input char is done in user_interactions*/
/*the printing of all possible inputs are done in user_interactions */
} else {
mvwaddstr(win, 0, terminal_width/2, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
}
void window_lft(WINDOW *win){
if (pthread_mutex_trylock(&mutex_lft) == 0) {
print_dir(win, 0, &lft_dir);
pthread_mutex_unlock(&mutex_lft);
} else {
mvwaddstr(win, terminal_height/2, terminal_width/8, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
}
void window_mid(WINDOW *win){
if (pthread_mutex_trylock(&mutex_mid) == 0) {
if (mid_dir.file_count == 0) {
mvwaddstr(win, 0, 0, "empty");
} else {
print_dir(win, 1, &mid_dir);
}
pthread_mutex_unlock(&mutex_mid);
} else {
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
}
void window_rgt(WINDOW *win){
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
if (!rgt_dir.current_file) {
mvwaddstr(win, 0, 0, "not accessible");
}else if (rgt_dir.current_file->file_type == FILE_TYPE_OPEN_FILE) {
mvwaddnstr(win, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
mvwaddstr(win, 0, 0, "not accessible");
} else {
print_dir(win, 0, &rgt_dir);
}
pthread_mutex_unlock(&mutex_rgt);
} else {
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_GENERIC;
}
}
-7
View File
@@ -1,7 +0,0 @@
#include "window.c"
void window_top(WINDOW *win);
void window_btm(WINDOW *win);
void window_lft(WINDOW *win);
void window_mid(WINDOW *win);
void window_rgt(WINDOW *win);