Compare commits

..

76 Commits

Author SHA1 Message Date
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
nova
673c7e5414 bounds checking and changes to the pthread signals 2026-05-10 19:45:55 +02:00
nova
93c70aa07a adjustments as a result of asynic rendering 2026-05-10 19:45:04 +02:00
nova
edcf093269 improved main loop sequence for the async rendering 2026-05-10 19:44:17 +02:00
nova
557e0eb416 small change 2026-05-10 19:13:16 +02:00
nova
3c0f26efee attempted multithreadded rendering 2026-05-10 19:12:39 +02:00
nova
491c00b9d4 improvements to the threading 2026-05-10 18:28:54 +02:00
nova
955d8f439b reimplementations of some functions 2026-05-08 22:02:51 +02:00
nova
d9d1ed115d improvements to the rendering 2026-05-06 22:27:24 +02:00
nova
41293c6afd improvements to the rendering 2026-05-06 22:21:33 +02:00
nova
1a85a2d810 fix of out of bounds memory access in 2 places 2026-05-05 20:07:56 +02:00
nova
e5625ada08 start of a major rewrite 2026-05-05 19:41:45 +02:00
nova
b639ad3998 chonfig adjustment 2026-05-01 22:18:08 +02:00
nova
1711926003 string escaping 2026-05-01 22:17:33 +02:00
nova
6372dbba69 improvements to sort_random 2026-04-04 21:58:43 +02:00
nova
acb7db1617 bg no longer as string, now also only on hovered 2026-03-28 15:32:53 +01:00
nova
da4c90d243 no longer mallocs new strings on dir print 2026-03-27 22:01:26 +01:00
nova
ac50d377ca avif and blender 2026-03-16 21:21:07 +01:00
nova
a64982857a better flags 2026-03-16 21:19:11 +01:00
nova
3d47e0410f check if dir is empty 2026-02-08 18:49:55 +01:00
nova
f53fd66d88 added printing of mid_content[selected_file_current].file_name in top ui 2026-02-04 22:20:00 +01:00
nova
7e4ae9bb84 remove now useless memcopy 2026-02-04 22:17:52 +01:00
nova
36c8524a70 removed unused stdlib.h 2026-02-04 21:56:56 +01:00
nova
99ac76162f no longer try to file preview in a directory without files 2026-02-04 21:56:28 +01:00
nova
1d3b71b00f fix incorrect offset on files with long extensions 2026-02-04 21:55:03 +01:00
nova
84b1c17dd8 unzip jis 2026-02-02 23:24:41 +01:00
nova
1f1de78283 -fsanitize=address related stuff 2026-01-17 18:10:01 +01:00
nova
f3a39b0df0 small changes 2026-01-17 17:53:52 +01:00
nova
8734fa6ae4 -fsanitize=address related compiler assisted debugging 2026-01-12 18:35:38 +01:00
nova
66f3f3bef6 small changes 2026-01-05 22:15:11 +01:00
nova
393864c80f better string handling 2025-12-12 20:28:39 +01:00
nova
217884d920 multiple small changes 2025-12-07 14:36:33 +01:00
nova
3a891388ed ncursesw 2025-11-16 12:09:40 +01:00
nova
0bdb4a1a0a moving ui text into config.h 2025-11-16 12:02:04 +01:00
nova
ddcf4d4105 migration of concat to macro based implementation 2025-11-16 11:34:11 +01:00
nova
be9436570c removal of unnecessary null check, during testing it was never null 2025-11-15 22:31:19 +01:00
nova
74166f7283 indentation change, now using continue 2025-11-15 22:28:08 +01:00
nova
9a67b35ebe handling of '/' in thread_lft 2025-11-15 22:21:30 +01:00
nova
1e99e9d364 global_path handling 2025-11-15 22:08:20 +01:00
nova
dd7f5634e2 very simplistic 'handling' of split/non split ncurses 2025-11-15 22:01:33 +01:00
nova
5287c77648 varrious small changes 2025-11-09 17:40:56 +01:00
nova
5b7f017588 jump to /usr added 2025-11-04 22:16:51 +01:00
nova
33d7761329 some fixes to copy pasting 2025-11-04 22:16:21 +01:00
18 changed files with 1111 additions and 1237 deletions

View File

@@ -1,8 +1,7 @@
CC := gcc CC := gcc
CFLAGS := -Wall -Wextra -O2 -flto=auto CFLAGS := -Wall -Wextra -O3 -flto=auto
CURSES := -lncursesw -ltinfow #utf8 support CURSES := $(shell pkg-config --libs ncursesw)
#CURSES := -lncurses -tinfo #no utf8 CFLAGS_DEBUG := $(CFLAGS) -ggdb
CFLAGS_DEBUG := $(CFLAGS) -g
CFLAGS_PROFILE := $(CFLAGS) -pg CFLAGS_PROFILE := $(CFLAGS) -pg
GDB := gdb --tui ./th GDB := gdb --tui ./th
VALGRIND := valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --log-fd=9 9>>valgrind.log ./th VALGRIND := valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --log-fd=9 9>>valgrind.log ./th

130
backend.c
View File

@@ -1,14 +1,42 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "config.h"
char* concat(const char *s1, const char *s2){ #define concat(out, s1, s2, _free) { \
const size_t len1 = strlen(s1); concat## _free(out, s1, s2); \
const size_t len2 = strlen(s2);
char *result = malloc(len1 + len2 + 1);
memcpy(result, s1, len1);
memcpy(result + len1, s2, len2 + 1);
return result;
} }
#define concat0(out, s1, s2) \
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
memcpy(result, s1, strlen(s1)); \
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
out = result;
#define concat1(out, s1, s2) \
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
memcpy(result, s1, strlen(s1)); \
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
free(s1); \
out = result;
#define concat2(out, s1, s2) \
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
memcpy(result, s1, strlen(s1)); \
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
free(s2); \
out = result;
#define concat3(out, s1, s2) \
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
memcpy(result, s1, strlen(s1)); \
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
free(s1); \
free(s2); \
out = result;
char* smartstrcasestr(const char *haystack, const char *needle){ char* smartstrcasestr(const char *haystack, const char *needle){
char smart = 0; char smart = 0;
char *ret; char *ret;
@@ -52,3 +80,91 @@ char* smartstrcasestr(const char *haystack, const char *needle){
return ret; return ret;
} }
char* parse_cmd(const char *cmd, file *f){
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]) {
if (f->file_name[i] == '\'') {
count++;
}
i++;
}
out = malloc(strlen(cmd) + 1 + (strlen(f->file_name)+(count*3)) + 3);
pos = out;
if (offset) {
memcpy(pos, cmd, offset - cmd);
pos += offset - cmd;
} else {
memcpy(pos, cmd, strlen(cmd));
pos += strlen(cmd) + 1;
pos[-1] = ' ';
}
*pos = '\'';
pos++;
i = 0;
while(f->file_name[i]) {
if (f->file_name[i] == '\'') {
*pos++ = '\'';
*pos++ = '\\';
*pos++ = '\'';
}
*pos = f->file_name[i];
pos++;
i++;
}
*pos = '\'';
if (offset) {
pos[1]= ' ';
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;
}

View File

@@ -5,5 +5,7 @@
#endif #endif
char* concat(const char *s1, const char *s2); /*char* concat(const char *s1, const char *s2);*/
char* smartstrcasestr(const char *haystack, const char *needle); char* smartstrcasestr(const char *haystack, const char *needle);
char* parse_cmd(const char *cmd, file *f);

View File

@@ -9,9 +9,6 @@
unsigned int color_count; unsigned int color_count;
color *colors; color *colors;
extern file *rgt_content;
extern unsigned long rgt_file_count;
extern unsigned int settings; extern unsigned int settings;
extern unsigned int status; extern unsigned int status;
@@ -105,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);

View File

