Compare commits
96 Commits
0b98e8eb68
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a31f452ea | ||
|
|
daf43daa00 | ||
|
|
cf03a230b6 | ||
|
|
87bfdd1b86 | ||
|
|
20fee198ae | ||
|
|
632904fd89 | ||
|
|
dd5307b411 | ||
|
|
41933eb6d0 | ||
|
|
0a45d1e3e8 | ||
|
|
d33ac88de2 | ||
|
|
e42d55e66a | ||
|
|
f6380ddeda | ||
|
|
905f6e8588 | ||
|
|
095cf7b357 | ||
|
|
9f7ed73885 | ||
|
|
41af25e0b1 | ||
|
|
f807fe56b5 | ||
|
|
adb10b6d5d | ||
|
|
c692a1a992 | ||
|
|
8c80a6e3da | ||
|
|
1aa66c82fb | ||
|
|
f5d0c8bc85 | ||
|
|
9e8bd3c022 | ||
|
|
f40cc91cce | ||
|
|
a5483335c5 | ||
|
|
a7d4a6322c | ||
|
|
749dba1ce8 | ||
|
|
ac0b644bcb | ||
|
|
b4acda1aa6 | ||
|
|
b7124cbb1d | ||
|
|
adac32fcc1 | ||
|
|
dcb47d420b | ||
|
|
689565f732 | ||
|
|
58f99eb2cf | ||
|
|
673c7e5414 | ||
|
|
93c70aa07a | ||
|
|
edcf093269 | ||
|
|
557e0eb416 | ||
|
|
3c0f26efee | ||
|
|
491c00b9d4 | ||
|
|
955d8f439b | ||
|
|
d9d1ed115d | ||
|
|
41293c6afd | ||
|
|
1a85a2d810 | ||
|
|
e5625ada08 | ||
|
|
b639ad3998 | ||
|
|
1711926003 | ||
|
|
6372dbba69 | ||
|
|
acb7db1617 | ||
|
|
da4c90d243 | ||
|
|
ac50d377ca | ||
|
|
a64982857a | ||
|
|
3d47e0410f | ||
|
|
f53fd66d88 | ||
|
|
7e4ae9bb84 | ||
|
|
36c8524a70 | ||
|
|
99ac76162f | ||
|
|
1d3b71b00f | ||
|
|
84b1c17dd8 | ||
|
|
1f1de78283 | ||
|
|
f3a39b0df0 | ||
|
|
8734fa6ae4 | ||
|
|
66f3f3bef6 | ||
|
|
393864c80f | ||
|
|
217884d920 | ||
|
|
3a891388ed | ||
|
|
0bdb4a1a0a | ||
|
|
ddcf4d4105 | ||
|
|
be9436570c | ||
|
|
74166f7283 | ||
|
|
9a67b35ebe | ||
|
|
1e99e9d364 | ||
|
|
dd7f5634e2 | ||
|
|
5287c77648 | ||
|
|
5b7f017588 | ||
|
|
33d7761329 | ||
|
|
0970c43c37 | ||
|
|
79f8c82338 | ||
|
|
67b99b1cec | ||
|
|
4229ebe1d5 | ||
|
|
3da05ce27f | ||
|
|
d5a816ae38 | ||
|
|
cbd479ff4f | ||
|
|
7450280c43 | ||
|
|
326d3f7e52 | ||
|
|
df726e2f32 | ||
|
|
140457e4b7 | ||
|
|
23654741bc | ||
|
|
fa544204ba | ||
|
|
61023ce42e | ||
|
|
3fa16fd8b2 | ||
|
|
ac6d0e8408 | ||
|
|
731bfe722a | ||
|
|
3082fed378 | ||
|
|
23ff0b07ec | ||
|
|
c2d88f4909 |
7
Makefile
7
Makefile
@@ -1,8 +1,7 @@
|
||||
CC := gcc
|
||||
CFLAGS := -Wall -Wextra -O2 -flto=auto
|
||||
CURSES := -lncursesw -ltinfow #utf8 support
|
||||
#CURSES := -lncurses -tinfo #no utf8
|
||||
CFLAGS_DEBUG := $(CFLAGS) -g
|
||||
CFLAGS := -Wall -Wextra -O3 -flto=auto
|
||||
CURSES := $(shell pkg-config --libs ncursesw)
|
||||
CFLAGS_DEBUG := $(CFLAGS) -ggdb
|
||||
CFLAGS_PROFILE := $(CFLAGS) -pg
|
||||
GDB := gdb --tui ./th
|
||||
VALGRIND := valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --log-fd=9 9>>valgrind.log ./th
|
||||
|
||||
136
backend.c
136
backend.c
@@ -1,15 +1,43 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
|
||||
char* concat(const char *s1, const char *s2){
|
||||
const size_t len1 = strlen(s1);
|
||||
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 concat(out, s1, s2, _free) { \
|
||||
concat## _free(out, s1, s2); \
|
||||
}
|
||||
char* smartstrcasestr(char *haystack, const char *needle){
|
||||
|
||||
#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 smart = 0;
|
||||
char *ret;
|
||||
char passes = 0;
|
||||
@@ -24,7 +52,7 @@ char* smartstrcasestr(char *haystack, const char *needle){
|
||||
needle -= passes;
|
||||
if (smart == 0) {
|
||||
char *needle_case = malloc(strlen(needle)+1);
|
||||
strcpy(needle_case, needle);
|
||||
memcpy(needle_case, needle, strlen(needle)+1);
|
||||
passes = 0;
|
||||
while (*needle_case) {
|
||||
*needle_case = *needle_case | ' ';
|
||||
@@ -34,7 +62,7 @@ char* smartstrcasestr(char *haystack, const char *needle){
|
||||
needle_case -= passes;
|
||||
|
||||
char *haystack_case = malloc(strlen(haystack)+1);
|
||||
strcpy(haystack_case, haystack);
|
||||
memcpy(haystack_case, haystack, strlen(haystack)+1);
|
||||
passes = 0;
|
||||
while (*haystack_case) {
|
||||
*haystack_case = *haystack_case | ' ';
|
||||
@@ -52,3 +80,91 @@ char* smartstrcasestr(char *haystack, const char *needle){
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -5,5 +5,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
char* concat(const char *s1, const char *s2);
|
||||
char* smartstrcasestr(char *haystack, const char *needle);
|
||||
/*char* concat(const char *s1, const char *s2);*/
|
||||
char* smartstrcasestr(const char *haystack, const char *needle);
|
||||
char* parse_cmd(const char *cmd, file *f);
|
||||
|
||||
|
||||
8
colors.c
8
colors.c
@@ -9,9 +9,6 @@
|
||||
unsigned int color_count;
|
||||
color *colors;
|
||||
|
||||
extern file *rgt_content;
|
||||
extern unsigned long rgt_file_count;
|
||||
|
||||
extern unsigned int settings;
|
||||
extern unsigned int status;
|
||||
|
||||
@@ -105,10 +102,9 @@ void colors_init() {
|
||||
while (getline(&line, &size, dircolors) != -1) {
|
||||
fg = 7;
|
||||
bg = 0;
|
||||
if (line[0] == '.') {
|
||||
extension = strtok(line, " ");
|
||||
if (line[0] == '.' && (extension = strtok(line, " ")) != NULL) {
|
||||
colors[i].file_extension = malloc(strlen(extension)+1);
|
||||
strcpy(colors[i].file_extension, extension);
|
||||
memcpy(colors[i].file_extension, extension, strlen(extension)+1);
|
||||
|
||||
colors[i].color_pair = i+11;
|
||||
parse_colors(line, &fg, &bg);
|
||||
|
||||
64
config.h
64
config.h
@@ -1,6 +1,10 @@
|
||||
#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_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds of how often the directory should be reload */
|
||||
#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 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
|
||||
@@ -10,6 +14,11 @@
|
||||
#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[] = {
|
||||
/* mimetype shell command
|
||||
* ^ 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,
|
||||
* we need to define "gif" before "image" */
|
||||
{ "text", "$EDITOR" },
|
||||
{ "gif", "mpv --loop-file=\"inf\"" },
|
||||
{ "image", "feh" },
|
||||
{ "video", "mpv" },
|
||||
{ "avif", "@ mpv" },
|
||||
{ "gif", "@ mpv --loop-file=\"inf\"" },
|
||||
{ "image", "@ feh" },
|
||||
{ "video", "@ mpv" },
|
||||
{ "audio", "mpv" },
|
||||
{ "pdf", "zathura" },
|
||||
{ "pdf", "@ zathura" },
|
||||
};
|
||||
static const extension file_extension_default_cmd[] = {
|
||||
/* extension shell command
|
||||
* similar to mimetype_default_cmd, however it searches for exact string matches
|
||||
* and is checked before mimetype_default_cmd */
|
||||
{ ".exe", "wine"},
|
||||
{ ".cbz", "mcomix"},
|
||||
{ ".cbr", "mcomix"},
|
||||
{ ".cbz", "@ mcomix"},
|
||||
{ ".cbr", "@ mcomix"},
|
||||
{ ".json", "$EDITOR"},
|
||||
{ ".csv", "$EDITOR"},
|
||||
{ ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */
|
||||
};
|
||||
static const binding key_binding[] = {
|
||||
/*key action blackmagic comment*/
|
||||
/*key action blackmagic comment*/
|
||||
/*you cannot add bindings that include other bindings in its entirety
|
||||
* possible: mk, mf
|
||||
* not possible: gg, ggg
|
||||
@@ -48,6 +59,7 @@ static const binding key_binding[] = {
|
||||
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" },
|
||||
{ "/", search, NULL, "search" },
|
||||
{ ":", jmp_file_index, NULL, "jump to file on input number" },
|
||||
{ "l", search_next, NULL, "search next" },
|
||||
{ "L", search_previous, NULL, "search previous" },
|
||||
|
||||
@@ -56,12 +68,12 @@ static const binding key_binding[] = {
|
||||
{ "n", move_up, NULL, "move up" },
|
||||
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||
|
||||
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
|
||||
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* execute shell cmd on file, accounts for SETTINGS_COMMAND_FORK */
|
||||
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
||||
* this means that it does not delete the hovered files if files are already selected */
|
||||
{ "yn", yank_text, "name", "yank filename of hovered file" },
|
||||
{ "yp", yank_text, "path", "yank path of hovered file" },
|
||||
{ "yn", yank_file_name, NULL, "yank filename of hovered file" },
|
||||
{ "yp", yank_file_path, NULL, "yank path of hovered file" },
|
||||
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
||||
{ "dd", yank_file, "cut", "cut file/directory" },
|
||||
{ "pp", paste, NULL, "paste" },
|
||||
@@ -69,8 +81,11 @@ static const binding key_binding[] = {
|
||||
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
||||
{ "gg", jump_top, NULL, "jump to first file in dir" },
|
||||
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
||||
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
|
||||
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" }, /* the path you started th in */
|
||||
{ "gD", jump_to_dir, "$HOME/Downloads", "jump to $HOME/Downloads" },
|
||||
{ "gC", jump_to_dir, "$HOME/Documents", "jump to $HOME/Documents" },
|
||||
{ "gP", jump_to_dir, "$HOME/Pictures", "jump to $HOME/Pictures" },
|
||||
{ "gM", jump_to_dir, "$HOME/Music", "jump to $HOME/Music" },
|
||||
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
||||
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
||||
{ "gp", jump_to_dir, "/etc/portage", "jump to /etc/portage" },
|
||||
@@ -78,6 +93,7 @@ static const binding key_binding[] = {
|
||||
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
||||
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
||||
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
||||
{ "gu", jump_to_dir, "/usr", "jump to /usr" },
|
||||
|
||||
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
||||
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
||||
@@ -85,13 +101,13 @@ static const binding key_binding[] = {
|
||||
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
|
||||
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
|
||||
{ "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" },
|
||||
{ "or", not_implemented, "", "order reverse" },
|
||||
{ "oe", not_implemented, "", "order extension" },
|
||||
{ "oe", order_by, sort_extension, "order extension" },
|
||||
{ "os", order_by, sort_size, "order size" },
|
||||
{ "ot", order_by, sort_type, "order type" },
|
||||
{ "oz", order_by, sort_random, "order random" },
|
||||
{ "or", order_by, sort_random, "order random" },
|
||||
{ "oa", order_by, sort_alpha, "order alphabetically" },
|
||||
|
||||
{ "mk", makedir, NULL, "create directory" },
|
||||
@@ -103,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 clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
|
||||
static const char ui_btm_text_storage_left[] = "total free";
|
||||
static const char ui_btm_current_dir_size[] = "sum of dir";
|
||||
static const char ui_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);
|
||||
@@ -114,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;
|
||||
#else
|
||||
static const char clipboard_cmd[];
|
||||
static const char rename_cmd[];
|
||||
static const char makefile_cmd[];
|
||||
static const char makedir_cmd[];
|
||||
static const mimetype mimetype_default_cmd[];
|
||||
static const extension file_extension_default_cmd[];
|
||||
static const binding key_binding[];
|
||||
@@ -122,5 +145,10 @@ static const unsigned long mimetype_default_count;
|
||||
static const unsigned long file_extension_default_count;
|
||||
static const char size_unit[];
|
||||
static const char size_unit_count;
|
||||
static const char ui_open_with_text[];
|
||||
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
|
||||
/* }}} */
|
||||
|
||||
28
defines.h
28
defines.h
@@ -3,15 +3,23 @@
|
||||
#define STATUS_QUIT_PROGRAM 1
|
||||
#define STATUS_RUN_BACKEND 2
|
||||
#define STATUS_RELOAD_DIRECTORY 4
|
||||
#define STATUS_UPDATE_SCREEN_MASK 24 /* 11000 */
|
||||
#define STATUS_UPDATE_SCREEN_0 8
|
||||
#define STATUS_UPDATE_ASYNC_REFRESH 8
|
||||
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
||||
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
||||
#define STATUS_USER_ROOT 64
|
||||
#define STATUS_INPUT_MATCH 128
|
||||
#define STATUS_UPDATE_SCREEN_CLEAR 32
|
||||
#define STATUS_UPDATE_SCREEN_MASK (STATUS_UPDATE_ASYNC_REFRESH | STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)
|
||||
#define STATUS_USER_ROOT 128
|
||||
#define STATUS_INPUT_MATCH 256
|
||||
#define STATUS_DELTA_TIME 512
|
||||
#define STATUS_MOVE_RIGHT_MATCH 1024
|
||||
|
||||
#define SETTINGS_HAS_COLOR 1
|
||||
|
||||
#define RENDER_QUEUE_TOP 0
|
||||
#define RENDER_QUEUE_LFT 1
|
||||
#define RENDER_QUEUE_MID 2
|
||||
#define RENDER_QUEUE_RGT 3
|
||||
#define RENDER_QUEUE_BTM 4
|
||||
|
||||
#define FILE_MODIFIERS_HIDDEN_FILES 1
|
||||
#define FILE_MODIFIERS_SORT_BITMASK 126 /* 00000000000000000000000001111110*/
|
||||
#define FILE_MODIFIERS_SORT_ALPHABETIC 2
|
||||
@@ -55,6 +63,9 @@
|
||||
#define YANK_CUT 2
|
||||
#define YANK_COPY 4
|
||||
|
||||
#define BTM_WINDOW_HEIGHT_ON_STR_INTERACTION 5
|
||||
#define INPUT_BUFFER_SIZE 255
|
||||
|
||||
#ifndef STRUCT_GUARD
|
||||
#define STRUCT_GUARD
|
||||
/* complex types are good actually */
|
||||
@@ -66,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 */
|
||||
char *file_name;
|
||||
} file;
|
||||
typedef struct Dir {
|
||||
file *current_file;
|
||||
file *file_list;
|
||||
unsigned long file_count;
|
||||
} dir;
|
||||
typedef struct Color {
|
||||
char *file_extension;
|
||||
short color_pair;
|
||||
@@ -92,7 +108,7 @@ typedef struct Yank {
|
||||
} yank;
|
||||
typedef struct Linked_dir {
|
||||
char *path;
|
||||
unsigned long selected_file_current;
|
||||
unsigned long index;
|
||||
struct Linked_dir *next;
|
||||
} linked_dir;
|
||||
|
||||
|
||||
335
dir.c
335
dir.c
@@ -12,126 +12,125 @@
|
||||
#include "config.h"
|
||||
|
||||
|
||||
extern file *mid_content;
|
||||
extern unsigned long mid_file_count;
|
||||
extern dir mid_dir;
|
||||
extern unsigned int settings;
|
||||
extern unsigned int file_modifiers;
|
||||
extern unsigned int color_count;
|
||||
extern unsigned int terminal_height;
|
||||
extern volatile unsigned long selected_file_current;
|
||||
extern volatile unsigned long selected_file_last;
|
||||
extern char *global_path;
|
||||
extern color *colors;
|
||||
int (*order_func)() = sort_natural;
|
||||
linked_dir *visited_dirs;
|
||||
linked_dir *current_dir;
|
||||
|
||||
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);
|
||||
|
||||
linked_dir *list_beginning;
|
||||
linked_dir *current_linked_dir;
|
||||
|
||||
|
||||
unsigned long get_dir_size(char *path){
|
||||
DIR *dir = opendir(path);
|
||||
unsigned long entry_count = 0;
|
||||
struct dirent *entry;
|
||||
if (dir && file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||
while ((entry=readdir(dir))) {
|
||||
entry_count++;
|
||||
}
|
||||
/* removes files "." and ".." */
|
||||
entry_count -= 2;
|
||||
} else if (dir) {
|
||||
while ((entry=readdir(dir))) {
|
||||
if (entry->d_name[0] != '.') {
|
||||
if (dir) {
|
||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||
while ((entry=readdir(dir))) {
|
||||
entry_count++;
|
||||
}
|
||||
}
|
||||
/* removes files "." and ".." */
|
||||
entry_count -= 2;
|
||||
} else {
|
||||
while ((entry=readdir(dir))) {
|
||||
if (entry->d_name[0] != '.') {
|
||||
entry_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
closedir(dir);
|
||||
return entry_count;
|
||||
|
||||
}
|
||||
|
||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
|
||||
struct dirent **entry;
|
||||
void get_dir_content(char *path, dir *dir){
|
||||
struct dirent **entry = NULL;
|
||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
||||
scandir(path, &entry, skip_dot, NULL);
|
||||
} else {
|
||||
scandir(path, &entry, skip_hidden_files, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *full_path = NULL;
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < *dir_file_count; i++ ) {
|
||||
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)) {
|
||||
} else {
|
||||
dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1);
|
||||
strcpy(dir_content[i].file_name, entry[i]->d_name);
|
||||
dir->file_list[i].file_name = malloc(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;
|
||||
file = malloc(sizeof(struct stat));
|
||||
|
||||
/* 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 + strlen(path) + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
||||
full_path[strlen(path)] = '/';
|
||||
|
||||
lstat(full_path, file);
|
||||
|
||||
dir_content[i].file_size = file->st_size;
|
||||
dir_content[i].permissions = file->st_mode;
|
||||
dir->file_list[i].file_size = file->st_size;
|
||||
dir->file_list[i].permissions = file->st_mode;
|
||||
|
||||
if (S_ISDIR(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)) {
|
||||
if (S_ISLNK(file->st_mode)) {
|
||||
stat(full_path, file);
|
||||
if (S_ISDIR(file->st_mode)) {
|
||||
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
||||
dir_content[i].file_size = get_dir_size(full_path);
|
||||
dir->file_list[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
||||
dir->file_list[i].color_pair = COLOR_SYMLINK;
|
||||
dir->file_list[i].file_size = get_dir_size(full_path);
|
||||
} else {
|
||||
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
|
||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
||||
dir->file_list[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_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) {
|
||||
dir_content[i].file_type = FILE_TYPE_EXEC;
|
||||
dir_content[i].color_pair = COLOR_EXEC;
|
||||
dir->file_list[i].file_type = FILE_TYPE_EXEC;
|
||||
dir->file_list[i].color_pair = COLOR_EXEC;
|
||||
} else if (S_ISREG(file->st_mode)) {
|
||||
dir_content[i].file_type = FILE_TYPE_REGULAR;
|
||||
dir_content[i].color_pair = COLOR_REGULAR;
|
||||
dir->file_list[i].file_type = FILE_TYPE_REGULAR;
|
||||
dir->file_list[i].color_pair = COLOR_REGULAR;
|
||||
unsigned long j = 0;
|
||||
char *extension = strrchr(entry[i]->d_name, '.');
|
||||
if (extension) {
|
||||
for (j = 0; j < color_count; j++) {
|
||||
if (!strncmp(colors[j].file_extension, extension, strlen(colors[j].file_extension))) {
|
||||
dir_content[i].color_pair = colors[j].color_pair;
|
||||
if (!strcmp(colors[j].file_extension, extension)) {
|
||||
dir->file_list[i].color_pair = colors[j].color_pair;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (S_ISBLK(file->st_mode)) {
|
||||
dir_content[i].file_type = FILE_TYPE_BLOCK;
|
||||
dir_content[i].color_pair = COLOR_BLOCK;
|
||||
dir->file_list[i].file_type = FILE_TYPE_BLOCK;
|
||||
dir->file_list[i].color_pair = COLOR_BLOCK;
|
||||
} 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)) {
|
||||
dir_content[i].file_type = FILE_TYPE_FIFO;
|
||||
dir_content[i].color_pair = COLOR_FIFO;
|
||||
dir->file_list[i].file_type = FILE_TYPE_FIFO;
|
||||
dir->file_list[i].color_pair = COLOR_FIFO;
|
||||
} else if (S_ISSOCK(file->st_mode)) {
|
||||
dir_content[i].file_type = FILE_TYPE_SOCK;
|
||||
dir_content[i].color_pair = COLOR_SOCK;
|
||||
dir->file_list[i].file_type = FILE_TYPE_SOCK;
|
||||
dir->file_list[i].color_pair = COLOR_SOCK;
|
||||
} else {
|
||||
dir_content[i].file_type = COLOR_REGULAR;
|
||||
dir_content[i].color_pair = COLOR_REGULAR;
|
||||
dir->file_list[i].file_type = COLOR_REGULAR;
|
||||
dir->file_list[i].color_pair = COLOR_REGULAR;
|
||||
unsigned long j = 0;
|
||||
char *extension = strrchr(entry[i]->d_name, '.');
|
||||
if (extension) {
|
||||
for (j = 0; j < color_count; j++) {
|
||||
if (!strncmp(colors[j].file_extension, extension, strlen(colors[j].file_extension))) {
|
||||
dir_content[i].color_pair = colors[j].color_pair;
|
||||
if (!strcmp(colors[j].file_extension, extension)) {
|
||||
dir->file_list[i].color_pair = colors[j].color_pair;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -139,26 +138,20 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
||||
}
|
||||
free(full_path);
|
||||
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[i]);
|
||||
}
|
||||
free(entry);
|
||||
|
||||
}
|
||||
|
||||
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 */
|
||||
unsigned long line_width = getmaxx(win);
|
||||
|
||||
char *bg = malloc(line_width+1);
|
||||
memset(bg, ' ', line_width);
|
||||
bg[line_width] = '\0';
|
||||
|
||||
unsigned long i = 0;
|
||||
float file_size;
|
||||
float printed_size = 0;
|
||||
@@ -172,22 +165,23 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
||||
#else
|
||||
long offset_front = 2;
|
||||
#endif
|
||||
unsigned long selected_file_current = dir->current_file - dir->file_list;
|
||||
|
||||
long offset_index = 2; /* only used for the index of the file itself */
|
||||
if (print_info) {
|
||||
if (*dir_file_count > 9) {
|
||||
if (dir->file_count > 9) {
|
||||
|
||||
#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) {
|
||||
offset_front++;
|
||||
dir_file_count_ /= 10;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (selected_file_current > (terminal_height/3)*2 && *dir_file_count > terminal_height - 2) {
|
||||
if (selected_file_current + (terminal_height/3) >= *dir_file_count) {
|
||||
offset_vertical = *dir_file_count - terminal_height+2;
|
||||
if (selected_file_current > (terminal_height/3)*2 && dir->file_count > terminal_height - 2) {
|
||||
if (selected_file_current + (terminal_height/3) >= dir->file_count) {
|
||||
offset_vertical = dir->file_count - terminal_height+2;
|
||||
} else {
|
||||
offset_vertical = selected_file_current - (terminal_height/3)*2;
|
||||
}
|
||||
@@ -195,12 +189,12 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
||||
} else {
|
||||
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) {
|
||||
file_size = dir_content[i].file_size;
|
||||
file_size = dir->file_list[i].file_size;
|
||||
char size_index = -1;
|
||||
|
||||
do {
|
||||
@@ -210,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);
|
||||
size_char = size_unit[(unsigned)size_index];
|
||||
|
||||
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
||||
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1);
|
||||
if (dir->file_list[i].file_type & FILE_TYPE_DIR) {
|
||||
offset_back = line_width - (snprintf(NULL,0,"%ld", dir->file_list[i].file_size) + 1);
|
||||
} else if (size_char =='B') {
|
||||
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
||||
} else {
|
||||
@@ -221,54 +215,29 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
||||
offset_back = line_width;
|
||||
}
|
||||
|
||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
|
||||
is_selected = 1;
|
||||
} else {
|
||||
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));
|
||||
} 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);
|
||||
unsigned long bg = 0;
|
||||
for (bg = 0; bg < line_width; bg++) {
|
||||
mvwaddch(win, i-offset_vertical, bg, ' ');
|
||||
}
|
||||
|
||||
} else {
|
||||
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;
|
||||
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 SETTINGS_LINE_NUMBERS == 2
|
||||
long i_ = (selected_file_current) - i;
|
||||
@@ -300,90 +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);
|
||||
#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) {
|
||||
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
||||
if (dir->file_list[i].file_type & FILE_TYPE_DIR) {
|
||||
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir->file_list[i].file_size);
|
||||
}else if (size_char =='B') {
|
||||
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
||||
} else {
|
||||
mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char);
|
||||
}
|
||||
} else {
|
||||
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
|
||||
}
|
||||
free(file_name);
|
||||
}
|
||||
char *extension = strrchr(dir->file_list[i].file_name, '.');
|
||||
|
||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||
unsigned long printable_size = offset_back-offset_front-is_selected-2;
|
||||
|
||||
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, dir->file_list[i].file_name, printable_size);
|
||||
if (extension && printable_size <= strlen(dir->file_list[i].file_name)) {
|
||||
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->file_list[i].status & FILE_STATUS_SELECTED) {
|
||||
wattroff(win, COLOR_PAIR(8));
|
||||
} 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);
|
||||
while(current_dir->next != NULL) {
|
||||
if (strcmp(path, current_dir->path) == 0) {
|
||||
hit = 1;
|
||||
current_linked_dir = list_beginning;
|
||||
while (current_linked_dir->next != NULL) {
|
||||
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||
break;
|
||||
} else {
|
||||
current_linked_dir = current_linked_dir->next;
|
||||
}
|
||||
current_dir = current_dir->next;
|
||||
}
|
||||
if (hit == 0) {
|
||||
current_dir->next = malloc(sizeof(linked_dir));
|
||||
current_dir->next->next = NULL;
|
||||
current_dir->next->path = path;
|
||||
return 0;
|
||||
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||
} else {
|
||||
free(path);
|
||||
return current_dir->selected_file_current;
|
||||
/**/
|
||||
|
||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
||||
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
||||
current_linked_dir->next->next = NULL;
|
||||
current_linked_dir->next->index = 0;
|
||||
|
||||
mid_dir.current_file = mid_dir.file_list;
|
||||
}
|
||||
|
||||
}
|
||||
void change_dir(char *new_path){
|
||||
|
||||
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(){
|
||||
visited_dirs = malloc(sizeof(linked_dir));
|
||||
visited_dirs->path = getcwd(NULL, 0);
|
||||
visited_dirs->selected_file_current = 0;
|
||||
visited_dirs->next = NULL;
|
||||
current_dir = visited_dirs;
|
||||
list_beginning = malloc(sizeof(linked_dir));
|
||||
list_beginning->path = getcwd(NULL, 0);
|
||||
list_beginning->index = 0;
|
||||
list_beginning->next = NULL;
|
||||
current_linked_dir = list_beginning;
|
||||
|
||||
}
|
||||
|
||||
void recursive_delete(file current_file){
|
||||
if (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;
|
||||
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
|
||||
unsigned long current_file_count = get_dir_size(current_file.file_name);
|
||||
@@ -410,4 +406,5 @@ void recursive_delete(file current_file){
|
||||
} else {
|
||||
remove(current_file.file_name);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
4
dir.h
4
dir.h
@@ -4,8 +4,8 @@
|
||||
#endif
|
||||
|
||||
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);
|
||||
void get_dir_content(char *path, dir *dir);
|
||||
void print_dir(WINDOW *win, char print_info, dir *dir);
|
||||
char update_selected_file();
|
||||
void dir_set_selected_file_current(unsigned long selected_file_current);
|
||||
unsigned long dir_get_selected_file_current();
|
||||
|
||||
@@ -13,26 +13,20 @@ extern unsigned int terminal_height;
|
||||
extern unsigned int terminal_width;
|
||||
char previewd;
|
||||
|
||||
char* text(char *path, unsigned long *file_size);
|
||||
char* text(file *f);
|
||||
void images_print(char *file_name);
|
||||
void images_clear();
|
||||
char* generic(char *path);
|
||||
char* generic(file *f);
|
||||
|
||||
char* get_mimetype(char *path){
|
||||
static char *cmd_str = "file --mime-type -b ./\"";
|
||||
unsigned long cmd_len = strlen(cmd_str);
|
||||
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';
|
||||
char* get_mimetype(file *f){
|
||||
static const char *cmd_str = "file --mime-type -b";
|
||||
char *cmd = parse_cmd(cmd_str, f);
|
||||
|
||||
FILE *cmd_open = popen(cmd, "r");
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
free(cmd);
|
||||
if (getline(&line, &size, cmd_open) != -1){
|
||||
pclose(cmd_open);
|
||||
return line;
|
||||
@@ -41,56 +35,59 @@ char* get_mimetype(char *path){
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
char* preview_file(char *file_name, unsigned long file_size){
|
||||
char* preview_file(file *f){
|
||||
/* this calls "file" on path */
|
||||
|
||||
char *file_buffer;
|
||||
|
||||
|
||||
char *mime = get_mimetype(file_name);
|
||||
char *mime = get_mimetype(f);
|
||||
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
images_clear();
|
||||
#endif
|
||||
|
||||
if (strstr(mime, "text")) {
|
||||
file_buffer = text(file_name, &file_size);
|
||||
file_buffer = text(f);
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
} else if (strstr(mime, "image")) {
|
||||
file_buffer = generic(file_name);
|
||||
images_print(file_name);
|
||||
file_buffer = generic(f);
|
||||
images_print(f->file_name);
|
||||
previewd = 1;
|
||||
#endif
|
||||
} else {
|
||||
file_buffer = generic(file_name);
|
||||
file_buffer = generic(f);
|
||||
}
|
||||
|
||||
free(mime);
|
||||
return file_buffer;
|
||||
|
||||
}
|
||||
char* text(char *path, unsigned long *file_size){
|
||||
char* text(file *f){
|
||||
|
||||
unsigned long size = (terminal_width/2) * terminal_height;
|
||||
if (size > *file_size) {
|
||||
size = *file_size;
|
||||
if (size > f->file_size) {
|
||||
size = f->file_size;
|
||||
}
|
||||
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) {
|
||||
fclose(fp);
|
||||
file_buffer[size] = '\0';
|
||||
return file_buffer;
|
||||
} else {
|
||||
fclose(fp);
|
||||
return "failed reading file";
|
||||
}
|
||||
}
|
||||
char* generic(char *path){
|
||||
char *cmd = concat("file ./\"", path);
|
||||
cmd = concat(cmd, "\"");
|
||||
char* generic(file *f){
|
||||
static const char *cmd_str = "file";
|
||||
char *cmd = parse_cmd(cmd_str, f);
|
||||
|
||||
FILE *cmd_open = popen(cmd, "r");
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
free(cmd);
|
||||
if (getline(&line, &size, cmd_open) != -1) {
|
||||
pclose(cmd_open);
|
||||
return line;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
char* preview_file(char *file_name, unsigned long file_size);
|
||||
char* get_mimetype(char *path);
|
||||
char* preview_file(file *f);
|
||||
char* get_mimetype(file *f);
|
||||
void images_clear();
|
||||
void ueberzug_init();
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
|
||||
1029
interactions.c
1029
interactions.c
@@ -1,6 +1,7 @@
|
||||
#include <curses.h>
|
||||
#include <pthread.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -11,52 +12,36 @@
|
||||
#include "dir.h"
|
||||
|
||||
|
||||
extern volatile unsigned long selected_file_current;
|
||||
extern volatile unsigned long selected_file_last;
|
||||
|
||||
extern unsigned int file_modifiers;
|
||||
extern pthread_mutex_t mutex_selection;
|
||||
extern pthread_mutex_t mutex_rgt;
|
||||
extern pthread_mutex_t mutex_mid;
|
||||
extern pthread_mutex_t mutex_btm;
|
||||
extern pthread_cond_t cond_rgt;
|
||||
extern file *mid_content;
|
||||
extern file *lft_content;
|
||||
extern file *rgt_content;
|
||||
extern pthread_mutex_t mutex_render;
|
||||
extern WINDOW *win_b;
|
||||
extern WINDOW *win_m;
|
||||
extern dir mid_dir;
|
||||
|
||||
extern unsigned int terminal_height;
|
||||
extern unsigned int terminal_width;
|
||||
|
||||
extern WINDOW *win_b;
|
||||
|
||||
extern char *rgt_buffer;
|
||||
extern char *btm_buffer;
|
||||
extern unsigned long mid_file_count;
|
||||
|
||||
extern unsigned int status;
|
||||
extern char *start_path;
|
||||
extern char *global_path;
|
||||
extern char *input;
|
||||
|
||||
extern time_t *seed;
|
||||
extern time_t seed;
|
||||
|
||||
char search_buffer[255];
|
||||
unsigned int timeout_time = 0;
|
||||
char search_buffer[INPUT_BUFFER_SIZE];
|
||||
unsigned int input_pass;
|
||||
int parsed_input_number;
|
||||
unsigned long parsed_input_number;
|
||||
yank yank_files = { 0 };
|
||||
|
||||
int read_string(WINDOW *win, int y, int x, char *str);
|
||||
int strcmp_offset(char *in0, char *in1, char offset);
|
||||
extern void render_pass();
|
||||
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){
|
||||
noraw();
|
||||
endwin();
|
||||
curs_set(1);
|
||||
echo();
|
||||
printf("ERROR in function %s: %s", function, str);
|
||||
}
|
||||
void user_interactions() {
|
||||
@@ -65,70 +50,64 @@ void user_interactions() {
|
||||
char ch;
|
||||
unsigned long i;
|
||||
unsigned long binding_matches = 0;
|
||||
static char binding_pass = 0;
|
||||
|
||||
|
||||
ch = getch();
|
||||
if(ch != ERR) {
|
||||
timeout(1); /* blocking timeout of getch() */
|
||||
input[input_pass] = ch;
|
||||
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
||||
input_pass++;
|
||||
if (ch == 27) { /* esc key */
|
||||
memset(input, ' ', terminal_width);
|
||||
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
||||
memset(input, 0, 255);
|
||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||
input_pass = 0;
|
||||
timeout(100); /* blocking timeout of getch() */
|
||||
}
|
||||
binding_pass = 0;
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void (*func_ptr)(int, int);
|
||||
unsigned long number_length = 0;
|
||||
|
||||
if (!binding_pass) {
|
||||
parsed_input_number = 0;
|
||||
while((*input >= '0') && (*input <= '9')) {
|
||||
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
||||
input++;
|
||||
number_length++;
|
||||
}
|
||||
input -= number_length;
|
||||
binding_pass = 1;
|
||||
parsed_input_number = 0;
|
||||
while((*input >= '0') && (*input <= '9')) {
|
||||
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
||||
input++;
|
||||
number_length++;
|
||||
}
|
||||
if (parsed_input_number == 0) {
|
||||
parsed_input_number = 1;
|
||||
}
|
||||
input -= number_length;
|
||||
|
||||
char cmp_len = strlen(input);
|
||||
if(strlen(input) < 1) {
|
||||
cmp_len++;
|
||||
}
|
||||
for (i = 0; i < binding_count; i++) {
|
||||
char cmp_len = strlen(input);
|
||||
if(strlen(input) < 1) {
|
||||
cmp_len = 1;
|
||||
}
|
||||
for (i = 0; i < binding_count; i++) {
|
||||
if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
||||
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
||||
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
func_ptr = key_binding[i].func;
|
||||
func_ptr(parsed_input_number, i);
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
|
||||
} else if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
||||
timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */
|
||||
} else {
|
||||
binding_matches++;
|
||||
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
|
||||
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "%s\t%s", key_binding[i].key, key_binding[i].comment);
|
||||
status |= STATUS_INPUT_MATCH;
|
||||
}
|
||||
}
|
||||
if (status & STATUS_INPUT_MATCH) {
|
||||
attron(A_UNDERLINE);
|
||||
mvaddstr(terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
|
||||
attroff(A_UNDERLINE);
|
||||
status &= ~STATUS_INPUT_MATCH;
|
||||
} else if (number_length != strlen(input)) {
|
||||
memset(input, 0, 255);
|
||||
input_pass = 0;
|
||||
binding_pass = 0;
|
||||
number_length = 0;
|
||||
timeout(100); /* blocking timeout of getch() */
|
||||
}
|
||||
}
|
||||
if (status & STATUS_INPUT_MATCH) {
|
||||
attron(A_UNDERLINE);
|
||||
mvwprintw(stdscr, terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
|
||||
attroff(A_UNDERLINE);
|
||||
status &= ~STATUS_INPUT_MATCH;
|
||||
} else if (number_length != strlen(input)) {
|
||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||
input_pass = 0;
|
||||
number_length = 0;
|
||||
binding_matches = 0;
|
||||
}
|
||||
}
|
||||
int read_string(WINDOW *win, int y, int x, char *str){
|
||||
@@ -148,783 +127,419 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
||||
err = 0;
|
||||
break;
|
||||
} else if (ch == '\t') { /* tab */
|
||||
memcpy(str + pass, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
||||
mvwaddstr(win, y, x +pass, mid_content[selected_file_current].file_name);
|
||||
pass += 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_dir.current_file->file_name);
|
||||
pass += strlen(mid_dir.current_file->file_name);
|
||||
} else if (ch == 127) { /* backspace */
|
||||
if (pass > 0) {
|
||||
pass--;
|
||||
mvwdelch(win, y, pass);
|
||||
mvwdelch(win, y, x + pass);
|
||||
}
|
||||
} else if (ch == 27) { /* esc key */
|
||||
err = 1;
|
||||
break;
|
||||
} else {
|
||||
mvwaddch(win, y, x +pass, ch);
|
||||
mvwaddch(win, y, x + pass, ch);
|
||||
str[pass] = ch;
|
||||
pass++;
|
||||
}
|
||||
}
|
||||
str[pass] = '\0';
|
||||
|
||||
timeout(10);
|
||||
curs_set(0);
|
||||
|
||||
return err;
|
||||
}
|
||||
int strcmp_offset(char *in0, char *in1, char offset){
|
||||
|
||||
int i = 0;
|
||||
while (in0[i] != '\0' && in1[i] != '\0') {
|
||||
if (in0[i+offset] != in1[i]) {
|
||||
return 1;
|
||||
}
|
||||
i++;
|
||||
in1++;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
void quit_program(){
|
||||
status = STATUS_QUIT_PROGRAM;
|
||||
}
|
||||
void toggle_selection(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
mid_content[selected_file_current].status ^= FILE_STATUS_SELECTED;
|
||||
status |= (STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
void update(){
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
|
||||
}
|
||||
void select_all(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
unsigned long i;
|
||||
for(i = 0; i < mid_file_count; i++) {
|
||||
mid_content[i].status ^= FILE_STATUS_SELECTED;
|
||||
for (i = 0; i < mid_dir.file_count; i++) {
|
||||
mid_dir.file_list[i].status ^= FILE_STATUS_SELECTED;
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void move_down(int passes){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
if (passes == 0) {
|
||||
passes++;
|
||||
}
|
||||
selected_file_current += passes;
|
||||
void move_down(unsigned long passes){
|
||||
|
||||
update_selected_file();
|
||||
dir_set_selected_file_current(selected_file_current);
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
void move_up(int passes){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
if (passes == 0) {
|
||||
passes++;
|
||||
}
|
||||
unsigned long tmp = selected_file_current;
|
||||
selected_file_current -= passes;
|
||||
if (tmp < selected_file_current) {
|
||||
selected_file_current = 0;
|
||||
mid_dir.current_file += passes;
|
||||
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
|
||||
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||
}
|
||||
|
||||
update_selected_file();
|
||||
dir_set_selected_file_current(selected_file_current);
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void move_left(int passes){
|
||||
if (passes == 0) {
|
||||
passes++;
|
||||
void move_up(unsigned long passes){
|
||||
|
||||
mid_dir.current_file -= passes;
|
||||
if (mid_dir.current_file < mid_dir.file_list) {
|
||||
mid_dir.current_file = mid_dir.file_list;
|
||||
}
|
||||
int i;
|
||||
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void move_left(unsigned long passes){
|
||||
unsigned long i;
|
||||
for (i = 0; i < passes; i++) {
|
||||
if (chdir("..") != 0) {
|
||||
/* TODO(2025-07-09T00:30:05) fix */
|
||||
FAIL("move_left", "unhandled error of chdir");
|
||||
} else {
|
||||
selected_file_current = dir_get_selected_file_current();
|
||||
}
|
||||
change_dir("..");
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
|
||||
}
|
||||
void move_right(){
|
||||
if (mid_content->file_name[0] == '\0') {
|
||||
return;
|
||||
}
|
||||
if (mid_content[selected_file_current].file_type &= FILE_TYPE_DIR) {
|
||||
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
||||
FAIL("move_right", "unhandled error of chdir");
|
||||
} else {
|
||||
selected_file_current = dir_get_selected_file_current();
|
||||
|
||||
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||
change_dir(mid_dir.current_file->file_name);
|
||||
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
||||
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
|
||||
if (system(cmd)) {
|
||||
}
|
||||
} else {
|
||||
unsigned long i = 0;
|
||||
char match = 0;
|
||||
char *mime = get_mimetype(mid_content[selected_file_current].file_name);
|
||||
char *extension = strrchr(mid_content[selected_file_current].file_name, '.');
|
||||
for (i = 0; i < file_extension_default_count; i++) {
|
||||
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
||||
char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
|
||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
|
||||
|
||||
if (system(cmd) == -1) {
|
||||
/*do nothing*/
|
||||
}
|
||||
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
||||
match = 1;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
char *mime = get_mimetype(mid_dir.current_file);
|
||||
char *extension = mid_dir.current_file->file_name;
|
||||
char *cmd = NULL;
|
||||
while (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
||||
if (*extension == '.') {
|
||||
break;
|
||||
}
|
||||
extension++;
|
||||
}
|
||||
if (match == 0) {
|
||||
|
||||
unsigned long i;
|
||||
if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
||||
for (i = 0; i < file_extension_default_count; i++) {
|
||||
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
|
||||
if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||
cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file);
|
||||
pid_t pid = fork();
|
||||
if (pid == 0 && setsid()) {
|
||||
system(cmd);
|
||||
status = STATUS_QUIT_PROGRAM;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
|
||||
if (system(cmd)) {
|
||||
}
|
||||
}
|
||||
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||
update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(status & STATUS_MOVE_RIGHT_MATCH)) {
|
||||
for (i = 0; i < mimetype_default_count; i++) {
|
||||
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||
|
||||
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
|
||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
btm_buffer = malloc(strlen(cmd));
|
||||
|
||||
strcpy(btm_buffer, cmd-1);
|
||||
|
||||
|
||||
if (system(cmd) == -1) {
|
||||
/*do nothing*/
|
||||
if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||
cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file);
|
||||
pid_t pid = fork();
|
||||
if (pid == 0 && setsid()) {
|
||||
system(cmd);
|
||||
status = STATUS_QUIT_PROGRAM;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
|
||||
if (system(cmd)) {
|
||||
}
|
||||
}
|
||||
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||
update();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
status &= ~STATUS_MOVE_RIGHT_MATCH;
|
||||
free(cmd);
|
||||
free(mime);
|
||||
}
|
||||
update_selected_file();
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
|
||||
}
|
||||
void toggle_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(unsigned long passes){
|
||||
unsigned long i;
|
||||
for (i = 0; i < passes; i++) {
|
||||
mid_dir.current_file->status ^= FILE_STATUS_SELECTED;
|
||||
move_down(1);
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void jump_bottom(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
selected_file_current = 0 - 1;
|
||||
update_selected_file();
|
||||
dir_set_selected_file_current(selected_file_current);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void jump_top(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
selected_file_current = 0;
|
||||
update_selected_file();
|
||||
dir_set_selected_file_current(selected_file_current);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
mid_dir.current_file = mid_dir.file_list;
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
|
||||
void open_with(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
btm_buffer = concat("open \"", mid_content[selected_file_current].file_name);
|
||||
btm_buffer = concat(btm_buffer, "\" with:");
|
||||
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
render_pass();
|
||||
unsigned long local_height;
|
||||
local_height = getmaxy(win_b);
|
||||
|
||||
|
||||
/* TODO(2025-06-22T01:24:36) fix fixed buffer size */
|
||||
char *str = malloc(255);
|
||||
memset(str, ' ', 255);
|
||||
int err = read_string(win_b, local_height - 1, 0 , str);
|
||||
|
||||
|
||||
if (!err) {
|
||||
char *cmd = concat(str, " ./\"");
|
||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
images_clear();
|
||||
#endif
|
||||
|
||||
if (system(cmd) == -1) {
|
||||
FAIL("open_with", "creating subcommand failed unhandled");
|
||||
}
|
||||
|
||||
free(btm_buffer);
|
||||
btm_buffer = cmd;
|
||||
|
||||
}
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
free(str);
|
||||
}
|
||||
|
||||
void rename_hovered(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name);
|
||||
btm_buffer = concat(btm_buffer, "\" to:");
|
||||
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
render_pass();
|
||||
|
||||
unsigned long local_height;
|
||||
local_height = getmaxy(win_b);
|
||||
|
||||
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
||||
char *str = malloc(255);
|
||||
memset(str, ' ', 255);
|
||||
int err = read_string(win_b, local_height - 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;
|
||||
}
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
|
||||
free(str);
|
||||
}
|
||||
|
||||
void delete(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hits) {
|
||||
btm_buffer = concat("delete:", file_str);
|
||||
} else {
|
||||
btm_buffer = concat("delete: \"", 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)");
|
||||
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
render_pass();
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
timeout(-1); /* negative numbers block until enter is pressed */
|
||||
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
||||
char ch = wgetch(win_b);
|
||||
|
||||
if (ch == 'y' || ch == 'Y') {
|
||||
/* TODO(2025-06-30T02:27:06) 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) {
|
||||
recursive_delete(mid_content[i]);
|
||||
}
|
||||
wclear(win_b);
|
||||
char *cmd;
|
||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||
char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file);
|
||||
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) {
|
||||
if (str[0] == SETTINGS_COMMAND_FORK) {
|
||||
cmd = parse_cmd(str+1, mid_dir.current_file);
|
||||
pid_t pid = fork();
|
||||
if (pid == 0 && setsid()) {
|
||||
system(cmd);
|
||||
status = STATUS_QUIT_PROGRAM;
|
||||
exit(1);
|
||||
}
|
||||
free(btm_buffer);
|
||||
btm_buffer = concat("deleted: ", file_str);
|
||||
} else {
|
||||
free(btm_buffer);
|
||||
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
||||
recursive_delete(mid_content[selected_file_current]);
|
||||
cmd = parse_cmd(str, mid_dir.current_file);
|
||||
if (system(cmd)) {
|
||||
}
|
||||
remove(mid_content[selected_file_current].file_name);
|
||||
btm_buffer = concat("deleted: \"", mid_content[selected_file_current].file_name);
|
||||
btm_buffer = concat(btm_buffer, "\"");
|
||||
|
||||
}
|
||||
/*system(cmd);*/
|
||||
|
||||
} else {
|
||||
free(btm_buffer);
|
||||
btm_buffer = "cancled deletion";
|
||||
}
|
||||
|
||||
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 makedir(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||
memset(btm_buffer, ' ', terminal_width);
|
||||
memcpy(btm_buffer, "create dir: ", strlen("create dir: "));
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
render_pass();
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
unsigned long local_height;
|
||||
local_height = getmaxy(win_b);
|
||||
|
||||
/* TODO(2025-07-03T01:19:55) fix fixed buffer size */
|
||||
char *str = malloc(255);
|
||||
memset(str, ' ', 255);
|
||||
int err = read_string(win_b, local_height - 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(cmd);
|
||||
}
|
||||
free(parsed_ui_text);
|
||||
free(str);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||
|
||||
}
|
||||
void rename_hovered(){
|
||||
wclear(win_b);
|
||||
file tmp;
|
||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
|
||||
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, tmp.file_name) == 0) {
|
||||
char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file);
|
||||
char *cmd1 = parse_cmd(cmd0, &tmp);
|
||||
system(cmd1);
|
||||
free(cmd0);
|
||||
free(cmd1);
|
||||
}
|
||||
free(parsed_ui_text);
|
||||
free(tmp.file_name);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
|
||||
}
|
||||
void delete(){
|
||||
TODO;
|
||||
}
|
||||
void makedir(){
|
||||
wclear(win_b);
|
||||
file tmp;
|
||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||
mvwprintw(win_b, 0, 0, ui_makedir_text);
|
||||
if (read_string(win_b, 0, strlen(ui_makedir_text)+1, tmp.file_name) == 0) {
|
||||
char *cmd = parse_cmd(makedir_cmd, &tmp);
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
}
|
||||
free(tmp.file_name);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void makefile(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
memcpy(btm_buffer, "create file: ", strlen("create file: "));
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
render_pass();
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
unsigned long local_height;
|
||||
local_height = getmaxy(win_b);
|
||||
|
||||
/* TODO(2025-07-03T01:19:49) fix fixed buffer size */
|
||||
char *str = malloc(255);
|
||||
memset(str, ' ', 255);
|
||||
int err = read_string(win_b, local_height - 1, 0, str);
|
||||
if (!err) {
|
||||
btm_buffer = concat(btm_buffer, str);
|
||||
FILE *fp;
|
||||
fp = fopen(str, "w");
|
||||
fclose(fp);
|
||||
wclear(win_b);
|
||||
file tmp;
|
||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||
mvwprintw(win_b, 0, 0, ui_makefile_text);
|
||||
if (read_string(win_b, 0, strlen(ui_makefile_text)+1, tmp.file_name) == 0) {
|
||||
char *cmd = parse_cmd(makefile_cmd, &tmp);
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
}
|
||||
free(str);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
free(tmp.file_name);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void enter_shell(unsigned long passes, int index){
|
||||
(void)passes; /*remove compiler warning*/
|
||||
|
||||
void update(){
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
}
|
||||
void enter_shell(int passes, int index){
|
||||
(void)passes;
|
||||
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
images_clear();
|
||||
#endif
|
||||
endwin();
|
||||
if (system(key_binding[index].black_magic) != 0) {
|
||||
/*do nothing*/
|
||||
endwin();\
|
||||
echo();\
|
||||
curs_set(1);\
|
||||
if (system(key_binding[index].black_magic)) {
|
||||
}
|
||||
initscr();
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
initscr(); /* start ncurses */
|
||||
noecho(); /* hide keyboard input */
|
||||
curs_set(0);
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
|
||||
}
|
||||
void not_implemented(int passes, int index){
|
||||
void not_implemented(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
|
||||
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
|
||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
|
||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
||||
TODO;
|
||||
}
|
||||
void jump_to_dir(int passes, int index){
|
||||
void jump_to_dir(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
|
||||
char *ch = (char*)key_binding[index].black_magic;
|
||||
char slash = 0;
|
||||
unsigned int env_len = 0;
|
||||
while (*ch != '\0') {
|
||||
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));
|
||||
strcpy(path, (char*)key_binding[index].black_magic);
|
||||
} 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));
|
||||
strcpy(path, (char*)key_binding[index].black_magic);
|
||||
}
|
||||
unsigned long len;
|
||||
char *c = strchr(key_binding[index].black_magic, '/');
|
||||
if (c) {
|
||||
len = c - (char*)key_binding[index].black_magic;
|
||||
} else {
|
||||
env_parsed = getenv((char*)key_binding[index].black_magic +1);
|
||||
if (env_parsed) {
|
||||
path = malloc(strlen(env_parsed)+1);
|
||||
strcpy(path, env_parsed);
|
||||
} else {
|
||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||
strcpy(path, (char*)key_binding[index].black_magic);
|
||||
}
|
||||
}
|
||||
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();
|
||||
len = strlen(key_binding[index].black_magic);
|
||||
}
|
||||
|
||||
/*env_parsed shall not be modified (read: free'd) - the man page*/
|
||||
if (env_str) {
|
||||
free(env_str);
|
||||
}
|
||||
if(path) {
|
||||
char *to_env = malloc(len + 1);
|
||||
memcpy(to_env, key_binding[index].black_magic, len);
|
||||
to_env[len] = '\0';
|
||||
char *env = getenv(to_env + 1); /*+1 to remove the '$' prefix, freeing env always segfaults*/
|
||||
|
||||
if (env) {
|
||||
char *path = malloc(strlen(key_binding[index].black_magic) + strlen(env) + 1);
|
||||
memcpy(path, env, strlen(env));
|
||||
memcpy(path + strlen(env), key_binding[index].black_magic + len, strlen(key_binding[index].black_magic)+1);
|
||||
change_dir(path);
|
||||
free(path);
|
||||
} else {
|
||||
change_dir(key_binding[index].black_magic);
|
||||
}
|
||||
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(int passes, int index){
|
||||
void order_by(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
|
||||
free(seed);
|
||||
seed = malloc(sizeof(time_t));
|
||||
*seed = time(NULL);
|
||||
seed = time(NULL);
|
||||
|
||||
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(int passes, int index){
|
||||
void cmd_on_selected(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
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)");
|
||||
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
render_pass();
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
|
||||
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*/
|
||||
}
|
||||
}
|
||||
}
|
||||
free(btm_buffer);
|
||||
memcpy(btm_buffer, "completed: ", strlen("completed: "));
|
||||
} else {
|
||||
free(btm_buffer);
|
||||
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);
|
||||
|
||||
} else {
|
||||
free(btm_buffer);
|
||||
memcpy(btm_buffer, "cancled deletion", strlen("cancled deletion"));
|
||||
}
|
||||
|
||||
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(int 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*/
|
||||
}
|
||||
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file);
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||
}
|
||||
void yank_file(int passes, int index){
|
||||
(void)passes;
|
||||
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);
|
||||
|
||||
unsigned long i;
|
||||
if (yank_files.status & YANK_IS_USED) {
|
||||
free(yank_files.path);
|
||||
for (i = 0; i < yank_files.count; i++) {
|
||||
free(yank_files.list[i]);
|
||||
}
|
||||
free(yank_files.list);
|
||||
yank_files.count = 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);
|
||||
strcpy(*yank_files.list, 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 < yank_files.count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
||||
strcpy(*yank_files.list, 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 yank_file(unsigned long passes, int index){
|
||||
TODO;
|
||||
}
|
||||
void paste(){
|
||||
unsigned long i;
|
||||
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 -r -i ", yank_files.path);
|
||||
} else {
|
||||
cmd = concat("mv ", yank_files.path);
|
||||
}
|
||||
cmd = concat(cmd, "/");
|
||||
cmd = concat(cmd, *yank_files.list);
|
||||
cmd = concat(cmd, " ./");
|
||||
mvprintw(i, 0, cmd);
|
||||
if (system(cmd) != 0) {
|
||||
cmd = concat(cmd, *yank_files.list);
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
FILE *cmd_open;
|
||||
while (1) {
|
||||
cmd_open = popen(cmd, "r");
|
||||
int val = getline(&line, &size, cmd_open);
|
||||
|
||||
if (pclose(cmd_open) == 0) {
|
||||
break;
|
||||
} else if (val == 0 || val == -1) {
|
||||
break;
|
||||
}
|
||||
cmd = concat(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);
|
||||
TODO;
|
||||
}
|
||||
void search(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
unsigned long local_height;
|
||||
local_height = getmaxy(win_b);
|
||||
memset(search_buffer, '\0', 255);
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
render_pass();
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
echo();
|
||||
unsigned long i;
|
||||
for (i = 0; i < terminal_width -1; i++) {
|
||||
mvwaddch(win_b, 0, i, ' ');
|
||||
}
|
||||
mvwaddch(win_b, 0, 0, '/');
|
||||
memset(search_buffer, 0, INPUT_BUFFER_SIZE);
|
||||
|
||||
curs_set(1);
|
||||
echo();
|
||||
|
||||
timeout(-1); /* negative numbers block until enter is pressed */
|
||||
|
||||
unsigned int pass = 0;
|
||||
char ch;
|
||||
char err = 0;
|
||||
|
||||
wmove(win_b, local_height-1, 1);
|
||||
wmove(win_b, 0, 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);
|
||||
if (ch == '\n') {
|
||||
err = 0;
|
||||
break;
|
||||
} else if (ch == '\t') { /* tab */
|
||||
memcpy(search_buffer, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
||||
mvwaddstr(win_b, local_height-1, pass, mid_content[selected_file_current].file_name);
|
||||
pass = 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, 0, pass+1, mid_dir.current_file->file_name);
|
||||
pass += strlen(mid_dir.current_file->file_name);
|
||||
} else if (ch == 127) { /* backspace */
|
||||
mvwdelch(win_b, local_height-1, 1);
|
||||
wdelch(win_b);
|
||||
if (pass != 0) {
|
||||
search_buffer[pass-1] = '\0';
|
||||
if (pass > 0) {
|
||||
pass--;
|
||||
mvwdelch(win_b, 0, pass+1);
|
||||
}
|
||||
} else if (ch == 27) { /* esc key */
|
||||
err = 1;
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
if (ch) {
|
||||
mvwaddch(win_b, 0, pass+1, ch);
|
||||
search_buffer[pass] = ch;
|
||||
pass++;
|
||||
unsigned long i;
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
||||
selected_file_current = i;
|
||||
if (update_selected_file()) {
|
||||
pthread_cond_signal(&cond_rgt);
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
|
||||
unsigned long index = (mid_dir.current_file - mid_dir.file_list);
|
||||
unsigned long x = getmaxx(win_b);
|
||||
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
|
||||
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||
mid_dir.current_file = &mid_dir.file_list[index];
|
||||
|
||||
/* re-render current dir */
|
||||
pthread_mutex_lock(&mutex_render);
|
||||
|
||||
werase(win_m);
|
||||
print_dir(win_m, 1, &mid_dir);
|
||||
|
||||
wnoutrefresh(win_m);
|
||||
pthread_mutex_unlock(&mutex_render);
|
||||
break;
|
||||
}
|
||||
render_pass();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
search_buffer[pass] = '\0';
|
||||
|
||||
timeout(10);
|
||||
noecho();
|
||||
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(){
|
||||
unsigned long i;
|
||||
for (i = selected_file_current+1; i < mid_file_count; i++) {
|
||||
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();
|
||||
long index = (mid_dir.current_file - mid_dir.file_list) + 1;
|
||||
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
|
||||
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||
mid_dir.current_file = &mid_dir.file_list[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void search_previous(){
|
||||
unsigned long i;
|
||||
for (i = selected_file_current-1;; i--) {
|
||||
if(i > selected_file_current) {
|
||||
break;
|
||||
}
|
||||
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();
|
||||
long index = (mid_dir.current_file - mid_dir.file_list) - 1;
|
||||
for (; &mid_dir.file_list[index] >= mid_dir.file_list; index--) {
|
||||
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||
mid_dir.current_file = &mid_dir.file_list[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void jmp_file_index(){
|
||||
TODO;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ void quit_program();
|
||||
void toggle_selection();
|
||||
void select_all();
|
||||
void move_right();
|
||||
void move_up(int passes);
|
||||
void move_down(int passes);
|
||||
void move_left(int passes);
|
||||
void move_up(unsigned long passes);
|
||||
void move_down(unsigned long passes);
|
||||
void move_left(unsigned long passes);
|
||||
void jump_bottom();
|
||||
void jump_top();
|
||||
void toggle_hidden_files();
|
||||
@@ -21,14 +21,16 @@ void delete();
|
||||
void makedir();
|
||||
void makefile();
|
||||
void update();
|
||||
void enter_shell(int passes, int index);
|
||||
void not_implemented(int passes, int index);
|
||||
void jump_to_dir(int passes, int index);
|
||||
void order_by(int passes, int index);
|
||||
void cmd_on_selected(int passes, int index);
|
||||
void yank_text(int passes, int index);
|
||||
void yank_file(int passes, int index);
|
||||
void enter_shell(unsigned long passes, int index);
|
||||
void not_implemented(unsigned long passes, int index);
|
||||
void jump_to_dir(unsigned long passes, int index);
|
||||
void order_by(unsigned long passes, int index);
|
||||
void cmd_on_selected(unsigned long passes, int index);
|
||||
void yank_file_name();
|
||||
void yank_file_path();
|
||||
void yank_file(unsigned long passes, int index);
|
||||
void paste();
|
||||
void search();
|
||||
void search_next();
|
||||
void search_previous();
|
||||
void jmp_file_index();
|
||||
|
||||
109
main.c
109
main.c
@@ -7,6 +7,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "config.h"
|
||||
#include "threading.h"
|
||||
#include "window.c"
|
||||
#include "colors.h"
|
||||
@@ -18,10 +19,10 @@ unsigned int terminal_width;
|
||||
unsigned int temp_heigth = 0; /*used for screen refresh*/
|
||||
unsigned int temp_width = 0;
|
||||
unsigned int settings;
|
||||
unsigned int file_modifiers;
|
||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
char *start_path;
|
||||
time_t *seed;
|
||||
unsigned int file_modifiers = 0;
|
||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY) & ~STATUS_UPDATE_SCREEN_RESIZE;
|
||||
char *global_path;
|
||||
time_t seed;
|
||||
|
||||
WINDOW *win_t;
|
||||
WINDOW *win_b;
|
||||
@@ -29,13 +30,17 @@ WINDOW *win_l;
|
||||
WINDOW *win_m;
|
||||
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 *terminal_width_empty_line; /* used in user_interactions */
|
||||
|
||||
void render_pass();
|
||||
void init();
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
init();
|
||||
@@ -58,8 +63,6 @@ int main(){
|
||||
pthread_t thread_m;
|
||||
pthread_t thread_r;
|
||||
|
||||
char threading = 0;
|
||||
terminal_width_empty_line = malloc(terminal_width);
|
||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||
time_t t;
|
||||
time_t dt;
|
||||
@@ -71,37 +74,37 @@ int main(){
|
||||
pthread_create(&thread_m, NULL, thread_mid, &status); /*current_content slash win_m*/
|
||||
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
||||
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
||||
|
||||
|
||||
timeout(SETTINGS_CURSES_TIMEOUT);
|
||||
|
||||
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
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)) {
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RESIZE);
|
||||
temp_width = terminal_width;
|
||||
temp_heigth = terminal_height;
|
||||
}
|
||||
if (threading) {
|
||||
status &= ~(STATUS_RELOAD_DIRECTORY);
|
||||
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();
|
||||
|
||||
|
||||
render_pass();
|
||||
|
||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||
time(&dt);
|
||||
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
|
||||
time(&t);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -110,15 +113,6 @@ int main(){
|
||||
ueberzug_close();
|
||||
#endif
|
||||
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_m);
|
||||
@@ -135,19 +129,11 @@ int main(){
|
||||
|
||||
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_RELOAD_FULL) {
|
||||
clear();
|
||||
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
||||
}
|
||||
|
||||
/*TODO: check if deallocation of window and reallocation is faster than this or not */
|
||||
|
||||
wclear(win_t);
|
||||
wclear(win_b);
|
||||
wclear(win_l);
|
||||
wclear(win_m);
|
||||
wclear(win_r);
|
||||
|
||||
wresize(win_t, 1, terminal_width);
|
||||
wresize(win_l, terminal_height-2, terminal_width/8);
|
||||
@@ -162,22 +148,11 @@ void render_pass(){
|
||||
mvwin(win_r, 1, ((terminal_width/2)));
|
||||
mvwin(win_b, terminal_height-1, 0);
|
||||
|
||||
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
}
|
||||
|
||||
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
||||
status &= ~(STATUS_UPDATE_SCREEN_MASK);
|
||||
window_top(win_t);
|
||||
window_lft(win_l);
|
||||
window_mid(win_m);
|
||||
window_rgt(win_r);
|
||||
window_btm(win_b);
|
||||
wrefresh(win_t);
|
||||
wrefresh(win_l);
|
||||
wrefresh(win_m);
|
||||
wrefresh(win_r);
|
||||
wrefresh(win_b);
|
||||
if (pthread_mutex_lock(&mutex_render) == 0 || status & STATUS_UPDATE_SCREEN_MASK) {
|
||||
doupdate();
|
||||
status &= ~STATUS_UPDATE_SCREEN_MASK;
|
||||
pthread_mutex_unlock(&mutex_render);
|
||||
}
|
||||
}
|
||||
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
||||
@@ -186,13 +161,15 @@ void init() {
|
||||
setlocale(LC_ALL, "");
|
||||
initscr(); /* start ncurses */
|
||||
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);
|
||||
|
||||
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
||||
input = malloc(sizeof(char)*255); /* size of input buffer, out of bounds access will not be accounted for */
|
||||
memset(input, 0, 255);
|
||||
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
input = malloc(INPUT_BUFFER_SIZE); /* size of input buffer, out of bounds access will not be accounted for */
|
||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||
if (getuid() == 0) {
|
||||
status |= STATUS_USER_ROOT;
|
||||
}
|
||||
@@ -205,11 +182,11 @@ void init() {
|
||||
#endif
|
||||
|
||||
ESCDELAY = 10;
|
||||
global_path = getcwd(NULL, 0);
|
||||
char *start_path = getcwd(NULL, 0);
|
||||
setenv("START_PATH", start_path, 0);
|
||||
free(start_path);
|
||||
|
||||
seed = malloc(sizeof(time_t));
|
||||
*seed = time(NULL);
|
||||
seed = time(NULL);
|
||||
|
||||
}
|
||||
|
||||
85
sorting.c
85
sorting.c
@@ -1,6 +1,5 @@
|
||||
#include <curses.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
@@ -8,7 +7,7 @@
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
extern time_t *seed;
|
||||
extern time_t seed;
|
||||
|
||||
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)) {
|
||||
return 1;
|
||||
}
|
||||
time_t num = (time_t)&seed;
|
||||
unsigned long i;
|
||||
for (i = 0; i < 6; i++){
|
||||
num ^= *seed;
|
||||
if (num%2) {
|
||||
num ^= (time_t)#
|
||||
num ^= num << i;
|
||||
} else {
|
||||
num ^= (time_t)&seed;
|
||||
num ^= num >> i;
|
||||
}
|
||||
/* seed is the only value that actually changes whenever this funcion is called.
|
||||
* seed only updates when the order_by binding is executed.
|
||||
* this means that the random output only changes on the command of the user, and not SETTINGS_RELOAD_DIR_DELTA, this is intentional.
|
||||
* well the other stuff like file sizes and file count in a dir may also change, but this needs user intervention too.
|
||||
* that is unless the user decides to sort random in /var/log or something, which begs the question: why would you do that?
|
||||
*/
|
||||
time_t num = (((time_t)&sort_random) + (time_t)seed) ^ (((file*)file0)->file_size + ((file*)file1)->file_size);
|
||||
int i;
|
||||
for (i = 1; i < (((time_t)&getpid)%3); i++) {
|
||||
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){
|
||||
@@ -144,13 +144,13 @@ int sort_type(const void *file0, const void *file1){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (((file*)file0)->file_type == ((file*)file1)->file_type) {
|
||||
/*somehow relying on the else below, occasionaly trips either one of the checked for conditions*/
|
||||
return strcasecmp(((file*)file0)->file_name, ((file*)file1)->file_name);
|
||||
} else if (((file*)file0)->file_type > ((file*)file1)->file_type) {
|
||||
if (((file*)file0)->file_type > ((file*)file1)->file_type) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
} else if (((file*)file0)->file_type < ((file*)file1)->file_type) {
|
||||
return 1;
|
||||
} else {
|
||||
return sort_natural(file0, file1);
|
||||
}
|
||||
}
|
||||
int sort_size(const void *file0, const void *file1){
|
||||
|
||||
@@ -161,10 +161,43 @@ int sort_size(const void *file0, const void *file1){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (((file*)file0)->file_size == ((file*)file1)->file_size) {
|
||||
return strcasecmp(((file*)file0)->file_name, ((file*)file1)->file_name);
|
||||
} else if (((file*)file0)->file_size > ((file*)file1)->file_size) {
|
||||
if (((file*)file0)->file_size > ((file*)file1)->file_size) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
} else if (((file*)file0)->file_size < ((file*)file1)->file_size) {
|
||||
return 1;
|
||||
} else {
|
||||
return sort_natural(file0, file1);
|
||||
}
|
||||
}
|
||||
int sort_extension(const void *file0, const void *file1){
|
||||
|
||||
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||
return -1;
|
||||
}
|
||||
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *extension0 = strrchr(((file*)file0)->file_name, '.');
|
||||
char *extension1 = strrchr(((file*)file1)->file_name, '.');
|
||||
|
||||
if (extension0 && extension1) {
|
||||
if ((strcmp(extension0, extension1)) == 0) {
|
||||
return sort_natural(file0, file1);
|
||||
} else {
|
||||
file f0;
|
||||
file f1;
|
||||
memcpy(&f0, file0, sizeof(file));
|
||||
memcpy(&f1, file1, sizeof(file));
|
||||
f0.file_name = extension0;
|
||||
f1.file_name = extension1;
|
||||
return sort_natural(&f0, &f1);
|
||||
}
|
||||
} else if (extension0 != NULL && extension1 == NULL) {
|
||||
return 1;
|
||||
} else if (extension0 == NULL && extension1 != NULL) {
|
||||
return -1;
|
||||
} else {
|
||||
return sort_natural(file0, file1);
|
||||
}
|
||||
}
|
||||
|
||||
119
string.h
Normal file
119
string.h
Normal 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);
|
||||
524
threading.c
524
threading.c
@@ -4,7 +4,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
@@ -19,7 +18,7 @@ pthread_mutex_t mutex_btm;
|
||||
pthread_mutex_t mutex_lft;
|
||||
pthread_mutex_t mutex_mid;
|
||||
pthread_mutex_t mutex_rgt;
|
||||
pthread_mutex_t mutex_selection;
|
||||
pthread_mutex_t mutex_render;
|
||||
pthread_cond_t cond_mid;
|
||||
pthread_cond_t cond_rgt;
|
||||
pthread_cond_t cond_lft;
|
||||
@@ -27,77 +26,112 @@ pthread_cond_t cond_top;
|
||||
pthread_cond_t cond_btm;
|
||||
|
||||
|
||||
file *rgt_content;
|
||||
file *mid_content;
|
||||
file *lft_content;
|
||||
dir rgt_dir;
|
||||
dir mid_dir;
|
||||
dir lft_dir;
|
||||
char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */
|
||||
char *btm_buffer;
|
||||
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;
|
||||
|
||||
|
||||
|
||||
volatile unsigned long selected_file_current = 0;
|
||||
volatile unsigned long selected_file_last = 0;
|
||||
extern unsigned int terminal_width;
|
||||
extern unsigned int status;
|
||||
extern char *global_path;
|
||||
|
||||
unsigned int btm_status;
|
||||
|
||||
|
||||
void *thread_mid(){
|
||||
dir tmp;
|
||||
tmp.current_file = NULL;
|
||||
tmp.file_list = NULL;
|
||||
tmp.file_count = 0;
|
||||
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
pthread_cond_wait(&cond_mid, &mutex_mid);
|
||||
|
||||
char *path;
|
||||
if((path=getcwd(NULL, 0)) == NULL) {
|
||||
mid_content = malloc(sizeof(file));
|
||||
mid_content->file_name = "cannot open directory";
|
||||
mid_file_count = 1;
|
||||
} else {
|
||||
if (global_path == NULL) {
|
||||
mid_dir.current_file = NULL;
|
||||
mid_dir.file_count = 0;
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
continue;
|
||||
}
|
||||
char *path = malloc(strlen(global_path)+1);
|
||||
memcpy(path, global_path, strlen(global_path)+1);
|
||||
|
||||
|
||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
free(mid_content[i].file_name);
|
||||
}
|
||||
free(mid_content);
|
||||
mid_file_count = get_dir_size(path);
|
||||
if (mid_file_count != 0) {
|
||||
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';
|
||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||
long index = mid_dir.current_file - mid_dir.file_list;
|
||||
|
||||
mid_file_count = 0;
|
||||
tmp = mid_dir;
|
||||
|
||||
}
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
update_selected_file();
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
mid_dir.file_count = get_dir_size(path);
|
||||
mid_dir.file_list = malloc(mid_dir.file_count * sizeof(file));
|
||||
if (mid_dir.file_count) { /* fails if dir empty */
|
||||
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;
|
||||
}
|
||||
|
||||
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_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);
|
||||
}
|
||||
@@ -107,27 +141,50 @@ void *thread_lft(){
|
||||
pthread_mutex_lock(&mutex_lft);
|
||||
pthread_cond_wait(&cond_lft, &mutex_lft);
|
||||
|
||||
char *path;
|
||||
if((path=getcwd(NULL, 0)) == NULL) {
|
||||
lft_content = malloc(sizeof(file));
|
||||
lft_content[0].file_name = "cannot open directory";
|
||||
lft_file_count = 1;
|
||||
} else {
|
||||
if (global_path == NULL) {
|
||||
lft_dir.current_file = NULL;
|
||||
lft_dir.file_count = 0;
|
||||
pthread_mutex_unlock(&mutex_lft);
|
||||
continue;
|
||||
}
|
||||
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[0] = '/';
|
||||
|
||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||
lft_file_count = get_dir_size(path);
|
||||
free(lft_content);
|
||||
lft_content = malloc(lft_file_count * sizeof(file));
|
||||
memset(lft_content, '\0', lft_file_count * sizeof(file));
|
||||
get_dir_content(path, &lft_file_count, lft_content);
|
||||
}
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < lft_dir.file_count; i++) {
|
||||
free(lft_dir.file_list[i].file_name);
|
||||
}
|
||||
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);
|
||||
|
||||
free(path);
|
||||
}
|
||||
pthread_exit(0);
|
||||
|
||||
@@ -135,85 +192,80 @@ void *thread_lft(){
|
||||
}
|
||||
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)){
|
||||
pthread_mutex_lock(&mutex_rgt);
|
||||
pthread_cond_wait(&cond_rgt, &mutex_rgt);
|
||||
|
||||
|
||||
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
char *path;
|
||||
if (mid_file_count != 0) {
|
||||
path = malloc(strlen(mid_content[selected_file_current].file_name) + 1);
|
||||
strcpy(path, mid_content[selected_file_current].file_name);
|
||||
} else {
|
||||
path = malloc(sizeof(char));
|
||||
path[0] = '\0';
|
||||
}
|
||||
file_current.file_type = mid_content[selected_file_current].file_type;
|
||||
file_current.file_size = mid_content[selected_file_current].file_size;
|
||||
file_current.status = mid_content[selected_file_current].status;
|
||||
|
||||
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
|
||||
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||
|
||||
rgt_dir.file_list = malloc(sizeof(file));
|
||||
memcpy(rgt_dir.file_list, mid_dir.current_file, sizeof(file));
|
||||
rgt_dir.file_list->file_name = file_name;
|
||||
rgt_dir.current_file = rgt_dir.file_list;
|
||||
rgt_dir.file_count = 1;
|
||||
|
||||
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
|
||||
images_clear();
|
||||
#endif
|
||||
|
||||
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);
|
||||
tmp = rgt_dir;
|
||||
|
||||
rgt_file_count = get_dir_size(path);
|
||||
rgt_content = malloc(rgt_file_count * sizeof(file));
|
||||
memset(rgt_content, '\0', rgt_file_count * sizeof(file));
|
||||
get_dir_content(path, &rgt_file_count, rgt_content);
|
||||
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
|
||||
rgt_dir.file_count = get_dir_size(rgt_dir.current_file->file_name);
|
||||
rgt_dir.file_list = malloc(rgt_dir.file_count * sizeof(file));
|
||||
if (rgt_dir.file_count) { /* fails if dir empty */
|
||||
get_dir_content(tmp.current_file->file_name, &rgt_dir);
|
||||
} 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);
|
||||
rgt_buffer = malloc(sizeof(char));
|
||||
rgt_buffer[0] = '\0';
|
||||
} 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);
|
||||
}
|
||||
rgt_buffer = preview_file(rgt_dir.current_file);
|
||||
rgt_dir.current_file->file_type |= FILE_TYPE_OPEN_FILE;
|
||||
pthread_mutex_lock(&mutex_render);
|
||||
werase(win_r);
|
||||
if (rgt_dir.current_file->file_type & FILE_TYPE_OPEN_FILE) {
|
||||
mvwaddnstr(win_r, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
||||
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
|
||||
mvwaddstr(win_r, 0, 0, "not accessible");
|
||||
}
|
||||
free(rgt_content);
|
||||
rgt_file_count = 0;
|
||||
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);
|
||||
wnoutrefresh(win_r);
|
||||
pthread_mutex_unlock(&mutex_render);
|
||||
}
|
||||
} 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);
|
||||
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);
|
||||
}
|
||||
@@ -223,99 +275,160 @@ void *thread_top(){
|
||||
pthread_mutex_lock(&mutex_top);
|
||||
pthread_cond_wait(&cond_top, &mutex_top);
|
||||
|
||||
|
||||
free(top_buffer);
|
||||
|
||||
char *path;
|
||||
if((path=getcwd(NULL, 0)) == NULL) {
|
||||
if(global_path == NULL) {
|
||||
top_buffer = malloc(sizeof("cannot open directory"));
|
||||
top_width = sizeof("cannot open directory");
|
||||
top_buffer = "cannot open directory";
|
||||
} else {
|
||||
top_buffer = getcwd(NULL, 0);
|
||||
top_width = strlen(top_buffer);
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_top);
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
free(path);
|
||||
pthread_mutex_unlock(&mutex_top);
|
||||
}
|
||||
pthread_exit(0);
|
||||
}
|
||||
void *thread_btm(){
|
||||
char *path = NULL;
|
||||
char *ui_btm_right_block = malloc(sizeof(char));
|
||||
unsigned int ui_btm_right_block_size = 0;
|
||||
unsigned int buffer_width = 0;
|
||||
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
pthread_cond_wait(&cond_btm, &mutex_btm);
|
||||
|
||||
|
||||
free(btm_buffer);
|
||||
int buffer_width = terminal_width;
|
||||
btm_buffer = malloc(buffer_width);
|
||||
if (status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
|
||||
/*{{{ parse storage info; the fold of shame*/
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
unsigned long i;
|
||||
float total_dir_size = 0;
|
||||
for(i = 0; i < mid_dir.file_count; i++) {
|
||||
if ((mid_dir.file_list[i].file_type & (FILE_TYPE_DIR)) != FILE_TYPE_DIR) {
|
||||
total_dir_size += mid_dir.file_list[i].file_size;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
|
||||
|
||||
free(ui_btm_right_block);
|
||||
|
||||
if(path) {
|
||||
free(path);
|
||||
}
|
||||
path = getcwd(NULL, 0);
|
||||
struct statvfs fs;
|
||||
statvfs(path, &fs);
|
||||
|
||||
float disk_size_free = fs.f_bsize * fs.f_bavail;
|
||||
|
||||
float parsed_number[2] = { 0 };
|
||||
|
||||
|
||||
|
||||
char size_index[2] = { 0 };
|
||||
if (total_dir_size > 1) {
|
||||
size_index[0] = -1;
|
||||
while (total_dir_size > 1 && size_index[0] < size_unit_count) {
|
||||
parsed_number[0]=total_dir_size;
|
||||
size_index[0]++;
|
||||
total_dir_size /= 1024;
|
||||
}
|
||||
} else {
|
||||
size_index[0] = 0;
|
||||
parsed_number[0] = 0;
|
||||
}
|
||||
|
||||
if (disk_size_free > 1) {
|
||||
size_index[1] = -1;
|
||||
while (disk_size_free > 1 && size_index[1] < size_unit_count) {
|
||||
parsed_number[1]=disk_size_free;
|
||||
size_index[1]++;
|
||||
disk_size_free /= 1024;
|
||||
}
|
||||
} else {
|
||||
size_index[1] = 0;
|
||||
}
|
||||
if (size_index[0] > 0 && size_index[1] > 0) {
|
||||
ui_btm_right_block_size = snprintf(NULL, 0, "%0.2lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
|
||||
ui_btm_right_block = malloc(ui_btm_right_block_size);
|
||||
sprintf(ui_btm_right_block, "%0.2lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
|
||||
} else if (size_index[0] <= 0 && size_index[1] > 0) {
|
||||
ui_btm_right_block_size = snprintf(NULL, 0, "%0.0lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
|
||||
ui_btm_right_block = malloc(ui_btm_right_block_size);
|
||||
sprintf(ui_btm_right_block, "%0.0lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
|
||||
} else if (size_index[0] > 0 && size_index[1] <= 0) {
|
||||
ui_btm_right_block_size = snprintf(NULL, 0, "%0.2lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
|
||||
ui_btm_right_block = malloc(ui_btm_right_block_size);
|
||||
sprintf(ui_btm_right_block, "%0.2lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
|
||||
} else {
|
||||
ui_btm_right_block_size = snprintf(NULL, 0, "%0.0lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
|
||||
ui_btm_right_block = malloc(ui_btm_right_block_size);
|
||||
sprintf(ui_btm_right_block, "%0.0lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
|
||||
}
|
||||
/*}}}*/
|
||||
}
|
||||
|
||||
if (buffer_width != terminal_width) {
|
||||
buffer_width = terminal_width;
|
||||
free(btm_buffer);
|
||||
btm_buffer = malloc(buffer_width+1);
|
||||
}
|
||||
memset(btm_buffer, ' ', buffer_width);
|
||||
btm_buffer[buffer_width] = '\0';
|
||||
btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-';
|
||||
btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-';
|
||||
btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-';
|
||||
btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-';
|
||||
btm_buffer[4] = (mid_content[selected_file_current].permissions & S_IRGRP) ? 'r' : '-';
|
||||
btm_buffer[5] = (mid_content[selected_file_current].permissions & S_IWGRP) ? 'w' : '-';
|
||||
btm_buffer[6] = (mid_content[selected_file_current].permissions & S_IXGRP) ? 'x' : '-';
|
||||
btm_buffer[7] = (mid_content[selected_file_current].permissions & S_IROTH) ? 'r' : '-';
|
||||
btm_buffer[8] = (mid_content[selected_file_current].permissions & S_IWOTH) ? 'w' : '-';
|
||||
btm_buffer[9] = (mid_content[selected_file_current].permissions & S_IXOTH) ? 'x' : '-';
|
||||
|
||||
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
|
||||
|
||||
btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
|
||||
(S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
|
||||
btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
|
||||
btm_buffer[2] = (mid_dir.current_file->permissions & S_IWUSR) ? 'w' : '-';
|
||||
btm_buffer[3] = (mid_dir.current_file->permissions & S_IXUSR) ? 'x' : '-';
|
||||
btm_buffer[4] = (mid_dir.current_file->permissions & S_IRGRP) ? 'r' : '-';
|
||||
btm_buffer[5] = (mid_dir.current_file->permissions & S_IWGRP) ? 'w' : '-';
|
||||
btm_buffer[6] = (mid_dir.current_file->permissions & S_IXGRP) ? 'x' : '-';
|
||||
btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
|
||||
btm_buffer[8] = (mid_dir.current_file->permissions & S_IWOTH) ? 'w' : '-';
|
||||
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
|
||||
|
||||
|
||||
char *path;
|
||||
path=getcwd(NULL, 0);
|
||||
struct statvfs fs;
|
||||
statvfs(path, &fs);
|
||||
|
||||
float disk_size_free = fs.f_bsize * fs.f_bavail;
|
||||
float parsed_number = 0;
|
||||
int offset_back = buffer_width - strlen(ui_btm_text_storage_left);
|
||||
strcpy(btm_buffer + offset_back, ui_btm_text_storage_left);
|
||||
char *float_str = malloc(buffer_width / 4);
|
||||
|
||||
char size_index = -1;
|
||||
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
unsigned long i;
|
||||
unsigned long total_dir_size = 0;
|
||||
for(i = 0; i < mid_file_count; i++) {
|
||||
if (!(mid_content[i].file_type & (FILE_TYPE_DIR))) {
|
||||
total_dir_size += mid_content[i].file_size;
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
wnoutrefresh(win_b);
|
||||
pthread_mutex_unlock(&mutex_render);
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
/*the printing of all possible inputs are done in user_interactions */
|
||||
|
||||
do {
|
||||
parsed_number=disk_size_free;
|
||||
disk_size_free /= 1024;
|
||||
size_index++;
|
||||
} while (disk_size_free > 1 && size_index < size_unit_count);
|
||||
|
||||
|
||||
snprintf(float_str, 10, "%0.2lf", parsed_number);
|
||||
|
||||
btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index];
|
||||
offset_back -= strlen(float_str) + 2;
|
||||
memcpy(btm_buffer + offset_back, float_str, strlen(float_str));
|
||||
|
||||
parsed_number = 0;
|
||||
size_index = -1;
|
||||
do {
|
||||
parsed_number=total_dir_size;
|
||||
total_dir_size /= 1024;
|
||||
size_index++;
|
||||
} while (total_dir_size > 1 && size_index < size_unit_count);
|
||||
|
||||
offset_back -= strlen(ui_btm_current_dir_size) + 5;
|
||||
memcpy(btm_buffer + offset_back, ui_btm_current_dir_size, strlen(ui_btm_current_dir_size));
|
||||
|
||||
snprintf(float_str, 10, "%0.2lf", parsed_number);
|
||||
btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index];
|
||||
offset_back -= strlen(float_str) + 2;
|
||||
memcpy(btm_buffer + offset_back, float_str, strlen(float_str));
|
||||
free(path);
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
}
|
||||
@@ -323,9 +436,6 @@ void *thread_btm(){
|
||||
}
|
||||
|
||||
void threading_init(){
|
||||
rgt_content = malloc(sizeof(file));
|
||||
mid_content = malloc(sizeof(file));
|
||||
lft_content = malloc(sizeof(file));
|
||||
|
||||
top_buffer = malloc(sizeof(char));
|
||||
rgt_buffer = malloc(sizeof(char));
|
||||
@@ -334,37 +444,21 @@ void threading_init(){
|
||||
memset(rgt_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;
|
||||
rgt_content->file_size = 0;
|
||||
rgt_content->file_name = malloc(sizeof(char));
|
||||
rgt_content->file_name[0] = '\0';
|
||||
|
||||
|
||||
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;
|
||||
pthread_mutex_init(&mutex_top, NULL);
|
||||
pthread_mutex_init(&mutex_mid, NULL);
|
||||
pthread_mutex_init(&mutex_lft, NULL);
|
||||
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);
|
||||
|
||||
}
|
||||
void threading_free(){
|
||||
free(rgt_content);
|
||||
free(mid_content);
|
||||
free(lft_content);
|
||||
free(top_buffer);
|
||||
|
||||
pthread_mutex_destroy(&mutex_top);
|
||||
|
||||
69
window.c
69
window.c
@@ -14,17 +14,14 @@ extern unsigned int timeout_time;
|
||||
extern unsigned int color_count;
|
||||
extern color *colors;
|
||||
|
||||
extern file *mid_content;
|
||||
extern file *lft_content;
|
||||
extern file *rgt_content;
|
||||
extern dir rgt_dir;
|
||||
extern dir mid_dir;
|
||||
extern dir lft_dir;
|
||||
extern char *top_buffer;
|
||||
extern char *rgt_buffer;
|
||||
extern char *btm_buffer;
|
||||
|
||||
|
||||
extern unsigned long lft_file_count;
|
||||
extern unsigned long mid_file_count;
|
||||
extern unsigned long rgt_file_count;
|
||||
extern unsigned long top_width;
|
||||
|
||||
extern pthread_mutex_t mutex_top;
|
||||
@@ -34,22 +31,26 @@ extern pthread_mutex_t mutex_mid;
|
||||
extern pthread_mutex_t mutex_rgt;
|
||||
|
||||
void window_top(WINDOW *win){
|
||||
werase(win);
|
||||
|
||||
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*/
|
||||
wattron(win, COLOR_PAIR(COLOR_PATH));
|
||||
mvwaddstr(win, 0, 0, top_buffer);
|
||||
mvwaddch(win, 0, strlen(top_buffer), '/');
|
||||
wattroff(win, COLOR_PAIR(COLOR_PATH));
|
||||
if (mid_dir.file_count != 0) {
|
||||
mvwaddstr(win, 0, strlen(top_buffer)+1, mid_dir.current_file->file_name);
|
||||
}
|
||||
}
|
||||
wattroff(win, COLOR_PAIR(COLOR_PATH));
|
||||
pthread_mutex_unlock(&mutex_top);
|
||||
} else {
|
||||
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
/*
|
||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||
*/
|
||||
}
|
||||
}
|
||||
void window_btm(WINDOW *win){
|
||||
werase(win);
|
||||
|
||||
if (pthread_mutex_trylock(&mutex_btm) == 0) {
|
||||
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||
@@ -58,58 +59,60 @@ void window_btm(WINDOW *win){
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
/*the printing of the input char is done in user_interactions*/
|
||||
/*the printing of all possible inputs are done in user_interactions */
|
||||
} else {
|
||||
} else {
|
||||
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
/*
|
||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||
*/
|
||||
}
|
||||
}
|
||||
void window_lft(WINDOW *win){
|
||||
werase(win);
|
||||
|
||||
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);
|
||||
|
||||
} else {
|
||||
mvwaddstr(win, terminal_height/2, terminal_width/8, "LOADING");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
/*
|
||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||
*/
|
||||
}
|
||||
}
|
||||
void window_mid(WINDOW *win){
|
||||
werase(win);
|
||||
|
||||
if (pthread_mutex_trylock(&mutex_mid) == 0) {
|
||||
if (mid_file_count == 0) {
|
||||
if (mid_dir.file_count == 0) {
|
||||
mvwaddstr(win, 0, 0, "empty");
|
||||
} else {
|
||||
print_dir(win, 1, &mid_file_count, mid_content);
|
||||
print_dir(win, 1, &mid_dir);
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
} else {
|
||||
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
/*
|
||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||
*/
|
||||
}
|
||||
}
|
||||
void window_rgt(WINDOW *win){
|
||||
werase(win);
|
||||
|
||||
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
|
||||
if (rgt_file_count == 0) {
|
||||
if (rgt_content[0].file_type == FILE_TYPE_OPEN_FILE) {
|
||||
mvwaddnstr(win, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
||||
} else if (rgt_content->permissions & S_IRUSR) {
|
||||
mvwaddstr(win, 0, 0, "not accessible");
|
||||
} else {
|
||||
mvwaddstr(win, 0, 0, "empty");
|
||||
}
|
||||
|
||||
|
||||
if (!rgt_dir.current_file) {
|
||||
mvwaddstr(win, 0, 0, "not accessible");
|
||||
}else if (rgt_dir.current_file->file_type == FILE_TYPE_OPEN_FILE) {
|
||||
mvwaddnstr(win, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
||||
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
|
||||
mvwaddstr(win, 0, 0, "not accessible");
|
||||
} else {
|
||||
print_dir(win, 0, &rgt_file_count, rgt_content);
|
||||
print_dir(win, 0, &rgt_dir);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
} else {
|
||||
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
/*
|
||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user