@@ -1,6 +1,10 @@
#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */ #define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching */ #define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching; depends on ueberzug */
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds of how often the directory should be reload */ #define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds between automatic refresh of dir contents */
#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 #ifndef CONFIG_GUARD
@@ -10,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"
@@ -19,24 +28,26 @@ 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" },
{ "gif", "mpv --loop-file=\"inf\"" }, { "avif", "@ mpv" },
{ "image", "feh" }, { "gif", "@ mpv --loop-file=\"inf\"" },
{ "video", "mpv" }, { "image", "@ feh" },
{ "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 */
}; };
static const binding key_binding[] = { static const binding key_binding[] = {
/*key action blackmagic comment*/ /*key action blackmagic comment*/
/*you cannot add bindings that include other bindings in its entirety /*you cannot add bindings that include other bindings in its entirety
* possible: mk, mf * possible: mk, mf
* not possible: gg, ggg * not possible: gg, ggg
@@ -57,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" },
@@ -82,6 +93,7 @@ static const binding key_binding[] = {
{ "go", jump_to_dir, "/opt", "jump to /opt" }, { "go", jump_to_dir, "/opt", "jump to /opt" },
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" }, { "gt", jump_to_dir, "/tmp", "jump to /tmp" },
{ "gv", jump_to_dir, "/var", "jump to /var" }, { "gv", jump_to_dir, "/var", "jump to /var" },
{ "gu", jump_to_dir, "/usr", "jump to /usr" },
{ "u7", cmd_on_selected, "7z x", "unzip 7z" }, { "u7", cmd_on_selected, "7z x", "unzip 7z" },
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" }, { "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
@@ -89,6 +101,7 @@ static const binding key_binding[] = {
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" }, { "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" }, { "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
{ "uz", cmd_on_selected, "unzip ", "unzip zip" }, { "uz", cmd_on_selected, "unzip ", "unzip zip" },
{ "uj", cmd_on_selected, "unzip -O shift-jis", "unzip zip shift-jis" },
{ "on", order_by, sort_natural, "order natural" }, { "on", order_by, sort_natural, "order natural" },
{ "oe", order_by, sort_extension, "order extension" }, { "oe", order_by, sort_extension, "order extension" },
@@ -106,9 +119,13 @@ 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[] = "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:";
/* {{{ */ /* {{{ */
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding); static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
@@ -117,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[];
@@ -125,5 +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[];
static const char ui_makedir_text[];
static const char ui_makefile_text[];
static const char ui_rename_text[];
static const char ui_delete_text[];
#endif #endif
/* }}} */ /* }}} */

View File

@@ -3,16 +3,23 @@
#define STATUS_QUIT_PROGRAM 1 #define STATUS_QUIT_PROGRAM 1
#define STATUS_RUN_BACKEND 2 #define STATUS_RUN_BACKEND 2
#define STATUS_RELOAD_DIRECTORY 4 #define STATUS_RELOAD_DIRECTORY 4
#define STATUS_UPDATE_SCREEN_MASK 24 /* 11000 */ #define STATUS_UPDATE_ASYNC_REFRESH 8
#define STATUS_UPDATE_SCREEN_0 8
#define STATUS_UPDATE_SCREEN_RESIZE 16 #define STATUS_UPDATE_SCREEN_RESIZE 16
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32 #define STATUS_UPDATE_SCREEN_CLEAR 32
#define STATUS_USER_ROOT 64 #define STATUS_UPDATE_SCREEN_MASK (STATUS_UPDATE_ASYNC_REFRESH | STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)
#define STATUS_INPUT_MATCH 128 #define STATUS_USER_ROOT 128
#define STATUS_DELTA_TIME 256 #define STATUS_INPUT_MATCH 256
#define STATUS_DELTA_TIME 512
#define STATUS_MOVE_RIGHT_MATCH 1024
#define SETTINGS_HAS_COLOR 1 #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_HIDDEN_FILES 1
#define FILE_MODIFIERS_SORT_BITMASK 126 /* 00000000000000000000000001111110*/ #define FILE_MODIFIERS_SORT_BITMASK 126 /* 00000000000000000000000001111110*/
#define FILE_MODIFIERS_SORT_ALPHABETIC 2 #define FILE_MODIFIERS_SORT_ALPHABETIC 2
@@ -70,6 +77,11 @@ typedef struct File {
unsigned long file_size; /*if its a file, its in bytes, if its a dir, its the count of files within that dir */ unsigned long file_size; /*if its a file, its in bytes, if its a dir, its the count of files within that dir */
char *file_name; char *file_name;
} file; } file;
typedef struct Dir {
file *current_file;
file *file_list;
unsigned long file_count;
} dir;
typedef struct Color { typedef struct Color {
char *file_extension; char *file_extension;
short color_pair; short color_pair;
@@ -96,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;

332
dir.c
View File

@@ -12,48 +12,43 @@
#include "config.h" #include "config.h"
extern file *mid_content; extern dir mid_dir;
extern unsigned long mid_file_count;
extern unsigned int settings; 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);
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
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) {
while ((entry=readdir(dir))) { if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
entry_count++; while ((entry=readdir(dir))) {
}
/* removes files "." and ".." */
entry_count -= 2;
} else if (dir) {
while ((entry=readdir(dir))) {
if (entry->d_name[0] != '.') {
entry_count++; 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; return entry_count;
} }
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){ void get_dir_content(char *path, dir *dir){
struct dirent **entry = NULL; struct dirent **entry = NULL;
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */ if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
scandir(path, &entry, skip_dot, NULL); scandir(path, &entry, skip_dot, NULL);
@@ -61,77 +56,81 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
scandir(path, &entry, skip_hidden_files, NULL); scandir(path, &entry, skip_hidden_files, 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++ ) {
dir->file_list[i].file_name = NULL;
if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) { if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
} else { } else {
dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1); dir->file_list[i].file_name = malloc(strlen(entry[i]->d_name)+1);
memcpy(dir_content[i].file_name, entry[i]->d_name, strlen(entry[i]->d_name) + 1); memcpy(dir->file_list[i].file_name, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
dir->file_list[i].status = 0;
struct stat *file; struct stat *file;
file = malloc(sizeof(struct stat)); file = malloc(sizeof(struct stat));
/* using the full path allows using the same function for all windows */ /* using the full path allows using the same function for all windows */
char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/")); full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/"));
memcpy(full_path, path, strlen(path)); memcpy(full_path, path, strlen(path));
memcpy(full_path + strlen(path) + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1); memcpy(full_path + strlen(path) + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
full_path[strlen(path)] = '/'; full_path[strlen(path)] = '/';
lstat(full_path, file); lstat(full_path, file);
dir_content[i].file_size = file->st_size; dir->file_list[i].file_size = file->st_size;
dir_content[i].permissions = file->st_mode; dir->file_list[i].permissions = file->st_mode;
if (S_ISDIR(file->st_mode)) { if (S_ISLNK(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_DIR;
dir_content[i].color_pair = COLOR_DIR;
dir_content[i].file_size = get_dir_size(full_path);
} else if (S_ISLNK(file->st_mode)) {
stat(full_path, file); stat(full_path, file);
if (S_ISDIR(file->st_mode)) { if (S_ISDIR(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK; dir->file_list[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
dir_content[i].color_pair = COLOR_SYMLINK; dir->file_list[i].color_pair = COLOR_SYMLINK;
dir_content[i].file_size = get_dir_size(full_path); dir->file_list[i].file_size = get_dir_size(full_path);
} else { } else {
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK; dir->file_list[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
dir_content[i].color_pair = COLOR_SYMLINK; dir->file_list[i].color_pair = COLOR_SYMLINK;
} }
} else if (S_ISDIR(file->st_mode)) {
dir->file_list[i].file_type = FILE_TYPE_DIR;
dir->file_list[i].color_pair = COLOR_DIR;
dir->file_list[i].file_size = get_dir_size(full_path);
} else if (file->st_mode & S_IXUSR) { } else if (file->st_mode & S_IXUSR) {
dir_content[i].file_type = FILE_TYPE_EXEC; dir->file_list[i].file_type = FILE_TYPE_EXEC;
dir_content[i].color_pair = COLOR_EXEC; dir->file_list[i].color_pair = COLOR_EXEC;
} else if (S_ISREG(file->st_mode)) { } else if (S_ISREG(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_REGULAR; dir->file_list[i].file_type = FILE_TYPE_REGULAR;
dir_content[i].color_pair = COLOR_REGULAR; dir->file_list[i].color_pair = COLOR_REGULAR;
unsigned long j = 0; unsigned long j = 0;
char *extension = strrchr(entry[i]->d_name, '.'); char *extension = strrchr(entry[i]->d_name, '.');
if (extension) { if (extension) {
for (j = 0; j < color_count; j++) { for (j = 0; j < color_count; j++) {
if (!strcmp(colors[j].file_extension, extension)) { if (!strcmp(colors[j].file_extension, extension)) {
dir_content[i].color_pair = colors[j].color_pair; dir->file_list[i].color_pair = colors[j].color_pair;
} }
} }
} }
} else if (S_ISBLK(file->st_mode)) { } else if (S_ISBLK(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_BLOCK; dir->file_list[i].file_type = FILE_TYPE_BLOCK;
dir_content[i].color_pair = COLOR_BLOCK; dir->file_list[i].color_pair = COLOR_BLOCK;
} else if (S_ISCHR(file->st_mode)) { } else if (S_ISCHR(file->st_mode)) {
dir_content[i].file_type = COLOR_CHARDEV; dir->file_list[i].file_type = COLOR_CHARDEV;
} else if (S_ISFIFO(file->st_mode)) { } else if (S_ISFIFO(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_FIFO; dir->file_list[i].file_type = FILE_TYPE_FIFO;
dir_content[i].color_pair = COLOR_FIFO; dir->file_list[i].color_pair = COLOR_FIFO;
} else if (S_ISSOCK(file->st_mode)) { } else if (S_ISSOCK(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_SOCK; dir->file_list[i].file_type = FILE_TYPE_SOCK;
dir_content[i].color_pair = COLOR_SOCK; dir->file_list[i].color_pair = COLOR_SOCK;
} else { } else {
dir_content[i].file_type = COLOR_REGULAR; dir->file_list[i].file_type = COLOR_REGULAR;
dir_content[i].color_pair = COLOR_REGULAR; dir->file_list[i].color_pair = COLOR_REGULAR;
unsigned long j = 0; unsigned long j = 0;
char *extension = strrchr(entry[i]->d_name, '.'); char *extension = strrchr(entry[i]->d_name, '.');
if (extension) { if (extension) {
for (j = 0; j < color_count; j++) { for (j = 0; j < color_count; j++) {
if (!strcmp(colors[j].file_extension, extension)) { if (!strcmp(colors[j].file_extension, extension)) {
dir_content[i].color_pair = colors[j].color_pair; dir->file_list[i].color_pair = colors[j].color_pair;
} }
} }
} else { } else {
@@ -139,29 +138,20 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
} }
free(full_path); free(full_path);
free(file); free(file);
free(entry[i]);
} }
} }
qsort(dir_content, *dir_file_count, sizeof(file), order_func); qsort(dir->file_list, dir->file_count, sizeof(file), order_func);
for (i = 0; i < *dir_file_count; i++) { free(entry);
free(entry[i]);
}
if (entry != NULL) {
free(entry);
} else {
}
} }
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content){ void print_dir(WINDOW *win, char print_info, dir *dir){
/* i am not proud of this function */ /* i am not proud of this function */
unsigned long line_width = getmaxx(win); unsigned long line_width = getmaxx(win);
char *bg = malloc(line_width+1);
memset(bg, ' ', line_width);
bg[line_width] = '\0';
unsigned long i = 0; unsigned long i = 0;
float file_size; float file_size;
float printed_size = 0; float printed_size = 0;
@@ -175,22 +165,23 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
#else #else
long offset_front = 2; long offset_front = 2;
#endif #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 */ long offset_index = 2; /* only used for the index of the file itself */
if (print_info) { if (print_info) {
if (*dir_file_count > 9) { if (dir->file_count > 9) {
#if SETTINGS_LINE_NUMBERS != 0 #if SETTINGS_LINE_NUMBERS != 0
unsigned long dir_file_count_ = *dir_file_count; unsigned long dir_file_count_ = dir->file_count;
while(dir_file_count_ > 9) { while(dir_file_count_ > 9) {
offset_front++; offset_front++;
dir_file_count_ /= 10; dir_file_count_ /= 10;
} }
#endif #endif
} }
if (selected_file_current > (terminal_height/3)*2 && *dir_file_count > terminal_height - 2) { if (selected_file_current > (terminal_height/3)*2 && dir->file_count > terminal_height - 2) {
if (selected_file_current + (terminal_height/3) >= *dir_file_count) { if (selected_file_current + (terminal_height/3) >= dir->file_count) {
offset_vertical = *dir_file_count - terminal_height+2; offset_vertical = dir->file_count - terminal_height+2;
} else { } else {
offset_vertical = selected_file_current - (terminal_height/3)*2; offset_vertical = selected_file_current - (terminal_height/3)*2;
} }
@@ -198,12 +189,12 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
} else { } else {
offset_front = 0; offset_front = 0;
} }
for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) { for (i = offset_vertical; i < dir->file_count && i < (terminal_height + offset_vertical); i++) {
if (print_info) { if (print_info) {
file_size = dir_content[i].file_size; file_size = dir->file_list[i].file_size;
char size_index = -1; char size_index = -1;
do { do {
@@ -213,8 +204,8 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
} 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_content[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_content[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);
} else { } else {
@@ -224,54 +215,29 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
offset_back = line_width; offset_back = line_width;
} }
if (dir_content[i].status & FILE_STATUS_SELECTED) { if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
is_selected = 1; is_selected = 1;
} else { } else {
is_selected = 0; is_selected = 0;
} }
if (dir_content[i].status & FILE_STATUS_SELECTED) { if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
wattron(win, COLOR_PAIR(8)); wattron(win, COLOR_PAIR(8));
} else { } else {
wattron(win, COLOR_PAIR(dir_content[i].color_pair)); wattron(win, COLOR_PAIR(dir->file_list[i].color_pair));
} }
if (dir_content[i].status & FILE_STATUS_HOVER) { if (&dir->file_list[i] == dir->current_file) {
wattron(win, A_REVERSE); wattron(win, A_REVERSE);
unsigned long bg = 0;
for (bg = 0; bg < line_width; bg++) {
mvwaddch(win, i-offset_vertical, bg, ' ');
}
} else { } else {
wattroff(win, A_REVERSE); wattroff(win, A_REVERSE);
} }
/* shortens the printed file name if it is too long
* example input: aaaaaaaa.txt
* example output: aaa~.txt
* if no extension is found, the name will truncate */
char *file_name = NULL;
unsigned long printable_size = (offset_back - is_selected - offset_front);
if (strlen(dir_content[i].file_name) > printable_size) {
char *extension = strrchr(dir_content[i].file_name, '.');
if (extension && extension != dir_content[i].file_name) {
file_name = malloc(printable_size);
printable_size -= strlen(extension);
memcpy(file_name, dir_content[i].file_name, printable_size);
memcpy(file_name + printable_size-1, extension, strlen(extension));
file_name[printable_size + strlen(extension)-1] = '\0';
file_name[printable_size - 2] = '~';
} else {
file_name = malloc(printable_size-1);
memcpy(file_name, dir_content[i].file_name, printable_size);
file_name[printable_size-2] = '~';
file_name[printable_size-1] = '\0';
}
} else {
file_name = malloc(strlen(dir_content[i].file_name)+1);
memcpy(file_name, dir_content[i].file_name, strlen(dir_content[i].file_name)+1);
}
mvwaddstr(win, i-offset_vertical, 0, bg);
if(print_info) { if(print_info) {
#if SETTINGS_LINE_NUMBERS == 2 #if SETTINGS_LINE_NUMBERS == 2
long i_ = (selected_file_current) - i; long i_ = (selected_file_current) - i;
@@ -303,96 +269,117 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
mvwprintw(win, i-offset_vertical, offset_front-offset_index, "%ld", i); mvwprintw(win, i-offset_vertical, offset_front-offset_index, "%ld", i);
#endif #endif
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
if (dir_content[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_content[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);
} else { } else {
mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char); mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char);
} }
} else {
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
} }
if (file_name != NULL) { char *extension = strrchr(dir->file_list[i].file_name, '.');
/* sometimes NULL remains, need to do deeper analysis soon */
free(file_name); unsigned long printable_size = offset_back-offset_front-is_selected-2;
} else {
printf("file_name remains NULL on %s, if this happens consistent on the same file, please inform me", dir_content[i].file_name); mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, dir->file_list[i].file_name, printable_size);
volatile static int debug_print_dir; if (extension && printable_size <= strlen(dir->file_list[i].file_name)) {
debug_print_dir++; mvwaddnstr(win, i-offset_vertical, offset_back-strlen(extension)-1, extension, strlen(extension));
mvwaddnstr(win, i-offset_vertical, offset_back-strlen(extension)-2, "~", 1);
} }
if (dir_content[i].status & FILE_STATUS_SELECTED) {
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
wattroff(win, COLOR_PAIR(8)); wattroff(win, COLOR_PAIR(8));
} else { } else {
wattroff(win, COLOR_PAIR(dir_content[i].color_pair)); wattroff(win, COLOR_PAIR(dir->file_list[i].color_pair));
} }
} }
free(bg);
} }
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 (mid_content->file_name[0] == '\0') { /* only happens if the current path is either empty or inaccessible */
return ret;
}
if (selected_file_current >= mid_file_count) {
selected_file_current = mid_file_count-1;
}
if (selected_file_current != selected_file_last) {
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
ret = 1;
} else {
ret = 0;
}
mid_content[selected_file_current].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[0] != '\0') {
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;
} else {
current_linked_dir = current_linked_dir->next;
} }
current_dir = current_dir->next;
} }
if (hit == 0) { if(strcmp(current_linked_dir->path, path) == 0) {
current_dir->next = malloc(sizeof(linked_dir)); mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
current_dir->next->next = NULL;
current_dir->next->path = path;
return 0;
} else { } 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){
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;
} }
void recursive_delete(file current_file){ void recursive_delete(file current_file){
if (current_file.file_type & FILE_TYPE_DIR) { /*
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; unsigned int file_modifiers_tmp = file_modifiers;
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES; file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
unsigned long current_file_count = get_dir_size(current_file.file_name); unsigned long current_file_count = get_dir_size(current_file.file_name);
@@ -419,4 +406,5 @@ void recursive_delete(file current_file){
} else { } else {
remove(current_file.file_name); remove(current_file.file_name);
} }
*/
} }

4
dir.h
View File

@@ -4,8 +4,8 @@
#endif #endif
unsigned long get_dir_size(char *path); unsigned long get_dir_size(char *path);
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content); void get_dir_content(char *path, dir *dir);
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content); void print_dir(WINDOW *win, char print_info, dir *dir);
char update_selected_file(); char update_selected_file();
void dir_set_selected_file_current(unsigned long selected_file_current); void dir_set_selected_file_current(unsigned long selected_file_current);
unsigned long dir_get_selected_file_current(); unsigned long dir_get_selected_file_current();

View File

@@ -13,26 +13,20 @@ extern unsigned int terminal_height;
extern unsigned int terminal_width; extern unsigned int terminal_width;
char previewd; char previewd;
char* text(char *path, unsigned long *file_size); char* text(file *f);
void images_print(char *file_name); void images_print(char *file_name);
void images_clear(); void images_clear();
char* generic(char *path); char* generic(file *f);
char* get_mimetype(char *path){ char* get_mimetype(file *f){
static char *cmd_str = "file --mime-type -b ./\""; static const char *cmd_str = "file --mime-type -b";
unsigned long cmd_len = strlen(cmd_str); char *cmd = parse_cmd(cmd_str, f);
unsigned int path_len = strlen(path);
char *cmd = malloc((cmd_len + path_len) + 2);
memset(cmd, ' ', cmd_len + path_len);
memcpy(cmd, cmd_str, cmd_len);
memcpy(cmd + cmd_len, path, path_len);
cmd[cmd_len + path_len] = '\"';
cmd[cmd_len + path_len + 1] = '\0';
FILE *cmd_open = popen(cmd, "r"); FILE *cmd_open = popen(cmd, "r");
char *line = NULL; char *line = NULL;
size_t size = 0; size_t size = 0;
free(cmd);
if (getline(&line, &size, cmd_open) != -1){ if (getline(&line, &size, cmd_open) != -1){
pclose(cmd_open); pclose(cmd_open);
return line; return line;
@@ -41,56 +35,59 @@ char* get_mimetype(char *path){
return "unknown"; return "unknown";
} }
} }
char* preview_file(char *file_name, unsigned long file_size){ char* preview_file(file *f){
/* this calls "file" on path */ /* this calls "file" on path */
char *file_buffer; char *file_buffer;
char *mime = get_mimetype(f);
char *mime = get_mimetype(file_name);
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0 #if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
images_clear(); images_clear();
#endif #endif
if (strstr(mime, "text")) { if (strstr(mime, "text")) {
file_buffer = text(file_name, &file_size); file_buffer = text(f);
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0 #if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
} else if (strstr(mime, "image")) { } else if (strstr(mime, "image")) {
file_buffer = generic(file_name); file_buffer = generic(f);
images_print(file_name); images_print(f->file_name);
previewd = 1; previewd = 1;
#endif #endif
} else { } else {
file_buffer = generic(file_name); file_buffer = generic(f);
} }
free(mime); free(mime);
return file_buffer; return file_buffer;
} }
char* text(char *path, unsigned long *file_size){ char* text(file *f){
unsigned long size = (terminal_width/2) * terminal_height; unsigned long size = (terminal_width/2) * terminal_height;
if (size > *file_size) { if (size > f->file_size) {
size = *file_size; size = f->file_size;
} }
char *file_buffer = malloc(size + 1); char *file_buffer = malloc(size + 1);
FILE *fp = fopen(path, "r"); FILE *fp = fopen(f->file_name, "r");
if (fread(file_buffer, size, 1, fp) != 0) { if (fread(file_buffer, size, 1, fp) != 0) {
fclose(fp);
file_buffer[size] = '\0'; file_buffer[size] = '\0';
return file_buffer; return file_buffer;
} else { } else {
fclose(fp);
return "failed reading file"; return "failed reading file";
} }
} }
char* generic(char *path){ char* generic(file *f){
char *cmd = concat("file ./\"", path); static const char *cmd_str = "file";
cmd = concat(cmd, "\""); char *cmd = parse_cmd(cmd_str, f);
FILE *cmd_open = popen(cmd, "r"); FILE *cmd_open = popen(cmd, "r");
char *line = NULL; char *line = NULL;
size_t size = 0; size_t size = 0;
free(cmd);
if (getline(&line, &size, cmd_open) != -1) { if (getline(&line, &size, cmd_open) != -1) {
pclose(cmd_open); pclose(cmd_open);
return line; return line;

View File

@@ -4,8 +4,8 @@
#include "config.h" #include "config.h"
#endif #endif
char* preview_file(char *file_name, unsigned long file_size); char* preview_file(file *f);
char* get_mimetype(char *path); char* get_mimetype(file *f);
void images_clear(); void images_clear();
void ueberzug_init(); void ueberzug_init();
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0 #if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0

View File

@@ -12,50 +12,36 @@
#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 file *mid_content; extern WINDOW *win_m;
extern file *lft_content; extern dir mid_dir;
extern file *rgt_content;
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 long mid_file_count;
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;
char search_buffer[INPUT_BUFFER_SIZE]; char search_buffer[INPUT_BUFFER_SIZE];
unsigned int input_pass; 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 void window_btm(WINDOW *win, char force_render);
extern int (*order_func)();
#define TODO noraw(); \
endwin();\
curs_set(1);\
echo();\
printf("TODO: %s at %d in %s \n", __func__, __LINE__, __FILE__);\
exit(1);
void FAIL(char *function, char *str){ void FAIL(char *function, char *str){
noraw();
endwin();
curs_set(1);
echo();
printf("ERROR in function %s: %s", function, str); printf("ERROR in function %s: %s", function, str);
} }
void user_interactions() { void user_interactions() {
@@ -64,53 +50,46 @@ void user_interactions() {
char ch; char ch;
unsigned long i; unsigned long i;
unsigned long binding_matches = 0; unsigned long binding_matches = 0;
static char binding_pass = 0;
ch = getch(); ch = getch();
if(ch != ERR) { if(ch != ERR) {
timeout(10); /* blocking timeout of getch() */
input[input_pass] = ch; input[input_pass] = ch;
input_pass++; input_pass++;
if (ch == 27) { /* esc key */ if (ch == 27) { /* esc key */
memset(input, ' ', terminal_width);
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
memset(input, 0, INPUT_BUFFER_SIZE); memset(input, 0, INPUT_BUFFER_SIZE);
input_pass = 0; input_pass = 0;
timeout(100); /* blocking timeout of getch() */
} }
binding_pass = 0;
status |= STATUS_UPDATE_SCREEN_0;
} else {
timeout(100);
} }
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
void (*func_ptr)(int, int); void (*func_ptr)(int, int);
unsigned long number_length = 0; unsigned long number_length = 0;
if (!binding_pass) { parsed_input_number = 0;
parsed_input_number = 0; while((*input >= '0') && (*input <= '9')) {
while((*input >= '0') && (*input <= '9')) { parsed_input_number = (parsed_input_number * 10) + (*input - '0');
parsed_input_number = (parsed_input_number * 10) + (*input - '0'); input++;
input++; number_length++;
number_length++;
}
input -= number_length;
binding_pass = 1;
} }
if (parsed_input_number == 0) {
parsed_input_number = 1;
}
input -= number_length;
char cmp_len = strlen(input); char cmp_len = strlen(input);
if(strlen(input) < 1) { if(strlen(input) < 1) {
cmp_len++; cmp_len = 1;
} }
for (i = 0; i < binding_count; i++) { for (i = 0; i < binding_count; i++) {
if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) { if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
if (strcmp(input + number_length, key_binding[i].key) == 0) { if (strcmp(input + number_length, key_binding[i].key) == 0) {
pthread_mutex_lock(&mutex_mid);
func_ptr = key_binding[i].func; func_ptr = key_binding[i].func;
func_ptr(parsed_input_number, i); func_ptr(parsed_input_number, i);
pthread_mutex_unlock(&mutex_mid);
timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */
} else { } else {
binding_matches++; binding_matches++;
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t"); mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
@@ -127,10 +106,8 @@ void user_interactions() {
} else if (number_length != strlen(input)) { } else if (number_length != strlen(input)) {
memset(input, 0, INPUT_BUFFER_SIZE); memset(input, 0, INPUT_BUFFER_SIZE);
input_pass = 0; input_pass = 0;
binding_pass = 0;
number_length = 0; number_length = 0;
binding_matches = 0; binding_matches = 0;
timeout(100); /* blocking timeout of getch() */
} }
} }
int read_string(WINDOW *win, int y, int x, char *str){ int read_string(WINDOW *win, int y, int x, char *str){
@@ -150,26 +127,25 @@ int read_string(WINDOW *win, int y, int x, char *str){
err = 0; err = 0;
break; break;
} else if (ch == '\t') { /* tab */ } else if (ch == '\t') { /* tab */
memcpy(str + pass, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)); memcpy(str + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
mvwaddstr(win, y, x +pass, mid_content[selected_file_current].file_name); mvwaddstr(win, y, x + pass, mid_dir.current_file->file_name);
pass += strlen(mid_content[selected_file_current].file_name); pass += strlen(mid_dir.current_file->file_name);
} 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;
break; break;
} else { } else {
mvwaddch(win, y, x +pass, ch); mvwaddch(win, y, x + pass, ch);
str[pass] = ch; str[pass] = ch;
pass++; pass++;
} }
} }
str[pass] = '\0'; str[pass] = '\0';
timeout(100);
curs_set(0); curs_set(0);
return err; return err;
@@ -177,399 +153,221 @@ int read_string(WINDOW *win, int y, int x, char *str){
void quit_program(){ void quit_program(){
status = STATUS_QUIT_PROGRAM; status = STATUS_QUIT_PROGRAM;
} }
void update(){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
}
void select_all(){ void select_all(){
pthread_mutex_lock(&mutex_selection);
pthread_mutex_lock(&mutex_mid);
unsigned long i; unsigned long i;
for(i = 0; i < mid_file_count; i++) { for (i = 0; i < mid_dir.file_count; i++) {
mid_content[i].status ^= FILE_STATUS_SELECTED; mid_dir.file_list[i].status ^= FILE_STATUS_SELECTED;
} }
pthread_mutex_unlock(&mutex_mid); status |= (STATUS_RUN_BACKEND);
pthread_mutex_unlock(&mutex_selection);
} }
void move_down(unsigned long passes){ void move_down(unsigned long passes){
pthread_mutex_lock(&mutex_selection);
if (passes == 0) { mid_dir.current_file += passes;
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;
} }
selected_file_current += passes;
update_selected_file(); status |= (STATUS_RUN_BACKEND);
dir_set_selected_file_current(selected_file_current);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
pthread_mutex_unlock(&mutex_selection);
} }
void move_up(unsigned long passes){ void move_up(unsigned long passes){
pthread_mutex_lock(&mutex_selection);
if (passes == 0) { mid_dir.current_file -= passes;
passes++; if (mid_dir.current_file < mid_dir.file_list) {
} mid_dir.current_file = mid_dir.file_list;
unsigned long tmp = selected_file_current;
selected_file_current -= passes;
if (tmp < selected_file_current) {
selected_file_current = 0;
} }
update_selected_file(); status |= (STATUS_RUN_BACKEND);
dir_set_selected_file_current(selected_file_current);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
} }
void move_left(unsigned long passes){ void move_left(unsigned long passes){
if (passes == 0) {
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");
} else {
selected_file_current = dir_get_selected_file_current();
}
} }
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
} }
void move_right(){ void move_right(){
if (mid_content->file_name[0] == '\0') {
return; if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
} change_dir(mid_dir.current_file->file_name);
if ((mid_content[selected_file_current].file_type & FILE_TYPE_DIR) == FILE_TYPE_DIR) { } else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
if (chdir(mid_content[selected_file_current].file_name) != 0) { char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
FAIL("move_right", "unhandled error of chdir"); if (system(cmd)) {
} else {
selected_file_current = dir_get_selected_file_current();
} }
} else { } else {
unsigned long i = 0; char *mime = get_mimetype(mid_dir.current_file);
char match = 0; char *extension = mid_dir.current_file->file_name;
char *mime = get_mimetype(mid_content[selected_file_current].file_name); char *cmd = NULL;
char *extension = strrchr(mid_content[selected_file_current].file_name, '.'); while (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
if (extension != NULL) { if (*extension == '.') {
break;
}
extension++;
}
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++) { for (i = 0; i < file_extension_default_count; i++) {
if (strstr(extension, file_extension_default_cmd[i].file_extension)) { if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
char *cmd = concat(file_extension_default_cmd[i].command, " ./\""); if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
cmd = concat(cmd, mid_content[selected_file_current].file_name); cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file);
cmd = concat(cmd, "\""); pid_t pid = fork();
if (pid == 0 && setsid()) {
system(cmd);
if (system(cmd) == -1) { status = STATUS_QUIT_PROGRAM;
/*do nothing*/ exit(1);
}
} else {
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
if (system(cmd)) {
}
} }
curs_set(1); /*for some reason, 1 here turns it invisible once again */ status |= STATUS_MOVE_RIGHT_MATCH;
match = 1; update();
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
break; break;
} }
} }
} }
if (match == 0) { if (!(status & STATUS_MOVE_RIGHT_MATCH)) {
for (i = 0; i < mimetype_default_count; i++) { for (i = 0; i < mimetype_default_count; i++) {
if (strstr(mime, mimetype_default_cmd[i].mimetype)) { if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
char *cmd = concat(mimetype_default_cmd[i].command, " ./\""); cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file);
cmd = concat(cmd, mid_content[selected_file_current].file_name); pid_t pid = fork();
cmd = concat(cmd, "\""); if (pid == 0 && setsid()) {
system(cmd);
status = STATUS_QUIT_PROGRAM;
exit(1);
if (system(cmd) == -1) { }
/*do nothing*/ } else {
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
if (system(cmd)) {
}
} }
curs_set(1); /*for some reason, 1 here turns it invisible once again */ status |= STATUS_MOVE_RIGHT_MATCH;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); update();
break; break;
} }
} }
} }
status &= ~STATUS_MOVE_RIGHT_MATCH;
free(cmd);
free(mime); free(mime);
} }
update_selected_file(); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
} }
void toggle_hidden_files(){ void toggle_hidden_files(){
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES; file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
} }
void toggle_selection(){ void toggle_selection(unsigned long passes){
pthread_mutex_lock(&mutex_selection); unsigned long i;
pthread_mutex_lock(&mutex_mid); for (i = 0; i < passes; i++) {
mid_content[selected_file_current].status ^= FILE_STATUS_SELECTED; mid_dir.current_file->status ^= FILE_STATUS_SELECTED;
status |= (STATUS_UPDATE_SCREEN_MASK); move_down(1);
pthread_mutex_unlock(&mutex_mid); }
pthread_mutex_unlock(&mutex_selection); status |= (STATUS_RUN_BACKEND);
move_down(1);
} }
void jump_bottom(){ void jump_bottom(){
pthread_mutex_lock(&mutex_selection); mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
selected_file_current = 0 - 1; status |= (STATUS_RUN_BACKEND);
update_selected_file();
dir_set_selected_file_current(selected_file_current);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
} }
void jump_top(){ void jump_top(){
pthread_mutex_lock(&mutex_selection); mid_dir.current_file = mid_dir.file_list;
selected_file_current = 0; status |= (STATUS_RUN_BACKEND);
update_selected_file();
dir_set_selected_file_current(selected_file_current);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
} }
void open_with(){ void open_with(){
pthread_mutex_lock(&mutex_btm); wclear(win_b);
char *cmd;
char *btm_buffer_tmp = btm_buffer;
werase(win_b);
mvwin(win_b, terminal_height-6, 0);
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
btm_buffer = concat("open \"", mid_content[selected_file_current].file_name);
btm_buffer = concat(btm_buffer, "\" with:");
window_btm(win_b, 1);
char *str = malloc(INPUT_BUFFER_SIZE); char *str = malloc(INPUT_BUFFER_SIZE);
memset(str, ' ', INPUT_BUFFER_SIZE); char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file);
str[INPUT_BUFFER_SIZE-1] = '\0'; mvwprintw(win_b, 0, 0, parsed_ui_text);
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0 , str); 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);
if (err == 0) { pid_t pid = fork();
char *cmd = concat(str, " ./\""); if (pid == 0 && setsid()) {
cmd = concat(cmd, mid_content[selected_file_current].file_name); system(cmd);
cmd = concat(cmd, "\""); status = STATUS_QUIT_PROGRAM;
exit(1);
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0 }
images_clear(); } else {
#endif cmd = parse_cmd(str, mid_dir.current_file);
if (system(cmd)) {
if (system(cmd) == -1) { }
FAIL("open_with", "creating subcommand failed unhandled");
} }
free(cmd);
} }
free(parsed_ui_text);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
free(btm_buffer);
btm_buffer = btm_buffer_tmp;
pthread_mutex_unlock(&mutex_btm);
free(str); free(str);
} status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
}
void rename_hovered(){ void rename_hovered(){
pthread_mutex_lock(&mutex_btm); wclear(win_b);
file tmp;
char *btm_buffer_tmp = btm_buffer; tmp.file_name = malloc(INPUT_BUFFER_SIZE);
werase(win_b); char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
mvwin(win_b, terminal_height-6, 0); mvwprintw(win_b, 0, 0, parsed_ui_text);
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/ 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);
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name); char *cmd1 = parse_cmd(cmd0, &tmp);
btm_buffer = concat(btm_buffer, "\" to:"); system(cmd1);
free(cmd0);
window_btm(win_b, 1); free(cmd1);
char *str = malloc(INPUT_BUFFER_SIZE);
memset(str, ' ', INPUT_BUFFER_SIZE);
str[INPUT_BUFFER_SIZE-1] = '\0';
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
if (!err) {
char *cmd = concat("mv ./\"", mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\" ./\"");
cmd = concat(cmd, str);
cmd = concat(cmd, "\"");
if (system(cmd) == -1) {
FAIL("rename_hovered", "mv or creating subcommand failed");
};
btm_buffer = cmd;
} }
free(str); free(parsed_ui_text);
free(btm_buffer); free(tmp.file_name);
btm_buffer = btm_buffer_tmp; status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
pthread_mutex_unlock(&mutex_btm);
} }
void delete(){ void delete(){
pthread_mutex_lock(&mutex_btm); TODO;
char *btm_buffer_tmp = btm_buffer;
unsigned int i = 0;
unsigned int hits = 0;
char *file_str = " ";
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
file_str = concat(file_str, "\"");
file_str = concat(file_str, mid_content[i].file_name);
file_str = concat(file_str, "\" ");
hits++;
}
}
werase(win_b);
mvwin(win_b, terminal_height-6, 0);
if (strlen(file_str) < (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION-1) * (terminal_width/3)) {
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3));
memset(btm_buffer, ' ', (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)));
memcpy(btm_buffer, "delete: ",strlen("delete: "));
if (hits) {
memcpy(btm_buffer + strlen("delete: "), file_str, strlen(file_str));
} else {
btm_buffer[strlen("delete: ")] = '"';
memcpy(btm_buffer + strlen("delete: ") + sizeof(char), mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)-1);
btm_buffer[strlen("delete: ") + sizeof(char) + strlen(mid_content[selected_file_current].file_name)] = '"';
}
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3) - (terminal_width/3)) , "(y/N)", strlen("(y/N)"));
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)] = '\0';
} else {
/*since more data is present than can be represented using div3, we do the uncool thing*/
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width);
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
memset(btm_buffer, ' ', BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
memcpy(btm_buffer, "delete: ",strlen("delete: "));
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
/*lets hope im never gonna need to format something like this ever again*/
memcpy(btm_buffer + strlen("delete: "), file_str,
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
strlen(file_str)));
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width - terminal_width) , "(y/N)", strlen("(y/N)"));
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width] = '\0';
}
window_btm(win_b, 1);
timeout(-1); /* negative numbers block until enter is pressed */
char ch = wgetch(win_b);
if (ch == 'y' || ch == 'Y') {
if (hits) {
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
recursive_delete(mid_content[i]);
}
}
} else {
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
recursive_delete(mid_content[selected_file_current]);
}
remove(mid_content[selected_file_current].file_name);
}
}
free(btm_buffer);
btm_buffer = btm_buffer_tmp;
if (hits) {
free(file_str);
}
timeout(10);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
pthread_mutex_unlock(&mutex_btm);
} }
void makedir(){ void makedir(){
pthread_mutex_lock(&mutex_btm); wclear(win_b);
file tmp;
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
char *btm_buffer_tmp = btm_buffer; mvwprintw(win_b, 0, 0, ui_makedir_text);
werase(win_b); if (read_string(win_b, 0, strlen(ui_makedir_text)+1, tmp.file_name) == 0) {
mvwin(win_b, terminal_height-6, 0); char *cmd = parse_cmd(makedir_cmd, &tmp);
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/ system(cmd);
free(cmd);
btm_buffer = "create dir: ";
window_btm(win_b, 1);
char *str = malloc(INPUT_BUFFER_SIZE);
memset(str, ' ', INPUT_BUFFER_SIZE);
str[INPUT_BUFFER_SIZE-1] = '\0';
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
if (!err) {
btm_buffer = concat(btm_buffer, str);
mode_t mask = umask(0);
mkdir(str, 0755); /*magic number from default permissions as created by mkdir*/
umask(mask);
} }
free(str); free(tmp.file_name);
free(btm_buffer); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
btm_buffer = btm_buffer_tmp;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
pthread_mutex_unlock(&mutex_btm);
} }
void makefile(){ void makefile(){
pthread_mutex_lock(&mutex_btm); wclear(win_b);
file tmp;
char *btm_buffer_tmp = btm_buffer; tmp.file_name = malloc(INPUT_BUFFER_SIZE);
werase(win_b); mvwprintw(win_b, 0, 0, ui_makefile_text);
mvwin(win_b, terminal_height-6, 0); if (read_string(win_b, 0, strlen(ui_makefile_text)+1, tmp.file_name) == 0) {
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/ char *cmd = parse_cmd(makefile_cmd, &tmp);
system(cmd);
btm_buffer = "create file: "; free(cmd);
window_btm(win_b, 1);
char *str = malloc(INPUT_BUFFER_SIZE);
memset(str, ' ', INPUT_BUFFER_SIZE);
str[INPUT_BUFFER_SIZE-1] = '\0';
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
if (!err) {
btm_buffer = concat(btm_buffer, str);
FILE *fp;
fp = fopen(str, "w");
fclose(fp);
} }
free(str); free(tmp.file_name);
free(btm_buffer); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
btm_buffer = btm_buffer_tmp;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
pthread_mutex_unlock(&mutex_btm);
}
void update(){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
} }
void enter_shell(unsigned long passes, int index){ void enter_shell(unsigned long passes, int index){
(void)passes; (void)passes; /*remove compiler warning*/
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0 endwin();\
images_clear(); echo();\
#endif curs_set(1);\
endwin(); if (system(key_binding[index].black_magic)) {
if (system(key_binding[index].black_magic) != 0) {
/*do nothing*/
} }
initscr(); initscr(); /* start ncurses */
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); 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;
@@ -577,382 +375,171 @@ void not_implemented(unsigned long passes, int index){
mvaddstr(terminal_height-1, 0, key_binding[index].comment); 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), "\t");
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented"); mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
TODO;
} }
void jump_to_dir(unsigned long passes, int index){ void jump_to_dir(unsigned long passes, int index){
(void)passes; (void)passes;
char *ch = (char*)key_binding[index].black_magic; unsigned long len;
char slash = 0; char *c = strchr(key_binding[index].black_magic, '/');
unsigned int env_len = 0; if (c) {
while (*ch != '\0') { len = c - (char*)key_binding[index].black_magic;
if (*ch == '/') {
slash = 1;
break;
}
env_len++;
ch++;
}
char *env_str = NULL;
char *env_parsed = NULL;
char *path = NULL;
ch = (char*)key_binding[index].black_magic;
if (*ch == '/') {
path = malloc(strlen((char*)key_binding[index].black_magic));
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
} else if (slash) {
env_str = malloc(env_len * sizeof(char));
memcpy(env_str, (char*)key_binding[index].black_magic +1, env_len);
env_str[env_len-1] = '\0';
env_parsed = getenv(env_str);
if (env_parsed) {
path = concat(env_parsed, (char*)key_binding[index].black_magic + env_len);
} else {
path = malloc(strlen((char*)key_binding[index].black_magic));
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
}
} else { } else {
env_parsed = getenv((char*)key_binding[index].black_magic +1); len = strlen(key_binding[index].black_magic);
if (env_parsed) {
path = malloc(strlen(env_parsed)+1);
memcpy(path, env_parsed, strlen(env_parsed)+1);
} else {
path = malloc(strlen((char*)key_binding[index].black_magic));
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
}
}
if (chdir(path) != 0) {
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
} else {
selected_file_current = dir_get_selected_file_current();
} }
/*env_parsed shall not be modified (read: free'd) - the man page*/ char *to_env = malloc(len + 1);
if (env_str) { memcpy(to_env, key_binding[index].black_magic, len);
free(env_str); to_env[len] = '\0';
} char *env = getenv(to_env + 1); /*+1 to remove the '$' prefix, freeing env always segfaults*/
if(path) {
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); free(path);
} else {
change_dir(key_binding[index].black_magic);
} }
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); 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;
free(seed); seed = time(NULL);
seed = NULL;
seed = malloc(sizeof(time_t));
*seed = time(NULL);
order_func = key_binding[index].black_magic; order_func = key_binding[index].black_magic;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | 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){
(void)passes; (void)passes;
pthread_mutex_lock(&mutex_btm);
char *btm_buffer_tmp = btm_buffer; char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file);
unsigned int i = 0; system(cmd);
unsigned int hits = 0;
char *file_str = " ";
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
file_str = concat(file_str, "\"");
file_str = concat(file_str, mid_content[i].file_name);
file_str = concat(file_str, "\" ");
hits++;
}
}
if (hits) {
btm_buffer = concat(key_binding[index].black_magic, file_str);
} else {
btm_buffer = concat(key_binding[index].black_magic, "\"");
btm_buffer = concat(btm_buffer, mid_content[selected_file_current].file_name);
btm_buffer = concat(btm_buffer, "\"");
}
btm_buffer = concat(btm_buffer, "?");
btm_buffer = concat(btm_buffer, "\n\n");
btm_buffer = concat(btm_buffer, "(y/N)");
werase(win_b);
mvwin(win_b, terminal_height-6, 0);
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
window_btm(win_b, 1);
timeout(-1); /* negative numbers block until enter is pressed */
/* TODO(2025-07-06T07:22:49) fix fixed buffer size */
char ch = wgetch(win_b);
if (ch == 'y' || ch == 'Y') {
/* the second loop is used to add "./", wich is not being printed" */
char *cmd = malloc(sizeof(char));
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
if (hits) {
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
free(cmd);
cmd = concat((char*)key_binding[index].black_magic, " \"");
cmd = concat(cmd, mid_content[i].file_name);
cmd = concat(cmd, "\"");
if (system(cmd) != 0) {
/*do nothing*/
}
}
}
} else {
free(cmd);
cmd = concat((char*)key_binding[index].black_magic, " \"");
cmd = concat(cmd, mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\"");
if (system(cmd) != 0) {
/*do nothing*/
}
mvaddstr(10,10, cmd);
}
/*system(cmd);*/
free(cmd);
}
free(btm_buffer);
btm_buffer = btm_buffer_tmp;
timeout(10);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
if (hits) {
free(file_str);
}
pthread_mutex_unlock(&mutex_btm);
}
void yank_text(unsigned long passes, int index){
(void)passes;
char *cmd;
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
char *path=getcwd(NULL, 0);
cmd = concat("echo \"", path);
cmd = concat(cmd, "/");
cmd = concat(cmd, mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\" | ");
cmd = concat(cmd, clipboard_cmd);
free(path);
} else {
cmd = concat("echo \"", mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\" | ");
cmd = concat(cmd, clipboard_cmd);
}
if (system(cmd) == -1) {
/*do nothing*/
}
free(cmd); free(cmd);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
}
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_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){
(void)passes; TODO;
unsigned long i;
if (yank_files.status & YANK_IS_USED) {
for (i = 0; i < yank_files.count; i++) {
free(yank_files.list[i]);
}
free(yank_files.list);
free(yank_files.path);
yank_files.count = 0;
yank_files.status = 0;
}
yank_files.path=getcwd(NULL, 0);
yank_files.count = 0;
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
yank_files.count++;
}
}
if (yank_files.count == 0) {
yank_files.count = 1;
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
memcpy(*yank_files.list, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
} else {
yank_files.list = malloc(yank_files.count * sizeof(char*));
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
memcpy(*yank_files.list, mid_content[i].file_name, strlen(mid_content[i].file_name));
yank_files.list += 1;
}
}
yank_files.list -= yank_files.count;
}
yank_files.status |= YANK_IS_USED;
if (strncmp((char*)key_binding[index].black_magic, "cut", 3) == 0) {
yank_files.status |= YANK_CUT;
yank_files.status &= ~YANK_COPY;
} else {
yank_files.status |= YANK_COPY;
yank_files.status &= ~YANK_CUT;
}
} }
void paste(){ void paste(){
unsigned long i; TODO;
for (i = 0; i < yank_files.count; i++) {
/*TODO(2025-08-14T22:10:44) escape path*/
char *cmd;
if (yank_files.status & YANK_COPY) {
cmd = concat("false | cp -riv ", yank_files.path);
} else {
cmd = concat("mv ", yank_files.path);
}
cmd = concat(cmd, "/");
cmd = concat(cmd, *yank_files.list);
cmd = concat(cmd, " ./");
cmd = concat(cmd, *yank_files.list);
cmd = concat(cmd, " 2>&1");
char *line = malloc(INPUT_BUFFER_SIZE);
FILE *cmd_open;
while (1) {
cmd_open = popen(cmd, "r");
if (fgets(line, INPUT_BUFFER_SIZE, cmd_open) == 0) {
break;
}
if (strstr(line, "are the same file")) {
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
cmd = concat(cmd, "_");
cmd = concat(cmd, " 2>&1");
} else if ((strstr(line, "overwrite"))) {
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
cmd = concat(cmd, "_");
cmd = concat(cmd, " 2>&1");
} else if ((strstr(line, "No such file or directory"))) {
pclose(cmd_open);
break;
} else if (pclose(cmd_open) == 0) {
break;
}
pclose(cmd_open);
}
free(cmd);
yank_files.list++;
}
yank_files.list -= yank_files.count;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
} }
void search(){ void search(){
pthread_mutex_lock(&mutex_btm); echo();
unsigned long i;
unsigned long local_height; for (i = 0; i < terminal_width -1; i++) {
local_height = getmaxy(win_b); mvwaddch(win_b, 0, i, ' ');
memset(search_buffer, '\0', INPUT_BUFFER_SIZE); }
mvwaddch(win_b, 0, 0, '/');
window_btm(win_b, 1); memset(search_buffer, 0, INPUT_BUFFER_SIZE);
curs_set(1); curs_set(1);
echo();
timeout(-1); /* negative numbers block until enter is pressed */ timeout(-1); /* negative numbers block until enter is pressed */
unsigned int pass = 0; unsigned int pass = 0;
char ch; char ch;
char err = 0;
wmove(win_b, local_height-1, 1); wmove(win_b, 0, 1);
while(1) { while(1) {
/*ch = mvwgetch(win, y, x + pass);*/
werase(win_b);
mvwaddch(win_b, local_height-1, 0, '/');
mvwaddstr(win_b, local_height-1, 1, search_buffer);
ch = wgetch(win_b); ch = wgetch(win_b);
if (ch == '\n') { if (ch == '\n') {
err = 0;
break; break;
} else if (ch == '\t') { /* tab */ } else if (ch == '\t') { /* tab */
memcpy(search_buffer, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)); memcpy(search_buffer + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
mvwaddstr(win_b, local_height-1, pass, mid_content[selected_file_current].file_name); mvwaddstr(win_b, 0, pass+1, mid_dir.current_file->file_name);
pass = strlen(mid_content[selected_file_current].file_name); pass += strlen(mid_dir.current_file->file_name);
} else if (ch == 127) { /* backspace */ } else if (ch == 127) { /* backspace */
mvwdelch(win_b, local_height-1, 1); if (pass > 0) {
wdelch(win_b);
if (pass != 0) {
search_buffer[pass-1] = '\0';
pass--; pass--;
mvwdelch(win_b, 0, pass+1);
} }
} else if (ch == 27) { /* esc key */ } else if (ch == 27) { /* esc key */
err = 1;
break; break;
} else { }
if (ch) {
mvwaddch(win_b, 0, pass+1, ch);
search_buffer[pass] = ch; search_buffer[pass] = ch;
pass++; pass++;
unsigned long i;
for (i = 0; i < mid_file_count; i++) { unsigned long index = (mid_dir.current_file - mid_dir.file_list);
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) { unsigned long x = getmaxx(win_b);
selected_file_current = i; for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
if (update_selected_file()) { if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
pthread_cond_signal(&cond_rgt); mid_dir.current_file = &mid_dir.file_list[index];
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0); /* 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; break;
} }
render_pass();
} }
} }
} }
search_buffer[pass] = '\0'; search_buffer[pass] = '\0';
timeout(10); noecho();
curs_set(0); curs_set(0);
dir_set_selected_file_current(selected_file_current); status |= (STATUS_RUN_BACKEND);
update_selected_file();
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
pthread_mutex_unlock(&mutex_btm);
} }
void search_next(){ void search_next(){
unsigned long i; long index = (mid_dir.current_file - mid_dir.file_list) + 1;
for (i = selected_file_current+1; i < mid_file_count; i++) { for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) { if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
selected_file_current = i; mid_dir.current_file = &mid_dir.file_list[index];
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
update_selected_file();
render_pass();
break; break;
} }
} }
status |= (STATUS_RUN_BACKEND);
} }
void search_previous(){ void search_previous(){
unsigned long i; long index = (mid_dir.current_file - mid_dir.file_list) - 1;
for (i = selected_file_current-1;; i--) { for (; &mid_dir.file_list[index] >= mid_dir.file_list; index--) {
if(i > selected_file_current) { if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
break; mid_dir.current_file = &mid_dir.file_list[index];
}
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
selected_file_current = i;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
update_selected_file();
render_pass();
break; break;
} }
} }
status |= (STATUS_RUN_BACKEND);
} }
void jmp_file_index(){ void jmp_file_index(){
char *index = malloc(INPUT_BUFFER_SIZE); TODO;
memset(index, ' ', INPUT_BUFFER_SIZE);
index[INPUT_BUFFER_SIZE-1] = '\0';
unsigned long local_height;
local_height = getmaxy(win_b);
read_string(win_b, local_height - 1, 0, index);
unsigned long new_index = 0;
while((*index >= '0') && (*index <= '9')) {
new_index = (new_index * 10) + (*index - '0');
index++;
}
if (new_index > mid_file_count) {
selected_file_current = mid_file_count;
} else {
selected_file_current = new_index;
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
update_selected_file();
} }

View File

@@ -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();

98
main.c
View File

@@ -7,6 +7,7 @@
#include <time.h> #include <time.h>
#include "defines.h" #include "defines.h"
#include "config.h"
#include "threading.h" #include "threading.h"
#include "window.c" #include "window.c"
#include "colors.h" #include "colors.h"
@@ -18,10 +19,10 @@ 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;
time_t *seed; time_t seed;
WINDOW *win_t; WINDOW *win_t;
WINDOW *win_b; WINDOW *win_b;
@@ -29,13 +30,17 @@ WINDOW *win_l;
WINDOW *win_m; WINDOW *win_m;
WINDOW *win_r; WINDOW *win_r;
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;
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();
int main(){ int main(){
init(); init();
@@ -58,8 +63,6 @@ int main(){
pthread_t thread_m; pthread_t thread_m;
pthread_t thread_r; pthread_t thread_r;
char threading = 0;
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;
@@ -72,29 +75,29 @@ 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*/
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);
if (status & STATUS_RUN_BACKEND) {
free(global_path);
global_path = getcwd(NULL, 0);
pthread_cond_signal(&cond_mid);
pthread_cond_signal(&cond_lft);
status &= ~(STATUS_RUN_BACKEND);
} else {
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
}
if (!(terminal_height == temp_heigth) || !(terminal_width == temp_width)) { if (!(terminal_height == temp_heigth) || !(terminal_width == temp_width)) {
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RESIZE); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RESIZE);
temp_width = terminal_width; temp_width = terminal_width;
temp_heigth = terminal_height; temp_heigth = terminal_height;
} }
if (threading) {
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
threading = 0;
}
if (status & STATUS_RUN_BACKEND) {
pthread_cond_signal(&cond_top);
pthread_cond_signal(&cond_mid);
pthread_cond_signal(&cond_lft);
status &= ~(STATUS_RUN_BACKEND);
status |= STATUS_UPDATE_SCREEN_0;
threading = 1;
}
user_interactions(); user_interactions();
render_pass(); render_pass();
#if SETTINGS_RELOAD_DIR_DELTA != 0 #if SETTINGS_RELOAD_DIR_DELTA != 0
@@ -110,17 +113,6 @@ int main(){
ueberzug_close(); ueberzug_close();
#endif #endif
threading_free(); threading_free();
free(start_path);
/*
if (threading) {
pthread_join(thread_l, NULL);
pthread_join(thread_r, NULL);
pthread_join(thread_m, NULL);
pthread_join(thread_t, NULL);
pthread_join(thread_b, NULL);
}
*/
delwin(win_l); delwin(win_l);
delwin(win_m); delwin(win_m);
@@ -137,14 +129,11 @@ int main(){
void render_pass(){ void render_pass(){
if (status & STATUS_UPDATE_SCREEN_CLEAR) {
clear();
status &= ~STATUS_UPDATE_SCREEN_CLEAR;
}
if (status & STATUS_UPDATE_SCREEN_RESIZE) { if (status & STATUS_UPDATE_SCREEN_RESIZE) {
if (status & STATUS_UPDATE_SCREEN_RELOAD_FULL) {
clear();
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
}
/*TODO: check if deallocation of window and reallocation is faster than this or not */
wresize(win_t, 1, terminal_width); wresize(win_t, 1, terminal_width);
wresize(win_l, terminal_height-2, terminal_width/8); wresize(win_l, terminal_height-2, terminal_width/8);
@@ -159,22 +148,11 @@ void render_pass(){
mvwin(win_r, 1, ((terminal_width/2))); mvwin(win_r, 1, ((terminal_width/2)));
mvwin(win_b, terminal_height-1, 0); mvwin(win_b, terminal_height-1, 0);
status |= STATUS_UPDATE_SCREEN_0;
} }
if (pthread_mutex_lock(&mutex_render) == 0 || status & STATUS_UPDATE_SCREEN_MASK) {
if (status & STATUS_UPDATE_SCREEN_MASK) { doupdate();
status &= ~(STATUS_UPDATE_SCREEN_MASK); status &= ~STATUS_UPDATE_SCREEN_MASK;
window_top(win_t); pthread_mutex_unlock(&mutex_render);
window_lft(win_l);
window_mid(win_m);
window_rgt(win_r);
window_btm(win_b, 0);
wrefresh(win_t);
wrefresh(win_l);
wrefresh(win_m);
wrefresh(win_r);
wrefresh(win_b);
} }
} }
/*this function exists for things done at startup (initialization, reading config, etc)*/ /*this function exists for things done at startup (initialization, reading config, etc)*/
@@ -183,13 +161,15 @@ void init() {
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
initscr(); /* start ncurses */ initscr(); /* start ncurses */
noecho(); /* hide keyboard input */ noecho(); /* hide keyboard input */
timeout(0); /* blocking timeout of getch() */ timeout(10); /* blocking timeout of getch(), using 10 rather than SETTINGS_CURSES_TIMEOUT to cause a faster first render
regardless on SETTINGS_CURSES_TIMEOUT, 10 was taken arbitrary.
if the blocking is too low, the first render happens delayed, however even this delay causes a quicker than
(compute time of threads) + timeout */
curs_set(0); curs_set(0);
/*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;
} }
@@ -202,11 +182,11 @@ void init() {
#endif #endif
ESCDELAY = 10; ESCDELAY = 10;
global_path = getcwd(NULL, 0);
char *start_path = getcwd(NULL, 0); char *start_path = getcwd(NULL, 0);
setenv("START_PATH", start_path, 0); setenv("START_PATH", start_path, 0);
free(start_path); free(start_path);
seed = malloc(sizeof(time_t)); seed = time(NULL);
*seed = time(NULL);
} }

View File

@@ -1,6 +1,5 @@
#include <curses.h> #include <curses.h>
#include <dirent.h> #include <dirent.h>
#include <stdlib.h>
#include <strings.h> #include <strings.h>
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
@@ -8,7 +7,7 @@
#include "defines.h" #include "defines.h"
extern time_t *seed; extern time_t seed;
int skip_hidden_files(const struct dirent *entry){ int skip_hidden_files(const struct dirent *entry){
@@ -118,21 +117,22 @@ int sort_random(const void *file0, const void *file1){
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) { if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
return 1; return 1;
} }
time_t num = (time_t)&seed; /* seed is the only value that actually changes whenever this funcion is called.
time_t i; * seed only updates when the order_by binding is executed.
for (i = num%2; i < 6+(((time_t)&seed)%2); i++){ * this means that the random output only changes on the command of the user, and not SETTINGS_RELOAD_DIR_DELTA, this is intentional.
num ^= *seed; * well the other stuff like file sizes and file count in a dir may also change, but this needs user intervention too.
if (num%2) { * that is unless the user decides to sort random in /var/log or something, which begs the question: why would you do that?
num ^= (time_t)&num; */
num ^= num << (i + (((time_t)&seed)%5)); time_t num = (((time_t)&sort_random) + (time_t)seed) ^ (((file*)file0)->file_size + ((file*)file1)->file_size);
} else { int i;
num ^= (time_t)&seed; for (i = 1; i < (((time_t)&getpid)%3); i++) {
num ^= num >> (i + (((time_t)&num)%5)); num ^= num << ((((time_t)&file0)%27)+i);
} num ^= num >> ((((time_t)&file1)%18)+i);
num ^= ((time_t)&getpid) ^ (((time_t)&getpid) >> ((time_t)getpid())%10);
} }
num ^= getpid();
return ((num%3) - 1); return (((num & (3 << seed%16)) >> seed%16) - 1);
/*return ((num%3) - 1);*/
} }
int sort_type(const void *file0, const void *file1){ int sort_type(const void *file0, const void *file1){

119
string.h Normal file
View File

@@ -0,0 +1,119 @@
#include <curses.h>
#ifndef BACKEND_GUARD
#define BACKEND_GUARD
#include "defines.h"
#define SETTINGS_COMMAND_REPLACE_STR "%"
typedef struct String {
char *data;
size_t size;
} string;
#define s(str) { \
return (string) { \
.data = str; \
.size = strlen(str); \
} \
}
#define concat(out, s1, s2, _free) { \
concat## _free(out, s1, s2); \
}
#define concat0(out, s1, s2) \
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
memcpy(result, s1, strlen(s1)); \
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
out = result;
#define concat1(out, s1, s2) \
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
memcpy(result, s1, strlen(s1)); \
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
free(s1); \
out = result;
#define concat2(out, s1, s2) \
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
memcpy(result, s1, strlen(s1)); \
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
free(s2); \
out = result;
#define concat3(out, s1, s2) \
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
memcpy(result, s1, strlen(s1)); \
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
free(s1); \
free(s2); \
out = result;
/*
int s_strcmp(const char *s0, char string *s1) {
size_t size = s1->size - s0->size;
if (size) {
return size;
}
size = s0.size;
while (*s0->data == *s0->data && size) {
s0->data += 1;
s1->data += 1;
size--;
}
return size;
}
*/
char* smartstrcasestr(const char *haystack, const char *needle){
char smart = 0;
char *ret;
char passes = 0;
while (*needle) {
if (*needle >= 'A' && *needle <= 'Z') {
smart = 1;
break;
}
passes++;
needle++;
}
needle -= passes;
if (smart == 0) {
char *needle_case = malloc(strlen(needle)+1);
memcpy(needle_case, needle, strlen(needle)+1);
passes = 0;
while (*needle_case) {
*needle_case = *needle_case | ' ';
needle_case++;
passes++;
}
needle_case -= passes;
char *haystack_case = malloc(strlen(haystack)+1);
memcpy(haystack_case, haystack, strlen(haystack)+1);
passes = 0;
while (*haystack_case) {
*haystack_case = *haystack_case | ' ';
haystack_case++;
passes++;
}
haystack_case -= passes;
ret = strstr(haystack_case, needle_case);
free(needle_case);
free(haystack_case);
} else {
ret = strstr(haystack, needle);
}
return ret;
}
#endif
/*char* concat(const char *s1, const char *s2);*/
char* smartstrcasestr(const char *haystack, const char *needle);

View File

@@ -4,7 +4,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <time.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/statvfs.h> #include <sys/statvfs.h>
@@ -19,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;
@@ -27,81 +26,112 @@ pthread_cond_t cond_top;
pthread_cond_t cond_btm; pthread_cond_t cond_btm;
file *rgt_content; dir rgt_dir;
file *mid_content; dir mid_dir;
file *lft_content; dir lft_dir;
char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */ char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */
char *btm_buffer; char *btm_buffer;
char *top_buffer; /* current path */ char *top_buffer; /* current path */
extern WINDOW *win_t;
extern WINDOW *win_b;
extern WINDOW *win_l;
extern WINDOW *win_m;
extern WINDOW *win_r;
unsigned long rgt_file_count = 0;
unsigned long mid_file_count = 0;
unsigned long lft_file_count;
unsigned long top_width; unsigned long top_width;
volatile unsigned long selected_file_current = 0;
volatile unsigned long selected_file_last = 0;
extern unsigned int terminal_width; extern unsigned int terminal_width;
extern unsigned int status; extern unsigned int status;
extern char *global_path;
unsigned int btm_status; unsigned int btm_status;
void *thread_mid(){ void *thread_mid(){
dir tmp;
tmp.current_file = NULL;
tmp.file_list = NULL;
tmp.file_count = 0;
while(!(status & STATUS_QUIT_PROGRAM)){ while(!(status & STATUS_QUIT_PROGRAM)){
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;
char *path; if (global_path == NULL) {
if((path=getcwd(NULL, 0)) == NULL) { mid_dir.current_file = NULL;
mid_content = malloc(sizeof(file)); mid_dir.file_count = 0;
mid_content->file_name = "cannot open directory"; pthread_mutex_unlock(&mutex_mid);
mid_file_count = 1; continue;
} else { }
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) {
unsigned long i = 0; long index = mid_dir.current_file - mid_dir.file_list;
for (i = 0; i < mid_file_count; i++) {
free(mid_content[i].file_name);
}
free(mid_content);
mid_file_count = get_dir_size(path);
if (mid_file_count != 0) {
mid_content = malloc(mid_file_count * sizeof(file));
memset(mid_content, '\0', mid_file_count * sizeof(file));
get_dir_content(path, &mid_file_count, mid_content);
} else {
selected_file_current = 0;
mid_content = malloc(sizeof(file));
mid_content->file_type = 0;
mid_content->file_size = 0;
mid_content->permissions = 0;
mid_content->color_pair = 0;
mid_content->file_name = malloc(sizeof(char));
mid_content->file_name[0] = '\0';
mid_file_count = 0; tmp = mid_dir;
} mid_dir.file_count = get_dir_size(path);
pthread_mutex_lock(&mutex_selection); mid_dir.file_list = malloc(mid_dir.file_count * sizeof(file));
update_selected_file(); if (mid_dir.file_count) { /* fails if dir empty */
pthread_mutex_unlock(&mutex_selection); get_dir_content(path, &mid_dir);
mid_dir.current_file = &mid_dir.file_list[index];
} else { /* the hovered dir is empty */
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;
} }
btm_status = local_status;
pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_btm);
} }
free(path);
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_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);
}
wnoutrefresh(win_m);
pthread_mutex_unlock(&mutex_render);
unsigned long i;
for (i = 0; i < tmp.file_count; i++) {
free(tmp.file_list[i].file_name);
}
free(tmp.file_list);
tmp.current_file = NULL;
tmp.file_list = NULL;
tmp.file_count = 0;
} }
pthread_exit(0); pthread_exit(0);
} }
@@ -110,29 +140,51 @@ 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;
char *path; if (global_path == NULL) {
if((path=getcwd(NULL, 0)) == NULL) { lft_dir.current_file = NULL;
lft_content = malloc(sizeof(file)); lft_dir.file_count = 0;
lft_content[0].file_name = "cannot open directory"; pthread_mutex_unlock(&mutex_lft);
lft_file_count = 1; continue;
} else { }
char *path = malloc(strlen(global_path)+1);
memcpy(path, global_path, strlen(global_path)+1);
if (strcmp(path, "/") != 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) {
lft_file_count = get_dir_size(path); unsigned long i = 0;
free(lft_content); for (i = 0; i < lft_dir.file_count; i++) {
lft_content = malloc(lft_file_count * sizeof(file)); free(lft_dir.file_list[i].file_name);
memset(lft_content, '\0', lft_file_count * sizeof(file)); }
get_dir_content(path, &lft_file_count, lft_content); free(lft_dir.file_list);
} lft_dir.file_count = get_dir_size(path);
if (lft_dir.file_count != 0) {
lft_dir.file_list = malloc(lft_dir.file_count * sizeof(file));
get_dir_content(path, &lft_dir);
} else {
lft_dir.current_file = NULL;
lft_dir.file_count = 0;
}
}
} else {
lft_dir.file_count = 0;
} }
free(path);
/* 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); pthread_mutex_unlock(&mutex_lft);
free(path);
} }
pthread_exit(0); pthread_exit(0);
@@ -140,85 +192,80 @@ void *thread_lft(){
} }
void *thread_rgt(){ void *thread_rgt(){
file file_current; dir tmp;
tmp.current_file = NULL;
tmp.file_list = NULL;
tmp.file_count = 0;
while(!(status & STATUS_QUIT_PROGRAM)){ while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_rgt); pthread_mutex_lock(&mutex_rgt);
pthread_cond_wait(&cond_rgt, &mutex_rgt); pthread_cond_wait(&cond_rgt, &mutex_rgt);
pthread_mutex_lock(&mutex_mid); pthread_mutex_lock(&mutex_mid);
char *path;
if (mid_file_count != 0) { char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
path = malloc(strlen(mid_content[selected_file_current].file_name) + 1); file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
memcpy(path, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)+1);
} else { rgt_dir.file_list = malloc(sizeof(file));
path = malloc(sizeof(char)); memcpy(rgt_dir.file_list, mid_dir.current_file, sizeof(file));
path[0] = '\0'; rgt_dir.file_list->file_name = file_name;
} rgt_dir.current_file = rgt_dir.file_list;
file_current.file_type = mid_content[selected_file_current].file_type; rgt_dir.file_count = 1;
file_current.file_size = mid_content[selected_file_current].file_size;
file_current.status = mid_content[selected_file_current].status;
pthread_mutex_unlock(&mutex_mid); pthread_mutex_unlock(&mutex_mid);
if (mid_content[selected_file_current].permissions & S_IRUSR) {
if (file_current.file_type &= FILE_TYPE_DIR) {
if (rgt_dir.current_file->permissions & S_IRUSR) {
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
unsigned long i = 0; tmp = rgt_dir;
for (i = 0; i < rgt_file_count; i++) {
if (rgt_content[i].file_name) {
free(rgt_content[i].file_name);
}
}
free(rgt_content);
rgt_file_count = get_dir_size(path); rgt_dir.file_count = get_dir_size(rgt_dir.current_file->file_name);
rgt_content = malloc(rgt_file_count * sizeof(file)); rgt_dir.file_list = malloc(rgt_dir.file_count * sizeof(file));
memset(rgt_content, '\0', rgt_file_count * sizeof(file)); if (rgt_dir.file_count) { /* fails if dir empty */
get_dir_content(path, &rgt_file_count, rgt_content); get_dir_content(tmp.current_file->file_name, &rgt_dir);
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN; } 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 && rgt_dir.file_count > 0) {
free(rgt_buffer); free(rgt_buffer);
rgt_buffer = malloc(sizeof(char)); rgt_buffer = preview_file(rgt_dir.current_file);
rgt_buffer[0] = '\0'; rgt_dir.current_file->file_type |= FILE_TYPE_OPEN_FILE;
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) { pthread_mutex_lock(&mutex_render);
werase(win_r);
unsigned long i = 0; if (rgt_dir.current_file->file_type & FILE_TYPE_OPEN_FILE) {
for (i = 0; i < rgt_file_count; i++) { mvwaddnstr(win_r, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
if (rgt_content[i].file_name) { } else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
free(rgt_content[i].file_name); mvwaddstr(win_r, 0, 0, "not accessible");
}
} }
free(rgt_content); wnoutrefresh(win_r);
rgt_file_count = 0; pthread_mutex_unlock(&mutex_render);
rgt_content = malloc(sizeof(file));
free(rgt_buffer);
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
rgt_content->status = FILE_STATUS_HOVER;
rgt_buffer = preview_file(path, file_current.file_size);
} }
} else {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
if (rgt_content[i].file_name) {
free(rgt_content[i].file_name);
}
}
free(rgt_content);
rgt_file_count = 0;
rgt_content = malloc(sizeof(file));
free(rgt_buffer);
rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0';
} }
free(path);
pthread_mutex_unlock(&mutex_rgt); pthread_mutex_unlock(&mutex_rgt);
unsigned long i;
for (i = 0; i < tmp.file_count; i++) {
free(tmp.file_list[i].file_name);
}
free(tmp.file_list);
tmp.current_file = NULL;
tmp.file_list = NULL;
tmp.file_count = 0;
} }
pthread_exit(0); pthread_exit(0);
} }
@@ -228,20 +275,39 @@ void *thread_top(){
pthread_mutex_lock(&mutex_top); pthread_mutex_lock(&mutex_top);
pthread_cond_wait(&cond_top, &mutex_top); pthread_cond_wait(&cond_top, &mutex_top);
free(top_buffer); free(top_buffer);
char *path; if(global_path == NULL) {
if((path=getcwd(NULL, 0)) == NULL) {
top_buffer = malloc(sizeof("cannot open directory")); top_buffer = malloc(sizeof("cannot open directory"));
top_width = sizeof("cannot open directory"); top_width = sizeof("cannot open directory");
top_buffer = "cannot open directory"; top_buffer = "cannot open directory";
} else { pthread_mutex_unlock(&mutex_top);
top_buffer = malloc(strlen(path)+1); continue;
memcpy(top_buffer, path, strlen(path)+1);
top_width = strlen(top_buffer);
} }
free(path); 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);
/* rendering */
pthread_mutex_lock(&mutex_render);
werase(win_t);
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); pthread_mutex_unlock(&mutex_top);
} }
pthread_exit(0); pthread_exit(0);
@@ -255,32 +321,26 @@ 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;
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;
float total_dir_size = 0; float total_dir_size = 0;
for(i = 0; i < mid_file_count; i++) { for(i = 0; i < mid_dir.file_count; i++) {
if ((mid_content[i].file_type & (FILE_TYPE_DIR)) != FILE_TYPE_DIR) { if ((mid_dir.file_list[i].file_type & (FILE_TYPE_DIR)) != FILE_TYPE_DIR) {
total_dir_size += mid_content[i].file_size; total_dir_size += mid_dir.file_list[i].file_size;
} }
} }
pthread_mutex_unlock(&mutex_mid); pthread_mutex_unlock(&mutex_mid);
if (path != NULL) {
/* sometimes NULL remains, need to do deeper analysis soon */
free(path);
path = NULL;
} else {
volatile static int debug_thread_btm;
debug_thread_btm++;
}
free(ui_btm_right_block); free(ui_btm_right_block);
if(path) {
free(path);
}
path = getcwd(NULL, 0); path = getcwd(NULL, 0);
struct statvfs fs; struct statvfs fs;
statvfs(path, &fs); statvfs(path, &fs);
@@ -337,36 +397,45 @@ void *thread_btm(){
if (buffer_width != terminal_width) { if (buffer_width != terminal_width) {
buffer_width = terminal_width; buffer_width = terminal_width;
free(btm_buffer); free(btm_buffer);
btm_buffer = malloc(buffer_width); btm_buffer = malloc(buffer_width+1);
memset(btm_buffer, ' ', buffer_width/2);
} }
memset(btm_buffer + (buffer_width/2), ' ', buffer_width/2); memset(btm_buffer, ' ', buffer_width);
btm_buffer[buffer_width] = '\0'; btm_buffer[buffer_width] = '\0';
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size); memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-'; btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-'; (S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-'; btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-'; btm_buffer[2] = (mid_dir.current_file->permissions & S_IWUSR) ? 'w' : '-';
btm_buffer[4] = (mid_content[selected_file_current].permissions & S_IRGRP) ? 'r' : '-'; btm_buffer[3] = (mid_dir.current_file->permissions & S_IXUSR) ? 'x' : '-';
btm_buffer[5] = (mid_content[selected_file_current].permissions & S_IWGRP) ? 'w' : '-'; btm_buffer[4] = (mid_dir.current_file->permissions & S_IRGRP) ? 'r' : '-';
btm_buffer[6] = (mid_content[selected_file_current].permissions & S_IXGRP) ? 'x' : '-'; btm_buffer[5] = (mid_dir.current_file->permissions & S_IWGRP) ? 'w' : '-';
btm_buffer[7] = (mid_content[selected_file_current].permissions & S_IROTH) ? 'r' : '-'; btm_buffer[6] = (mid_dir.current_file->permissions & S_IXGRP) ? 'x' : '-';
btm_buffer[8] = (mid_content[selected_file_current].permissions & S_IWOTH) ? 'w' : '-'; btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
btm_buffer[9] = (mid_content[selected_file_current].permissions & S_IXOTH) ? 'x' : '-'; 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 all possible inputs are done in user_interactions */
pthread_mutex_unlock(&mutex_btm); pthread_mutex_unlock(&mutex_btm);
} }
pthread_exit(0); pthread_exit(0);
} }
void threading_init(){ void threading_init(){
rgt_content = malloc(sizeof(file));
mid_content = malloc(sizeof(file));
lft_content = malloc(sizeof(file));
top_buffer = malloc(sizeof(char)); top_buffer = malloc(sizeof(char));
rgt_buffer = malloc(sizeof(char)); rgt_buffer = malloc(sizeof(char));
@@ -375,37 +444,21 @@ void threading_init(){
memset(rgt_buffer, '\0', sizeof(char)); memset(rgt_buffer, '\0', sizeof(char));
memset(btm_buffer, '\0', sizeof(char)); memset(btm_buffer, '\0', sizeof(char));
mid_content->file_type = 0;
mid_content->file_size = 0;
mid_content->file_name = malloc(sizeof(char));
mid_content->file_name[0] = '\0';
rgt_content->file_type = 0; pthread_mutex_init(&mutex_top, NULL);
rgt_content->file_size = 0; pthread_mutex_init(&mutex_mid, NULL);
rgt_content->file_name = malloc(sizeof(char)); pthread_mutex_init(&mutex_lft, NULL);
rgt_content->file_name[0] = '\0'; pthread_mutex_init(&mutex_btm, NULL);
pthread_mutex_init(&mutex_rgt, 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);
pthread_cond_init(&cond_top, NULL);
pthread_cond_init(&cond_btm, NULL);
volatile char vol; /* needed to make sure higher optimization steps dont move these around */
vol = pthread_mutex_init(&mutex_top, NULL);
vol = pthread_mutex_init(&mutex_mid, NULL);
vol = pthread_mutex_init(&mutex_lft, NULL);
vol = pthread_mutex_init(&mutex_btm, NULL);
vol = pthread_mutex_init(&mutex_rgt, NULL);
vol = pthread_mutex_init(&mutex_selection, NULL);
vol = pthread_cond_init(&cond_rgt, NULL);
vol = pthread_cond_init(&cond_lft, NULL);
vol = pthread_cond_init(&cond_mid, NULL);
vol = pthread_cond_init(&cond_top, NULL);
vol = pthread_cond_init(&cond_btm, NULL);
vol;
selected_file_current = 0;
selected_file_last = 0;
} }
void threading_free(){ void threading_free(){
free(rgt_content);
free(mid_content);
free(lft_content);
free(top_buffer); free(top_buffer);
pthread_mutex_destroy(&mutex_top); pthread_mutex_destroy(&mutex_top);

View File

@@ -14,17 +14,14 @@ extern unsigned int timeout_time;
extern unsigned int color_count; extern unsigned int color_count;
extern color *colors; extern color *colors;
extern file *mid_content; extern dir rgt_dir;
extern file *lft_content; extern dir mid_dir;
extern file *rgt_content; extern dir lft_dir;
extern char *top_buffer; extern char *top_buffer;
extern char *rgt_buffer; extern char *rgt_buffer;
extern char *btm_buffer; extern char *btm_buffer;
extern unsigned long lft_file_count;
extern unsigned long mid_file_count;
extern unsigned long rgt_file_count;
extern unsigned long top_width; extern unsigned long top_width;
extern pthread_mutex_t mutex_top; extern pthread_mutex_t mutex_top;
@@ -34,22 +31,26 @@ extern pthread_mutex_t mutex_mid;
extern pthread_mutex_t mutex_rgt; extern pthread_mutex_t mutex_rgt;
void window_top(WINDOW *win){ void window_top(WINDOW *win){
werase(win);
if (pthread_mutex_trylock(&mutex_top) == 0) { if (pthread_mutex_trylock(&mutex_top) == 0) {
wattron(win, COLOR_PAIR(COLOR_PATH));
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*/
wattron(win, COLOR_PAIR(COLOR_PATH));
mvwaddstr(win, 0, 0, top_buffer); 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);
}
} }
wattroff(win, COLOR_PAIR(COLOR_PATH));
pthread_mutex_unlock(&mutex_top); pthread_mutex_unlock(&mutex_top);
} else { } else {
mvwaddstr(win, 0, terminal_width/2, "LOADING"); mvwaddstr(win, 0, terminal_width/2, "LOADING");
status |= STATUS_UPDATE_SCREEN_0; /*
status |= STATUS_UPDATE_SCREEN_GENERIC;
*/
} }
} }
void window_btm(WINDOW *win, char force_render){ void window_btm(WINDOW *win){
werase(win);
if (pthread_mutex_trylock(&mutex_btm) == 0) { if (pthread_mutex_trylock(&mutex_btm) == 0) {
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*/
@@ -58,62 +59,60 @@ void window_btm(WINDOW *win, char force_render){
pthread_mutex_unlock(&mutex_btm); pthread_mutex_unlock(&mutex_btm);
/*the printing of the input char is done in user_interactions*/ /*the printing of the input char is done in user_interactions*/
/*the printing of all possible inputs are done in user_interactions */ /*the printing of all possible inputs are done in user_interactions */
} else if (force_render) { } else {
/*force_render is used in stuff like open_with, search, and other functions that take over win_b,
* while needing to avoid possible conflicts like thread_btm itself*/
mvwprintw(win, 0, 0, "%s", btm_buffer);
} else {
mvwaddstr(win, 0, terminal_width/2, "LOADING"); mvwaddstr(win, 0, terminal_width/2, "LOADING");
status |= STATUS_UPDATE_SCREEN_0; /*
status |= STATUS_UPDATE_SCREEN_GENERIC;
*/
} }
} }
void window_lft(WINDOW *win){ void window_lft(WINDOW *win){
werase(win);
if (pthread_mutex_trylock(&mutex_lft) == 0) { if (pthread_mutex_trylock(&mutex_lft) == 0) {
print_dir(win, 0, &lft_file_count, lft_content); print_dir(win, 0, &lft_dir);
pthread_mutex_unlock(&mutex_lft); pthread_mutex_unlock(&mutex_lft);
} else { } else {
mvwaddstr(win, terminal_height/2, terminal_width/8, "LOADING"); mvwaddstr(win, terminal_height/2, terminal_width/8, "LOADING");
status |= STATUS_UPDATE_SCREEN_0; /*
status |= STATUS_UPDATE_SCREEN_GENERIC;
*/
} }
} }
void window_mid(WINDOW *win){ void window_mid(WINDOW *win){
werase(win);
if (pthread_mutex_trylock(&mutex_mid) == 0) { if (pthread_mutex_trylock(&mutex_mid) == 0) {
if (mid_file_count == 0) { if (mid_dir.file_count == 0) {
mvwaddstr(win, 0, 0, "empty"); mvwaddstr(win, 0, 0, "empty");
} else { } else {
print_dir(win, 1, &mid_file_count, mid_content); print_dir(win, 1, &mid_dir);
} }
pthread_mutex_unlock(&mutex_mid); pthread_mutex_unlock(&mutex_mid);
} else { } else {
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING"); mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_0; /*
status |= STATUS_UPDATE_SCREEN_GENERIC;
*/
} }
} }
void window_rgt(WINDOW *win){ void window_rgt(WINDOW *win){
werase(win);
if (pthread_mutex_trylock(&mutex_rgt) == 0) { if (pthread_mutex_trylock(&mutex_rgt) == 0) {
if (rgt_file_count == 0) { if (!rgt_dir.current_file) {
if (rgt_content[0].file_type == FILE_TYPE_OPEN_FILE) { mvwaddstr(win, 0, 0, "not accessible");
mvwaddnstr(win, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width); }else if (rgt_dir.current_file->file_type == FILE_TYPE_OPEN_FILE) {
} else if (rgt_content->permissions & S_IRUSR) { mvwaddnstr(win, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
mvwaddstr(win, 0, 0, "not accessible"); } else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
} else { mvwaddstr(win, 0, 0, "not accessible");
mvwaddstr(win, 0, 0, "empty");
}
} else { } else {
print_dir(win, 0, &rgt_file_count, rgt_content); print_dir(win, 0, &rgt_dir);
} }
pthread_mutex_unlock(&mutex_rgt); pthread_mutex_unlock(&mutex_rgt);
} else { } else {
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING"); mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_0; /*
status |= STATUS_UPDATE_SCREEN_GENERIC;
*/
} }
} }

View File

@@ -1,7 +1,7 @@
#include "window.c" #include "window.c"
void window_top(WINDOW *win); void window_top(WINDOW *win);
void window_btm(WINDOW *win, char force_render); void window_btm(WINDOW *win);
void window_lft(WINDOW *win); void window_lft(WINDOW *win);
void window_mid(WINDOW *win); void window_mid(WINDOW *win);
void window_rgt(WINDOW *win); void window_rgt(WINDOW *win);