1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-22 10:50:15 -04:00

Compare commits

..

64 Commits

Author SHA1 Message Date
nova
df726e2f32 delta time no longer reloading images 2025-10-13 23:09:57 +02:00
nova
140457e4b7 fixed copy/paste 2025-10-13 22:47:38 +02:00
nova
23654741bc fixed sort_extension, changes too small to list to other sort methods 2025-10-13 21:44:19 +02:00
nova
fa544204ba implemented jmp_file_index & int passes -> unsigned long 2025-10-12 01:44:27 +02:00
nova
61023ce42e temporary fixes & removal of unused function 2025-10-11 21:49:28 +02:00
nova
3fa16fd8b2 changes too small for proper commit message 2025-10-09 01:01:52 +02:00
nova
ac6d0e8408 avoiding useless memory read/writes & fixing race condition in btm_status 2025-10-09 00:13:25 +02:00
nova
731bfe722a fixing move_right on extensionless files 2025-10-08 23:49:34 +02:00
nova
3082fed378 fixed some race conditions and improved parsing storage size 2025-10-08 21:33:06 +02:00
nova
23ff0b07ec adding forgotten mutex unlocks 2025-10-05 21:56:56 +02:00
nova
c2d88f4909 moving stuff around to avoid 'previous implicit declaration' 2025-10-05 21:46:31 +02:00
nova
0b98e8eb68 removal of stray printf 2025-10-05 14:35:33 +02:00
nova
87ae2a5e8f refactoring of name shortening 2025-10-05 14:34:35 +02:00
nova
f0ad6295f7 removal of rand() in sort_rand 2025-10-05 00:57:18 +02:00
nova
e979209de3 slight likely branch improvements 2025-10-03 16:53:18 +02:00
nova
8fade0c4a8 profiling target added 2025-10-02 20:15:14 +02:00
nova
333d4d1df6 slight speed optimization 2025-10-02 20:14:53 +02:00
nova
c6763233bf resolved all compiler warnings so far 2025-09-30 22:05:26 +02:00
nova
7ee16c8f4a now accounting for hardlinks & refactored sorting 2025-09-30 21:54:56 +02:00
nova
b32848ad3d accounted for some race conditions 2025-09-29 21:40:35 +02:00
nova
4d9dc46691 yank_name now implemented 2025-09-29 21:10:34 +02:00
nova
8dcf88baea sum the size of the current dir 2025-09-29 20:10:40 +02:00
nova
8839f737c5 addded select_all 2025-09-29 19:29:31 +02:00
nova
36012b1a71 fixed image previews sticking around longer than expected 2025-09-29 19:17:23 +02:00
nova
4784ec3f64 fixed infinite loop on copy/paste 2025-09-29 19:13:37 +02:00
nova
d3e46846cd improvements to sort_rand 2025-09-28 10:45:33 +02:00
nova
21a11d8be1 fixed images not being flushed when going ontop of a directory 2025-09-24 23:14:20 +02:00
nova
b46d2da308 delta time to reload directory 2025-09-24 23:07:29 +02:00
nova
fe781c2d3c image previews can now be disabled 2025-09-24 22:44:13 +02:00
nova
fb1af6d2d2 now printing left storage & related refactoring 2025-09-24 22:20:07 +02:00
nova
14948ba573 fixed wrong condition being send 2025-09-22 19:20:14 +02:00
nova
e0a5871bc2 relative line numbers now show the index of the current file 2025-09-21 21:32:45 +02:00
nova
395c5fcb09 improvements to sort_natural 2025-09-21 21:30:15 +02:00
nova
525f205d67 recursive file deletion 2025-09-08 23:18:25 +02:00
nova
c923497f01 cast to unsigned char for proper sorting 2025-08-30 21:04:30 +02:00
nova
69f9a609e5 removal of socal_status 2025-08-30 21:01:40 +02:00
nova
5afabfb412 improvenments to random sort 2025-08-29 22:42:46 +02:00
nova
9f3042ccac improvenments to natural sort 2025-08-28 23:00:54 +02:00
nova
a05c3ecd96 search file function now does file previews 2025-08-24 20:09:32 +02:00
nova
4a9c38d034 handling of empty dirs 2025-08-24 19:45:08 +02:00
nova
ba1e95bca3 fixed images_clear ordering 2025-08-24 00:37:06 +02:00
nova
922881cd45 maximum size of file_previews 2025-08-24 00:04:24 +02:00
nova
59964cf828 moved left and rigth thread signaling into thread_mid 2025-08-23 23:21:30 +02:00
nova
e1c298ae50 removal of global file_current 2025-08-23 23:19:11 +02:00
nova
a57869a7a1 imrovenments to rendering 2025-08-23 22:48:46 +02:00
nova
520d4eca13 further thread pool stuff 2025-08-23 22:06:10 +02:00
nova
963a018419 removed the recreation and destruction of threads 2025-08-23 21:44:03 +02:00
nova
a0a102e5f6 tab completion in search and read_string 2025-08-23 20:58:48 +02:00
nova
0d2310cd7c searching now writes selected file in linked_dir 2025-08-23 20:48:19 +02:00
nova
3f90802663 refractoring, fixed enter_shell 2025-08-18 22:01:16 +02:00
nova
f25768d522 linked list to keep track of past directory indexes 2025-08-18 21:07:18 +02:00
nova
55cd4077b1 smart case search in file search 2025-08-17 23:21:28 +02:00
nova
3a2c226ed9 removed unnecessary render_pass 2025-08-17 21:54:35 +02:00
nova
1d54169c2d implemented file search 2025-08-17 21:29:49 +02:00
nova
f0a2f14966 improvenments to the renderer 2025-08-17 15:35:00 +02:00
nova
017bf407d9 relative lines 2025-08-17 01:46:54 +02:00
nova
2af21a0875 created dir.c & .h, improved header file handling 2025-08-17 00:54:13 +02:00
nova
9ea82511e6 added copy/paste function 2025-08-16 21:02:13 +02:00
nova
37d82bebf8 fixed N repetitions of movenment keys 2025-08-12 22:35:31 +02:00
nova
8b02e8e4e6 fixed visible cursor after exiting a sub program 2025-08-12 22:10:36 +02:00
nova
7526a9e6e5 implementation of jump_to_dir 2025-08-12 21:59:34 +02:00
nova
7b563894f7 improventments to navigation\; now ignoring inputs without associated binding. beginning of enter_shell 2025-08-10 14:12:37 +02:00
nova
7ab04a5a87 added image previews using ueberzug 2025-08-06 22:25:39 +02:00
nova
ec4d2dec8b proper permissions of makedir 2025-08-06 20:04:26 +02:00
16 changed files with 1709 additions and 850 deletions

View File

@@ -3,6 +3,7 @@ CFLAGS := -Wall -Wextra -O2 -flto=auto
CURSES := -lncursesw -ltinfow #utf8 support
#CURSES := -lncurses -tinfo #no utf8
CFLAGS_DEBUG := $(CFLAGS) -g
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
HELGRIND := valgrind --tool=helgrind --log-fd=9 9>>helgrind.log ./th
@@ -15,6 +16,9 @@ d:
$(CC) ./main.c -o th -std=c89 $(CFLAGS_DEBUG) $(CURSES)
$(GDB)
p:
$(CC) ./main.c -o th -std=c89 $(CFLAGS_PROFILE) $(CURSES)
v:
$(CC) ./main.c -o th -std=c89 $(CFLAGS_DEBUG) $(CURSES)
$(VALGRIND)

295
backend.c
View File

@@ -1,22 +1,5 @@
#define _POSIX_C_SOURCE 200809L
#include <curses.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include "defines.h"
#include "sorting.h"
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 color *colors;
int (*order_func)() = sort_natural;
char* concat(const char *s1, const char *s2){
const size_t len1 = strlen(s1);
@@ -26,254 +9,46 @@ char* concat(const char *s1, const char *s2){
memcpy(result + len1, s2, len2 + 1);
return result;
}
unsigned long get_dir_size(char *path){
DIR *dir = opendir(path);
unsigned long entry_count = 0;
if (dir) {
struct dirent *entry;
while ((entry=readdir(dir))) {
if (entry->d_name[0] != '.' || (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
entry_count++;
}
char* smartstrcasestr(char *haystack, const char *needle){
char smart = 0;
char *ret;
char passes = 0;
while (*needle) {
if (*needle >= 'A' && *needle <= 'Z') {
smart = 1;
break;
}
}
closedir(dir);
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
/* removes files "." and ".." */
entry_count -= 2;
passes++;
needle++;
}
return entry_count;
needle -= passes;
if (smart == 0) {
char *needle_case = malloc(strlen(needle)+1);
strcpy(needle_case, needle);
passes = 0;
while (*needle_case) {
*needle_case = *needle_case | ' ';
needle_case++;
passes++;
}
needle_case -= passes;
}
char *haystack_case = malloc(strlen(haystack)+1);
strcpy(haystack_case, haystack);
passes = 0;
while (*haystack_case) {
*haystack_case = *haystack_case | ' ';
haystack_case++;
passes++;
}
haystack_case -= passes;
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
struct dirent **entry;
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
scandir(path, &entry, skip_dot, alphasort);
ret = strstr(haystack_case, needle_case);
free(needle_case);
free(haystack_case);
} else {
scandir(path, &entry, skip_hidden_files, alphasort);
ret = strstr(haystack, needle);
}
unsigned long i = 0;
for (i = 0; i < *dir_file_count; i++ ) {
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_content[i].file_name[strlen(entry[i]->d_name)] = '\0';
struct stat *file;
file = malloc(sizeof(struct stat));
memset(file, ' ', sizeof(struct stat));
/* using the full path allows using the same function for all windows */
unsigned long path_len = strlen(path);
char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/"));
memcpy(full_path, path, strlen(path));
memcpy(full_path + path_len, "/", sizeof("/"));
memcpy(full_path + path_len + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
lstat(full_path, file);
dir_content[i].file_size = file->st_size;
dir_content[i].permissions = 1;
dir_content[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)) {
dir_content[i].file_type = FILE_TYPE_SYMLINK;
dir_content[i].color_pair = COLOR_SYMLINK;
dir_content[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;
} else if (S_ISBLK(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_BLOCK;
dir_content[i].color_pair = COLOR_BLOCK;
} else if (S_ISCHR(file->st_mode)) {
dir_content[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;
} else if (S_ISSOCK(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_SOCK;
dir_content[i].color_pair = COLOR_SOCK;
} else if (S_ISREG(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_REGULAR;
dir_content[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 (!strcmp(colors[j].file_extension, extension)) {
dir_content[i].color_pair = colors[j].color_pair;
}
}
} else {
}
} else {
dir_content[i].file_type = COLOR_REGULAR;
dir_content[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 (!strcmp(colors[j].file_extension, extension)) {
dir_content[i].color_pair = colors[j].color_pair;
}
}
} else {
}
}
free(full_path);
free(file);
}
}
qsort(dir_content, *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){
/* 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;
char size_char = ' ';
char is_selected = 0;
static const char sizes[6] = { 'B', 'K', 'M', 'G', 'T', 'P' };
unsigned long offset_vertical = 0;
unsigned long offset_back = 0;
unsigned long offset_front = 2;
if (print_info) {
if (*dir_file_count > 9) {
offset_front = (snprintf(NULL, 0, "%ld", *dir_file_count)) + 1;
}
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;
}
}
}
for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) {
if (print_info) {
file_size = dir_content[i].file_size;
char size_index = 0;
while (file_size > 1) {
printed_size=file_size;
file_size /= 1024;
size_index++;
if (size_index >= 6) {
break;
}
}
size_char = sizes[size_index-1];
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[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 {
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
}
}
if (dir_content[i].status & FILE_STATUS_SELECTED) {
is_selected = 1;
} else {
is_selected = 0;
}
if (dir_content[i].status & FILE_STATUS_SELECTED) {
wattron(win, COLOR_PAIR(8));
} else {
wattron(win, COLOR_PAIR(dir_content[i].color_pair));
}
if (dir_content[i].status & FILE_STATUS_HOVER) {
wattron(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 file_name_width = strlen(dir_content[i].file_name);
if ((file_name_width + offset_front + is_selected) > offset_back - 1) {
char *extension = strrchr(dir_content[i].file_name, '.');
if (extension) {
int char_offset = (file_name_width + offset_front + is_selected) - (offset_back - 1) ;
if ((file_name_width - char_offset - strlen(extension) - 1) > 1) {
file_name = malloc(file_name_width - char_offset + 1);
memcpy(file_name, dir_content[i].file_name, file_name_width - char_offset);
memcpy(file_name + (file_name_width - char_offset - strlen(extension)), extension, strlen(extension));
file_name[file_name_width - char_offset - strlen(extension) - 1] = '~';
file_name[file_name_width - char_offset] = '\0';
} else {
file_name = malloc(strlen(extension)+1);
file_name[0] = '~';
memcpy(file_name+1, extension, strlen(extension));
file_name[strlen(extension)] = '\0';
}
} else {
file_name = malloc(file_name_width+1);
memcpy(file_name, dir_content[i].file_name, file_name_width);
file_name[file_name_width] = '\0';
}
} else {
file_name = malloc(file_name_width+1);
memcpy(file_name, dir_content[i].file_name, file_name_width);
file_name[file_name_width] = '\0';
}
mvwaddstr(win, i-offset_vertical, 0, bg);
if(print_info) {
mvwprintw(win, i-offset_vertical, 0, "%ld", i);
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
free(file_name);
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[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);
}
if (dir_content[i].status & FILE_STATUS_HOVER) {
wattroff(win, A_REVERSE);
}
if (dir_content[i].status & FILE_STATUS_SELECTED) {
wattroff(win, COLOR_PAIR(8));
} else {
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
}
}
free(bg);
return ret;
}

View File

@@ -1,7 +1,9 @@
#include <curses.h>
#ifndef BACKEND_GUARD
#define BACKEND_GUARD
#include "backend.c"
#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);
char* concat(const char *s1, const char *s2);
char* smartstrcasestr(char *haystack, const char *needle);

126
config.h
View File

@@ -1,7 +1,14 @@
#include "defines.h"
#include "interactions.h"
#include "sorting.h"
#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 */
/* {{{ */
#ifndef CONFIG_GUARD
#define CONFIG_GUARD
#include "defines.h"
#include "sorting.h"
#include "interactions.h"
/* }}} */
static const mimetype mimetype_default_cmd[] = {
/* mimetype shell command
@@ -35,53 +42,88 @@ static const binding key_binding[] = {
* not possible: gg, ggg
* trying to use ggg will always fail as it will execute gg first instead, resetting the input buffer, thus never reaching ggg */
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
{ "q", quit_program, NULL, "quit" },
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
{ "/", not_implemented, NULL, "search" },
{ "q", quit_program, NULL, "quit" },
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
{ "v", select_all, NULL, "select all files in dir" },
{ "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" },
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
{ "t", move_down, NULL, "move down" },
{ "n", move_up, NULL, "move up" },
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
{ "t", move_down, NULL, "move down" },
{ "n", move_up, NULL, "move up" },
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
{ "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 */
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
* this means that it does not delete the hovered files if files are already selected */
{ "yn", yank_text, "name", "yank filename of hovered file" },
{ "yp", yank_text, "path", "yank path of hovered file" },
{ "yy", yank_file, "copy", "copy/yank file/directory" },
{ "dd", yank_file, "cut", "cut file/directory" },
{ "pp", paste, NULL, "paste" },
{ "G", jump_bottom, NULL, "jump to last file in dir" },
{ "gg", jump_top, NULL, "jump to first file in dir" },
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
{ "go", jump_to_dir, "/opt", "jump to /opt" },
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
{ "gv", jump_to_dir, "/var", "jump to /var" },
{ "G", jump_bottom, NULL, "jump to last file in dir" },
{ "gg", jump_top, NULL, "jump to first file in dir" },
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" }, /* 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" },
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
{ "go", jump_to_dir, "/opt", "jump to /opt" },
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
{ "gv", jump_to_dir, "/var", "jump to /var" },
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
{ "on", order_by, sort_natural, "order natural" },
{ "or", not_implemented, "", "order reverse" },
{ "oe", not_implemented, "", "order extension" },
{ "os", order_by, sort_size, "order size" },
{ "ot", order_by, sort_type, "order type" },
{ "oz", order_by, sort_random, "order random" },
{ "oa", order_by, sort_alpha, "order alphabetically" },
{ "on", order_by, sort_natural, "order natural" },
{ "oe", order_by, sort_extension, "order extension" },
{ "os", order_by, sort_size, "order size" },
{ "ot", order_by, sort_type, "order type" },
{ "or", order_by, sort_random, "order random" },
{ "oa", order_by, sort_alpha, "order alphabetically" },
{ "mk", makedir, NULL, "create directory" },
{ "mf", makefile, NULL, "create file" },
{ "mk", makedir, NULL, "create directory" },
{ "mf", makefile, NULL, "create file" },
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
{ "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace/delete key */
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
{ "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace key */
};
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 unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension);
static const char size_unit_count = (sizeof(size_unit) / sizeof(size_unit[0])) - 1;
#else
static const char clipboard_cmd[];
static const mimetype mimetype_default_cmd[];
static const extension file_extension_default_cmd[];
static const binding key_binding[];
static const unsigned long binding_count;
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;
#endif
/* }}} */

View File

@@ -8,6 +8,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_DELTA_TIME 256
#define SETTINGS_HAS_COLOR 1
@@ -24,8 +26,7 @@
#define FILE_STATUS_HOVER 1
#define FILE_STATUS_SELECTED 2
#define FILE_STATUS_IS_REGULAR_FILE 4
#define FILE_STATUS_DIR_EMPTY 64 /* if a directory is empty */
#define FILE_STATUS_FILE_OPEN 128 /* only used for file previews */
#define FILE_STATUS_FILE_OPEN 64 /* only used for file previews */
#define COLOR_UNKNOWN 0
#define COLOR_DIR 1
@@ -39,18 +40,22 @@
#define COLOR_ORPHAN 9
#define COLOR_PATH 10
#define FILE_TYPE_UNKNOWN COLOR_UNKNOWN
#define FILE_TYPE_DIR COLOR_DIR
#define FILE_TYPE_EXEC COLOR_EXEC
#define FILE_TYPE_REGULAR COLOR_REGULAR
#define FILE_TYPE_SYMLINK COLOR_SYMLINK
#define FILE_TYPE_BLOCK COLOR_BLOCK
#define FILE_TYPE_CHARDEV COLOR_CHARDEV
#define FILE_TYPE_SOCK COLOR_SOCK
#define FILE_TYPE_FIFO COLOR_FIFO
#define FILE_TYPE_ORPHAN COLOR_ORPHAN
#define FILE_TYPE_UNKNOWN 0
#define FILE_TYPE_EXEC 1
#define FILE_TYPE_REGULAR 2
#define FILE_TYPE_BLOCK 3
#define FILE_TYPE_CHARDEV 4
#define FILE_TYPE_SOCK 5
#define FILE_TYPE_FIFO 6
#define FILE_TYPE_ORPHAN 7
#define FILE_TYPE_DIR 32
#define FILE_TYPE_SYMLINK 64
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
#define YANK_IS_USED 1
#define YANK_CUT 2
#define YANK_COPY 4
#ifndef STRUCT_GUARD
#define STRUCT_GUARD
/* complex types are good actually */
@@ -80,6 +85,16 @@ typedef struct Binding {
void* black_magic;
char* comment;
} binding;
typedef struct Yank {
char status;
char *path;
char **list;
unsigned long count;
} yank;
typedef struct Linked_dir {
char *path;
unsigned long selected_file_current;
struct Linked_dir *next;
} linked_dir;
#endif

422
dir.c Normal file
View File

@@ -0,0 +1,422 @@
#include <curses.h>
#include <pthread.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "sorting.h"
#include "defines.h"
#include "config.h"
extern file *mid_content;
extern unsigned long mid_file_count;
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 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);
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] != '.') {
entry_count++;
}
}
}
closedir(dir);
return entry_count;
}
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
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);
}
unsigned long i = 0;
for (i = 0; i < *dir_file_count; i++ ) {
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);
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("/"));
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;
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)) {
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);
} else {
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
dir_content[i].color_pair = COLOR_SYMLINK;
}
} else if (file->st_mode & S_IXUSR) {
dir_content[i].file_type = FILE_TYPE_EXEC;
dir_content[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;
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;
}
}
}
} else if (S_ISBLK(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_BLOCK;
dir_content[i].color_pair = COLOR_BLOCK;
} else if (S_ISCHR(file->st_mode)) {
dir_content[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;
} else if (S_ISSOCK(file->st_mode)) {
dir_content[i].file_type = FILE_TYPE_SOCK;
dir_content[i].color_pair = COLOR_SOCK;
} else {
dir_content[i].file_type = COLOR_REGULAR;
dir_content[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;
}
}
} else {
}
}
free(full_path);
free(file);
}
}
qsort(dir_content, *dir_file_count, sizeof(file), order_func);
for (i = 0; i < *dir_file_count; i++) {
free(entry[i]);
}
if (entry != NULL) {
free(entry);
} else {
}
}
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content){
/* 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;
char size_char = ' ';
char is_selected = 0;
unsigned long offset_vertical = 0;
unsigned long offset_back = 0;
#if SETTINGS_LINE_NUMBERS == 0
unsigned long offset_front = 0;
#else
long offset_front = 2;
#endif
long offset_index = 2; /* only used for the index of the file itself */
if (print_info) {
if (*dir_file_count > 9) {
#if SETTINGS_LINE_NUMBERS != 0
unsigned long dir_file_count_ = *dir_file_count;
while(dir_file_count_ > 9) {
offset_front++;
dir_file_count_ /= 10;
}
#endif
}
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;
}
}
} else {
offset_front = 0;
}
for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) {
if (print_info) {
file_size = dir_content[i].file_size;
char size_index = -1;
do {
printed_size=file_size;
file_size /= 1024;
size_index++;
} 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);
} else if (size_char =='B') {
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
} else {
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
}
} else {
offset_back = line_width;
}
if (dir_content[i].status & FILE_STATUS_SELECTED) {
is_selected = 1;
} else {
is_selected = 0;
}
if (dir_content[i].status & FILE_STATUS_SELECTED) {
wattron(win, COLOR_PAIR(8));
} else {
wattron(win, COLOR_PAIR(dir_content[i].color_pair));
}
if (dir_content[i].status & FILE_STATUS_HOVER) {
wattron(win, A_REVERSE);
} 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 = NULL;
unsigned long printable_size = (offset_back - is_selected - offset_front);
if (strlen(dir_content[i].file_name) > printable_size) {
char *extension = strrchr(dir_content[i].file_name, '.');
if (extension && extension != dir_content[i].file_name) {
file_name = malloc(printable_size);
printable_size -= strlen(extension);
memcpy(file_name, dir_content[i].file_name, printable_size);
memcpy(file_name + printable_size-1, extension, strlen(extension));
file_name[printable_size + strlen(extension)-1] = '\0';
file_name[printable_size - 2] = '~';
} else {
file_name = malloc(printable_size-1);
memcpy(file_name, dir_content[i].file_name, printable_size);
file_name[printable_size-2] = '~';
file_name[printable_size-1] = '\0';
}
} else {
file_name = malloc(strlen(dir_content[i].file_name)+1);
memcpy(file_name, dir_content[i].file_name, strlen(dir_content[i].file_name)+1);
}
mvwaddstr(win, i-offset_vertical, 0, bg);
if(print_info) {
#if SETTINGS_LINE_NUMBERS == 2
long i_ = (selected_file_current) - i;
offset_index = 0;
while(i_) {
offset_index++;
i_ /= 10;
}
long relative_index = selected_file_current - i;
if (relative_index < 0) {
relative_index = relative_index * -1;
} else if (relative_index == 0) {
i_ = (selected_file_current != 0) ? (selected_file_current) : 1;
while(i_) {
offset_index++;
i_ /= 10;
}
relative_index = i;
}
mvwprintw(win, i-offset_vertical, offset_front-offset_index-1, "%ld", relative_index);
#elif SETTINGS_LINE_NUMBERS == 1
unsigned long i_ = i;
offset_index = 2;
while(i_ > 9) {
offset_index++;
i_ /= 10;
}
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);
}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);
}
if (file_name != NULL) {
/* sometimes NULL remains, need to do deeper analysis soon */
free(file_name);
} else {
printf("file_name remains NULL on %s, if this happens consistent on the same file, please inform me", dir_content[i].file_name);
volatile static int debug_print_dir;
debug_print_dir++;
}
if (dir_content[i].status & FILE_STATUS_SELECTED) {
wattroff(win, COLOR_PAIR(8));
} else {
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
}
}
free(bg);
}
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;
break;
}
current_dir = current_dir->next;
}
if (hit == 0) {
current_dir->next = malloc(sizeof(linked_dir));
current_dir->next->next = NULL;
current_dir->next->path = path;
return 0;
} else {
free(path);
return current_dir->selected_file_current;
}
}
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;
}
void recursive_delete(file current_file){
if (current_file.file_type & FILE_TYPE_DIR) {
unsigned int file_modifiers_tmp = file_modifiers;
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
unsigned long current_file_count = get_dir_size(current_file.file_name);
if (current_file_count != 0) {
file *current_dir = malloc(current_file_count * sizeof(file));
memset(current_dir, '\0', current_file_count * sizeof(file));
get_dir_content(current_file.file_name, &current_file_count, current_dir);
if (chdir(current_file.file_name) != 0) {
return;
}
unsigned long i;
for (i = 0; i < current_file_count; i++) {
recursive_delete(current_dir[i]);
free(current_dir[i].file_name);
}
free(current_dir);
if (chdir("..") != 0) {
return;
}
}
remove(current_file.file_name);
file_modifiers = file_modifiers_tmp;
} else {
remove(current_file.file_name);
}
}

13
dir.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef DIR_GUARD
#define DIR_GUARD
#include "dir.c"
#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);
char update_selected_file();
void dir_set_selected_file_current(unsigned long selected_file_current);
unsigned long dir_get_selected_file_current();
void dir_init();
void recursive_delete(file current_file);

View File

@@ -1,10 +1,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defines.h"
#include "backend.h"
#include "defines.h"
#include "config.h"
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
static FILE *ueberzug = NULL;
#endif
extern unsigned int terminal_height;
extern unsigned int terminal_width;
char previewd;
char* text(char *path, unsigned long *file_size);
void images_print(char *file_name);
void images_clear();
char* generic(char *path);
char* get_mimetype(char *path){
@@ -38,21 +49,36 @@ char* preview_file(char *file_name, unsigned long file_size){
char *mime = get_mimetype(file_name);
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
images_clear();
#endif
if (strstr(mime, "text")) {
file_buffer = text(file_name, &file_size);
} else {
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
} else if (strstr(mime, "image")) {
file_buffer = generic(file_name);
images_print(file_name);
previewd = 1;
#endif
} else {
file_buffer = generic(file_name);
}
free(mime);
return file_buffer;
}
char* text(char *path, unsigned long *file_size){
char *file_buffer = malloc(*file_size + 1);
unsigned long size = (terminal_width/2) * terminal_height;
if (size > *file_size) {
size = *file_size;
}
char *file_buffer = malloc(size + 1);
FILE *fp = fopen(path, "r");
if (fread(file_buffer, *file_size, 1, fp) != 0) {
file_buffer[*file_size] = '\0';
if (fread(file_buffer, size, 1, fp) != 0) {
file_buffer[size] = '\0';
return file_buffer;
} else {
return "failed reading file";
@@ -73,3 +99,38 @@ char* generic(char *path){
return "failed executing shell command \"file\"";
}
}
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
void images_clear(){
if (previewd == 1) {
fprintf(ueberzug, "{\"action\": \"remove\", \
\"identifier\": \"preview\"}\n");
fflush(ueberzug);
previewd = 0;
}
}
void images_print(char *file_name){
char *path=getcwd(NULL, 0);
fprintf(ueberzug, "{\"action\":\"add\", \
\"identifier\":\"preview\", \
\"max_height\":%d, \
\"max_width\":%d, \
\"y\":0, \
\"x\":%d, \
\"path\":\"%s/%s\"}\n", terminal_height, terminal_width/2, terminal_width/2, path, file_name);
fflush(ueberzug);
free(path);
}
void ueberzug_init(){
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW == 2
ueberzug = popen("ueberzug layer -s ", "w");
#elif SETTINGS_UEBERZUG_IMAGE_PREVIEW == 1
ueberzug = popen("ueberzug layer -s --no-cache ", "w");
#endif
}
void ueberzug_close(){
images_clear();
pclose(ueberzug);
}
#endif

View File

@@ -1,5 +1,13 @@
#ifndef PREVIEW_GUARD
#define PREVIEW_GUARD
#include "file_previews.c"
#include "defines.h"
#include "config.h"
#endif
char* preview_file(char *file_name, unsigned long file_size);
char* get_mimetype(char *path);
void images_clear();
void ueberzug_init();
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
void ueberzug_close();
#endif

View File

@@ -2,14 +2,14 @@
#include <pthread.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <signal.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include "file_previews.h"
#include "backend.h"
#include "defines.h"
#include "config.h"
#include "config.h"
#include "dir.h"
extern volatile unsigned long selected_file_current;
@@ -19,10 +19,11 @@ 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 volatile file *file_current;
extern unsigned int terminal_height;
extern unsigned int terminal_width;
@@ -34,15 +35,18 @@ extern char *btm_buffer;
extern unsigned long mid_file_count;
extern unsigned int status;
unsigned int timeout_time = 0;
extern char *input;
unsigned int input_pass;
int parsed_input_number;
extern char *start_path;
extern char *input;
extern time_t *seed;
char search_buffer[255];
unsigned int timeout_time = 0;
unsigned int input_pass;
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)();
@@ -54,7 +58,6 @@ void FAIL(char *function, char *str){
curs_set(1);
echo();
printf("ERROR in function %s: %s", function, str);
kill(getpid(),9);
}
void user_interactions() {
@@ -67,31 +70,34 @@ void user_interactions() {
ch = getch();
if(ch != ERR) {
timeout(1); /* blocking timeout of getch() */
timeout(10); /* 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);
input_pass = 0;
timeout(100); /* blocking timeout of getch() */
status |= STATUS_UPDATE_SCREEN_0;
}
binding_pass = 0;
status |= STATUS_UPDATE_SCREEN_0;
status |= STATUS_UPDATE_SCREEN_0;
} else {
timeout(100);
}
void (*func_ptr)(int, int);
int number_length = 0;
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++;
mvaddch(terminal_height-5, 5, number_length+48);
}
input -= number_length;
binding_pass = 1;
@@ -106,24 +112,25 @@ void user_interactions() {
func_ptr = key_binding[i].func;
func_ptr(parsed_input_number, i);
memset(input, 0, 255);
input_pass = 0;
binding_pass = 0;
number_length = 0;
timeout(100); /* blocking timeout of getch() */
} else if (strncmp(input+number_length, key_binding[i].key, cmp_len) == 0) {
} else if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
binding_matches++;
attron(A_UNDERLINE);
mvaddstr(terminal_height-binding_matches-2, 0, "input");
mvaddstr(terminal_height-binding_matches-2, sizeof("input"), "\t\t\t");
mvaddstr(terminal_height-binding_matches-2, sizeof("input") + sizeof("\t\t\t"), "command");
attroff(A_UNDERLINE);
mvaddstr(terminal_height-binding_matches-1, 0, key_binding[i].key);
mvaddstr(terminal_height-binding_matches-1, 0, key_binding[i].key);
mvaddstr(terminal_height-binding_matches-1, sizeof(key_binding[i].key), "\t");
mvaddstr(terminal_height-binding_matches-1, sizeof(key_binding[i].key) + sizeof("\t"), key_binding[i].comment);
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);
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, 255);
input_pass = 0;
binding_pass = 0;
number_length = 0;
timeout(100); /* blocking timeout of getch() */
}
}
}
int read_string(WINDOW *win, int y, int x, char *str){
@@ -142,14 +149,18 @@ int read_string(WINDOW *win, int y, int x, char *str){
if (ch == '\n') {
err = 0;
break;
} else if (ch == 27) { /* esc key */
err = 1;
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);
} else if (ch == 127) { /* backspace */
if (pass > 0) {
pass--;
mvwdelch(win, y, pass);
}
} else if (ch == 27) { /* esc key */
err = 1;
break;
} else {
mvwaddch(win, y, x +pass, ch);
str[pass] = ch;
@@ -158,96 +169,100 @@ int read_string(WINDOW *win, int y, int x, char *str){
}
str[pass] = '\0';
timeout(10);
timeout(100);
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(){
void select_all(){
pthread_mutex_lock(&mutex_selection);
pthread_mutex_lock(&mutex_mid);
mid_content[selected_file_current].status ^= FILE_STATUS_SELECTED;
file_current->status ^= FILE_STATUS_SELECTED;
status |= (STATUS_UPDATE_SCREEN_MASK);
unsigned long i;
for(i = 0; i < mid_file_count; i++) {
mid_content[i].status ^= FILE_STATUS_SELECTED;
}
pthread_mutex_unlock(&mutex_mid);
pthread_mutex_unlock(&mutex_selection);
}
void move_down(int passes){
void move_down(unsigned long passes){
pthread_mutex_lock(&mutex_selection);
if (passes == 0) {
passes++;
}
/*capping the maximum file is done inside thread_mid */
selected_file_current += passes;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
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){
void move_up(unsigned long passes){
pthread_mutex_lock(&mutex_selection);
if (passes == 0) {
passes++;
}
int i;
for (i = 0; i < passes; i++) {
if (selected_file_current != 0) {
selected_file_current--;
}
unsigned long tmp = selected_file_current;
selected_file_current -= passes;
if (tmp < selected_file_current) {
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);
}
void move_left(int passes){
void move_left(unsigned long passes){
if (passes == 0) {
passes++;
}
int i;
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();
}
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void move_right(){
if (file_current->file_type == FILE_TYPE_DIR || file_current->file_type == FILE_TYPE_SYMLINK) {
if (chdir(file_current->file_name) != 0) {
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();
}
} else {
unsigned long i = 0;
char match = 0;
char *mime = get_mimetype(file_current->file_name);
char *extension = strrchr(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, file_current->file_name);
cmd = concat(cmd, "\"");
char *mime = get_mimetype(mid_content[selected_file_current].file_name);
char *extension = strrchr(mid_content[selected_file_current].file_name, '.');
if (extension != NULL) {
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*/
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);
break;
}
match = 1;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
break;
}
}
if (match == 0) {
@@ -255,7 +270,7 @@ void move_right(){
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
cmd = concat(cmd, file_current->file_name);
cmd = concat(cmd, mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\"");
btm_buffer = malloc(strlen(cmd));
@@ -265,6 +280,7 @@ void move_right(){
if (system(cmd) == -1) {
/*do nothing*/
}
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);
break;
@@ -273,27 +289,43 @@ void move_right(){
}
free(mime);
}
update_selected_file();
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void toggle_hidden_files(){
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
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);
move_down(1);
}
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);
}
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);
}
void open_with(){
btm_buffer = concat("open \"", file_current->file_name);
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;
@@ -314,9 +346,13 @@ void open_with(){
if (!err) {
char *cmd = concat(str, " ./\"");
cmd = concat(cmd, file_current->file_name);
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");
}
@@ -332,8 +368,9 @@ void open_with(){
}
void rename_hovered(){
pthread_mutex_lock(&mutex_btm);
btm_buffer = concat("rename \"", file_current->file_name);
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name);
btm_buffer = concat(btm_buffer, "\" to:");
status |= STATUS_UPDATE_SCREEN_0;
@@ -341,7 +378,9 @@ void rename_hovered(){
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);
@@ -353,7 +392,7 @@ void rename_hovered(){
if (!err) {
char *cmd = concat("mv ./\"", file_current->file_name);
char *cmd = concat("mv ./\"", mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\" ./\"");
cmd = concat(cmd, str);
cmd = concat(cmd, "\"");
@@ -363,6 +402,7 @@ void rename_hovered(){
};
btm_buffer = cmd;
}
pthread_mutex_unlock(&mutex_btm);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
@@ -371,7 +411,8 @@ void rename_hovered(){
}
void delete(){
pthread_mutex_lock(&mutex_btm);
unsigned int i = 0;
unsigned int hits = 0;
char *file_str = " ";
@@ -387,7 +428,7 @@ void delete(){
if (hits) {
btm_buffer = concat("delete:", file_str);
} else {
btm_buffer = concat("delete: \"", file_current->file_name);
btm_buffer = concat("delete: \"", mid_content[selected_file_current].file_name);
btm_buffer = concat(btm_buffer, "\"");
}
@@ -400,8 +441,9 @@ void delete(){
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 */
@@ -409,32 +451,22 @@ void delete(){
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 */
int error;
if (hits) {
int j = 2;
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
error = remove(mid_content[i].file_name);
if (error != 0) {
mvaddstr(terminal_height-j, 0, "could not delete: " );
mvaddstr(terminal_height-j, strlen("could not delete: "), mid_content[i].file_name);
j++;
}
recursive_delete(mid_content[i]);
}
}
free(btm_buffer);
btm_buffer = concat("deleted: ", file_str);
} else {
free(btm_buffer);
error = remove(file_current->file_name);
if (error != 0) {
mvaddstr(terminal_height-2, 0, "could not delete: " );
mvaddstr(terminal_height-2, strlen("could not delete: "), mid_content[i].file_name);
btm_buffer = " ";
} else {
btm_buffer = concat("deleted: \"", file_current->file_name);
btm_buffer = concat(btm_buffer, "\"");
}
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
recursive_delete(mid_content[selected_file_current]);
}
remove(mid_content[selected_file_current].file_name);
btm_buffer = concat("deleted: \"", mid_content[selected_file_current].file_name);
btm_buffer = concat(btm_buffer, "\"");
}
/*system(cmd);*/
@@ -450,15 +482,22 @@ void delete(){
if (hits) {
free(file_str);
}
pthread_mutex_unlock(&mutex_btm);
}
void makedir(){
btm_buffer = "create dir: ";
status |= STATUS_UPDATE_SCREEN_0;
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);
@@ -469,18 +508,26 @@ void makedir(){
int err = read_string(win_b, local_height - 1, 0, str);
if (!err) {
btm_buffer = concat(btm_buffer, str);
mkdir(str, 755); /*magic number from default permissions as created by mkdir*/
mode_t mask = umask(0);
mkdir(str, 0755); /*magic number from default permissions as created by mkdir*/
umask(mask);
}
free(str);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
pthread_mutex_unlock(&mutex_btm);
}
void makefile(){
btm_buffer = "create file: ";
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);
@@ -496,31 +543,105 @@ void makefile(){
fclose(fp);
}
free(str);
pthread_mutex_unlock(&mutex_btm);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
}
void update(){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
}
void not_implemented(int passes, int index){
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");
void enter_shell(unsigned long 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*/
}
initscr();
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
}
void jump_to_dir(int passes, int index){
if ((char*)key_binding[index].black_magic) {
if (chdir(getenv((char*)key_binding[index].black_magic+1)) != 0) {
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
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");
}
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);
}
} 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();
}
/*env_parsed shall not be modified (read: free'd) - the man page*/
if (env_str) {
free(env_str);
}
if(path) {
free(path);
}
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 = NULL;
seed = malloc(sizeof(time_t));
*seed = time(NULL);
order_func = key_binding[index].black_magic;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | 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 = " ";
@@ -537,7 +658,7 @@ void cmd_on_selected(int passes, int index){
btm_buffer = concat(key_binding[index].black_magic, file_str);
} else {
btm_buffer = concat(key_binding[index].black_magic, "\"");
btm_buffer = concat(btm_buffer, file_current->file_name);
btm_buffer = concat(btm_buffer, mid_content[selected_file_current].file_name);
btm_buffer = concat(btm_buffer, "\"");
}
@@ -550,7 +671,9 @@ void cmd_on_selected(int passes, int index){
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 */
@@ -574,12 +697,12 @@ void cmd_on_selected(int passes, int index){
}
}
free(btm_buffer);
btm_buffer = concat("completed: ", key_binding[index].black_magic);
memcpy(btm_buffer, "completed: ", strlen("completed: "));
} else {
free(btm_buffer);
free(cmd);
cmd = concat((char*)key_binding[index].black_magic, " \"");
cmd = concat(cmd, file_current->file_name);
cmd = concat(cmd, mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\"");
if (system(cmd) != 0) {
/*do nothing*/
@@ -592,7 +715,7 @@ void cmd_on_selected(int passes, int index){
} else {
free(btm_buffer);
btm_buffer = "cancled deletion";
memcpy(btm_buffer, "cancled deletion", strlen("cancled deletion"));
}
timeout(10);
@@ -601,4 +724,236 @@ void cmd_on_selected(int passes, int index){
if (hits) {
free(file_str);
}
pthread_mutex_unlock(&mutex_btm);
}
void yank_text(unsigned long passes, int index){
(void)passes;
char *cmd;
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
char *path=getcwd(NULL, 0);
cmd = concat("echo \"", path);
cmd = concat(cmd, "/");
cmd = concat(cmd, mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\" | ");
cmd = concat(cmd, clipboard_cmd);
free(path);
} else {
cmd = concat("echo \"", mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\" | ");
cmd = concat(cmd, clipboard_cmd);
}
if (system(cmd) == -1) {
/*do nothing*/
}
free(cmd);
}
void yank_file(unsigned long passes, int index){
(void)passes;
unsigned long i;
if (yank_files.status & YANK_IS_USED) {
for (i = 0; i < yank_files.count; i++) {
free(yank_files.list[i]);
}
free(yank_files.list);
free(yank_files.path);
yank_files.count = 0;
yank_files.status = 0;
}
yank_files.path=getcwd(NULL, 0);
yank_files.count = 0;
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
yank_files.count++;
}
}
if (yank_files.count == 0) {
yank_files.count = 1;
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
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++) {
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 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 -riv ", yank_files.path);
} else {
cmd = concat("mv ", yank_files.path);
}
cmd = concat(cmd, "/");
cmd = concat(cmd, *yank_files.list);
cmd = concat(cmd, " ./");
cmd = concat(cmd, *yank_files.list);
cmd = concat(cmd, " 2>&1");
char *line = malloc(255);
FILE *cmd_open;
while (1) {
cmd_open = popen(cmd, "r");
if (fgets(line, 255, cmd_open) == 0) {
break;
}
if (strstr(line, "are the same file")) {
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
cmd = concat(cmd, "_");
cmd = concat(cmd, " 2>&1");
} else if ((strstr(line, "overwrite"))) {
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
cmd = concat(cmd, "_");
cmd = concat(cmd, " 2>&1");
} else if ((strstr(line, "No such file or directory"))) {
pclose(cmd_open);
break;
} else if (pclose(cmd_open) == 0) {
break;
}
pclose(cmd_open);
}
free(cmd);
yank_files.list++;
}
yank_files.list -= yank_files.count;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
}
void search(){
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);
curs_set(1);
timeout(-1); /* negative numbers block until enter is pressed */
unsigned int pass = 0;
char ch;
wmove(win_b, local_height-1, 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') {
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);
} else if (ch == 127) { /* backspace */
mvwdelch(win_b, local_height-1, 1);
wdelch(win_b);
if (pass != 0) {
search_buffer[pass-1] = '\0';
pass--;
}
} else if (ch == 27) { /* esc key */
break;
} else {
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);
break;
}
render_pass();
}
}
}
search_buffer[pass] = '\0';
timeout(10);
curs_set(0);
dir_set_selected_file_current(selected_file_current);
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();
break;
}
}
}
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();
break;
}
}
}
void jmp_file_index(){
char *index = malloc(255);
memset(index, ' ', 255);
index[254] = '\0';
unsigned long local_height;
local_height = getmaxy(win_b);
read_string(win_b, local_height - 1, 0, index);
unsigned long new_index = 0;
while((*index >= '0') && (*index <= '9')) {
new_index = (new_index * 10) + (*index - '0');
index++;
}
if (new_index > mid_file_count) {
selected_file_current = mid_file_count;
} else {
selected_file_current = new_index;
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
update_selected_file();
}

View File

@@ -1,5 +1,3 @@
#include <curses.h>
#include <pthread.h>
#ifndef INTERACTIONS_GUARD
#define INTERACTIONS_GUARD
#include "interactions.c"
@@ -9,10 +7,11 @@
void user_interactions();
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();
@@ -22,7 +21,15 @@ void delete();
void makedir();
void makefile();
void update();
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 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_text(unsigned long passes, int index);
void yank_file(unsigned long passes, int index);
void paste();
void search();
void search_next();
void search_previous();
void jmp_file_index();

72
main.c
View File

@@ -2,15 +2,17 @@
#include <curses.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/sysinfo.h>
#include <string.h>
#include <locale.h>
#include "threading.h"
#include "window.h"
#include <time.h>
#include "defines.h"
#include "threading.h"
#include "window.c"
#include "colors.h"
#include "interactions.h"
unsigned int terminal_height;
unsigned int terminal_width;
unsigned int temp_heigth = 0; /*used for screen refresh*/
@@ -19,6 +21,7 @@ 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;
WINDOW *win_t;
WINDOW *win_b;
@@ -57,7 +60,17 @@ int main(){
char threading = 0;
terminal_width_empty_line = malloc(terminal_width);
#if SETTINGS_RELOAD_DIR_DELTA != 0
time_t t;
time_t dt;
time(&t);
#endif
pthread_create(&thread_t, NULL, thread_top, &status); /*top bar*/
pthread_create(&thread_l, NULL, thread_lft, &status); /*parent_content slash win_l*/
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*/
while(!(status & STATUS_QUIT_PROGRAM)){
getmaxyx(stdscr, terminal_height, terminal_width);
@@ -67,28 +80,14 @@ int main(){
temp_width = terminal_width;
temp_heigth = terminal_height;
}
if (status & STATUS_RUN_BACKEND && threading) {
pthread_cancel(thread_b);
pthread_cancel(thread_r);
pthread_cancel(thread_m);
pthread_cancel(thread_l);
pthread_cancel(thread_t);
}
if (threading) {
status &= ~(STATUS_RELOAD_DIRECTORY);
pthread_join(thread_t, NULL);
pthread_join(thread_l, NULL);
pthread_join(thread_m, NULL);
pthread_join(thread_b, NULL);
pthread_join(thread_r, NULL);
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
threading = 0;
}
if (status & STATUS_RUN_BACKEND) {
pthread_create(&thread_t, NULL, thread_top, &status); /*top bar*/
pthread_create(&thread_l, NULL, thread_lft, &status); /*parent_content slash win_l*/
pthread_create(&thread_m, NULL, thread_mid, &status); /*current_content slash win_m*/
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
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;
@@ -98,17 +97,30 @@ int main(){
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_DELTA_TIME);
}
#endif
}
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
ueberzug_close();
#endif
threading_free();
free(start_path);
if (threading) {
/*
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);
@@ -116,9 +128,9 @@ int main(){
delwin(win_t);
delwin(win_b);
noraw();
endwin();
curs_set(1);
echo();
curs_set(1);
endwin();
return 0;
}
@@ -188,10 +200,18 @@ void init() {
}
threading_init(); /* found in threading.c */
colors_init();
colors_init(); /* in colors.c */
dir_init(); /*in dir.c */
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
ueberzug_init(); /* in file_previews.c */
#endif
ESCDELAY = 10;
char *start_path = getcwd(NULL, 0);
setenv("START_PATH", start_path, 0);
free(start_path);
seed = malloc(sizeof(time_t));
*seed = time(NULL);
}

276
sorting.c
View File

@@ -1,20 +1,24 @@
#include <curses.h>
#include <dirent.h>
#include <strings.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include "defines.h"
extern unsigned int settings;
extern unsigned int file_modifiers;
extern time_t *seed;
int skip_hidden_files(const struct dirent *entry){
if (entry->d_name[0] == '.') {
return 0;
}
return 1;
}
int skip_dot(const struct dirent *entry){
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
return 0;
}
@@ -22,136 +26,178 @@ int skip_dot(const struct dirent *entry){
}
int sort_natural(const void *file0, const void *file1){
unsigned char file_type0 = ((file*)file0)->file_type;
unsigned char file_type1 = ((file*)file1)->file_type;
char weight = 0;
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
weight |= 1;
}
if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
weight |= 2;
}
if (weight == 0 || weight == 3) {
char *file_name0 = ((file*)file0)->file_name;
char *file_name1 = ((file*)file1)->file_name;
return strcasecmp(file_name0, file_name1);
} else {
if (file_type0 > file_type1) {
return 1;
} else if (file_type0 < file_type1) {
return -1;
} else {
char *file_name0 = ((file*)file0)->file_name;
char *file_name1 = ((file*)file1)->file_name;
return strcasecmp(file_name0, file_name1);
}
}
}
int sort_alpha(const void *file0, const void *file1){
char *file_name0 = ((file*)file0)->file_name;
char *file_name1 = ((file*)file1)->file_name;
return strcmp(file_name0, file_name1);
}
int sort_random(const void *file0, const void *file1){
unsigned char file_type0 = ((file*)file0)->file_type;
unsigned char file_type1 = ((file*)file1)->file_type;
static int seed = 0;
static int random = 0;
if (seed == 0) {
seed = rand();
}
if (random == 0) {
random = seed;
}
char weight = 0;
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
weight |= 1;
}
if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
weight |= 2;
}
if (weight == 0 || weight == 3) {
random = random > 1;
if ((random & 2) == 2) {
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
return -1;
} else {
if (random & 1){
return 1;
} else {
return 0;
}
}
} else {
if (file_type0 > file_type1) {
}
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
return 1;
} else if (file_type0 < file_type1) {
return -1;
} else {
random = random > 1;
if ((random & 2) == 2) {
return -1;
} else {
if (random & 1){
return 1;
}
const unsigned char *a = (unsigned char*)((file*)file0)->file_name;
const unsigned char *b = (unsigned char*)((file*)file1)->file_name;
long parsed_number0 = 0;
long parsed_number1 = 0;
char is_num = 0;
char result = 0;
do {
if ((*a <= '9') && (*a >= '0')) {
parsed_number0 = 0;
do {
parsed_number0 = (parsed_number0 * 10) + (*a - '0');
a++;
} while((*a <= '9') && (*a >= '0'));
is_num |= 1;
}
if ((*b <= '9') && (*b >= '0')) {
parsed_number1 = 0;
do {
parsed_number1 = (parsed_number1 * 10) + (*b - '0');
b++;
} while((*b <= '9') && (*b >= '0'));
is_num |= 2;
}
if (is_num) {
if (is_num == 1) {
if (*b > '9') {
result = -1;
} else {
return 0;
result = 1;
}
break;
} else if (is_num == 2) {
if (*a > '9') {
result = 1;
} else {
result = -1;
}
break;
} else {
if (parsed_number0 > parsed_number1) {
result = 1;
break;
} else if (parsed_number0 < parsed_number1) {
result = -1;
break;
}
}
/* those breaks are not set here, due to the possibillity that both numbers are equal
* in which case the comparison should continue */
is_num = 0;
}
unsigned char aa = ((*a >= 'A') && (*a <= 'Z')) ? (*a | ' ') : *a;
unsigned char bb = ((*b >= 'A') && (*b <= 'Z')) ? (*b | ' ') : *b;
/*using a simple aa - bb would occasionaly cause underflows with wide chars*/
result = ((aa == bb) ? 0 : ((aa > bb) ? 1 : -1 ));
a++;
b++;
} while (result == 0);
return result;
}
int sort_alpha(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;
}
return strcmp(((file*)file0)->file_name, ((file*)file1)->file_name);
}
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;
}
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
return 1;
}
time_t num = (time_t)&seed;
time_t i;
for (i = num%2; i < 6+(((time_t)&seed)%2); i++){
num ^= *seed;
if (num%2) {
num ^= (time_t)&num;
num ^= num << (i + (((time_t)&seed)%5));
} else {
num ^= (time_t)&seed;
num ^= num >> (i + (((time_t)&num)%5));
}
}
return 0;
num ^= getpid();
return ((num%3) - 1);
}
int sort_type(const void *file0, const void *file1){
unsigned char file_type0 = ((file*)file0)->file_type;
unsigned char file_type1 = ((file*)file1)->file_type;
char *file_name0 = ((file*)file0)->file_name;
char *file_name1 = ((file*)file1)->file_name;
if (file_type0 == file_type1) {
return strcasecmp(file_name0, file_name1);
} else if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
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;
}
if (((file*)file0)->file_type > ((file*)file1)->file_type) {
return -1;
} else if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
} else if (((file*)file0)->file_type < ((file*)file1)->file_type) {
return 1;
} else {
if (file_type0 > file_type1) {
return -1;
} else if (file_type0 < file_type1) {
return 1;
} else {
return strcasecmp(file_name0, file_name1);
}
return sort_natural(file0, file1);
}
}
int sort_size(const void *file0, const void *file1){
unsigned char file_type0 = ((file*)file0)->file_type;
unsigned char file_type1 = ((file*)file1)->file_type;
unsigned long file_size0 = ((file*)file0)->file_size;
unsigned long file_size1 = ((file*)file1)->file_size;
char *file_name0 = ((file*)file0)->file_name;
char *file_name1 = ((file*)file1)->file_name;
if (file_type0 == file_type1) {
if (file_size0 > file_size1) {
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
return -1;
} else if (file_size0 < file_size1) {
}
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
return 1;
} else {
return strcasecmp(file_name0, file_name1);
}
}
if (((file*)file0)->file_size > ((file*)file1)->file_size) {
return -1;
} else if (((file*)file0)->file_size < ((file*)file1)->file_size) {
return 1;
} else {
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
return -1;
} else if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
return 1;
} else {
if (file_size0 > file_size1) {
return -1;
} else if (file_size0 < file_size1) {
return 1;
} else {
return strcasecmp(file_name0, file_name1);
}
}
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);
}
}

View File

@@ -5,20 +5,27 @@
#include <string.h>
#include <unistd.h>
#include <time.h>
#include "defines.h"
#include "backend.h"
#include <sys/stat.h>
#include <sys/statvfs.h>
#include "config.h"
#include "dir.h"
#include "file_previews.h"
pthread_mutex_t mutex_top;
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_wait;
pthread_cond_t cond_wait;
volatile char wait_count; /* this is used to determine how many threads are waiting for cont_wait */
pthread_cond_t cond_mid;
pthread_cond_t cond_rgt;
pthread_cond_t cond_lft;
pthread_cond_t cond_top;
pthread_cond_t cond_btm;
file *rgt_content;
file *mid_content;
@@ -27,7 +34,6 @@ char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used f
char *btm_buffer;
char *top_buffer; /* current path */
volatile file *file_current;
unsigned long rgt_file_count = 0;
@@ -40,231 +46,320 @@ 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;
unsigned int btm_status;
void *thread_mid(void *data){
unsigned int status = *(unsigned int*)data;
pthread_mutex_lock(&mutex_mid);
void *thread_mid(){
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_mid);
pthread_cond_wait(&cond_mid, &mutex_mid);
unsigned int local_status = status;
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 (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->status = FILE_STATUS_DIR_EMPTY;
mid_content->file_type = 0;
mid_content->file_size = 0;
mid_content->permissions = 0;
mid_content->color_pair = 0;
mid_content->file_name = "empty dir";
file_current->file_name = mid_content->file_name;
file_current->file_size = mid_content->file_size;
file_current->file_type = mid_content->file_type;
file_current->color_pair = mid_content->color_pair;
file_current->permissions = mid_content->permissions;
file_current->status = mid_content->status;
mid_file_count = 0;
while(wait_count < 2){
/*wait for thread_rgt and thread_btm to lock*/
}
pthread_mutex_lock(&mutex_wait);
pthread_cond_broadcast(&cond_wait);
pthread_mutex_unlock(&mutex_wait);
free(path);
pthread_mutex_unlock(&mutex_mid);
pthread_exit(0);
}
}
pthread_mutex_lock(&mutex_selection);
if (selected_file_current >= mid_file_count) {
selected_file_current = mid_file_count-1;
selected_file_current = mid_file_count-1;
}
if (selected_file_current != selected_file_last) {
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
}
selected_file_last = selected_file_current;
free(file_current->file_name);
file_current->file_name = malloc(strlen(mid_content[selected_file_current].file_name)+1);
strcpy(file_current->file_name, mid_content[selected_file_current].file_name);
file_current->file_name[strlen(mid_content[selected_file_current].file_name)] = '\0';
file_current->file_size = mid_content[selected_file_current].file_size;
file_current->file_type = mid_content[selected_file_current].file_type;
file_current->color_pair = mid_content[selected_file_current].color_pair;
file_current->permissions = mid_content[selected_file_current].permissions;
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
file_current->status = mid_content[selected_file_current].status;
pthread_mutex_unlock(&mutex_selection);
while(wait_count < 2){
/*wait for thread_rgt and thread_btm to lock*/
}
pthread_mutex_lock(&mutex_wait);
pthread_cond_broadcast(&cond_wait);
pthread_mutex_unlock(&mutex_wait);
}
free(path);
pthread_mutex_unlock(&mutex_mid);
pthread_exit(0);
}
void *thread_lft(void *data){
unsigned int status = *(unsigned int*)data;
pthread_mutex_lock(&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 {
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);
}
}
free(path);
pthread_mutex_unlock(&mutex_lft);
pthread_exit(0);
}
void *thread_rgt(void *data){
unsigned int status = *(unsigned int*)data;
pthread_mutex_lock(&mutex_rgt);
pthread_mutex_lock(&mutex_wait);
wait_count++;
pthread_cond_wait(&cond_wait, &mutex_wait);
wait_count--;
pthread_mutex_unlock(&mutex_wait);
pthread_mutex_lock(&mutex_selection);
char *path = malloc(strlen(file_current->file_name) + 1);
strcpy(path, file_current->file_name);
unsigned char file_current_type = file_current->file_type;
unsigned long file_current_size = file_current->file_size;
char file_current_status = file_current->status;
pthread_mutex_unlock(&mutex_selection);
if (file_current_type == FILE_TYPE_DIR || file_current_type == FILE_TYPE_SYMLINK) {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
free(rgt_content[i].file_name);
}
free(rgt_content);
rgt_file_count = get_dir_size(path);
rgt_content = malloc(rgt_file_count * sizeof(file));
memset(rgt_content, '\0', rgt_file_count * sizeof(file));
get_dir_content(path, &rgt_file_count, rgt_content);
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
free(rgt_buffer);
rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0';
} else {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
free(rgt_content[i].file_name);
}
free(rgt_content);
rgt_file_count = 0;
rgt_content = malloc(sizeof(file));
free(rgt_buffer);
if (file_current_status & FILE_STATUS_DIR_EMPTY) {
rgt_buffer = "empty dir";
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 {
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
rgt_content->status = FILE_STATUS_HOVER;
rgt_buffer = preview_file(path, file_current_size);
if (local_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';
mid_file_count = 0;
}
pthread_mutex_lock(&mutex_selection);
update_selected_file();
pthread_mutex_unlock(&mutex_selection);
}
btm_status = local_status;
pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_btm);
}
free(path);
pthread_mutex_unlock(&mutex_mid);
}
free(path);
pthread_mutex_unlock(&mutex_rgt);
pthread_exit(0);
}
void *thread_top(void *data){
unsigned int status = *(unsigned int*)data;
pthread_mutex_lock(&mutex_top);
free(top_buffer);
void *thread_lft(){
char *path;
if((path=getcwd(NULL, 0)) == 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);
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_lft);
pthread_cond_wait(&cond_lft, &mutex_lft);
unsigned int local_status = status;
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 {
path[strrchr(path, '/')-path] = '\0';
path[0] = '/';
if (local_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);
}
}
free(path);
pthread_mutex_unlock(&mutex_lft);
}
pthread_exit(0);
free(path);
pthread_mutex_unlock(&mutex_top);
}
void *thread_rgt(){
file file_current;
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;
pthread_mutex_unlock(&mutex_mid);
if (mid_content[selected_file_current].permissions & S_IRUSR) {
if (file_current.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);
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;
free(rgt_buffer);
rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0';
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) {
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_content->file_type = FILE_TYPE_OPEN_FILE;
rgt_content->status = FILE_STATUS_HOVER;
rgt_buffer = preview_file(path, file_current.file_size);
}
} else {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
if (rgt_content[i].file_name) {
free(rgt_content[i].file_name);
}
}
free(rgt_content);
rgt_file_count = 0;
rgt_content = malloc(sizeof(file));
free(rgt_buffer);
rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0';
}
free(path);
pthread_mutex_unlock(&mutex_rgt);
}
pthread_exit(0);
}
void *thread_btm(void *data){
unsigned int status = *(unsigned int*)data;
pthread_mutex_lock(&mutex_btm);
pthread_mutex_lock(&mutex_wait);
wait_count++;
pthread_cond_wait(&cond_wait, &mutex_wait);
wait_count--;
pthread_mutex_unlock(&mutex_wait);
void *thread_top(){
free(btm_buffer);
int buffer_width = terminal_width;
btm_buffer = malloc(buffer_width);
memset(btm_buffer, 0, buffer_width);
btm_buffer[0] = (S_ISDIR(file_current->permissions)) ? 'd' : '-';
btm_buffer[1] = (file_current->permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[2] = (file_current->permissions & S_IWUSR) ? 'w' : '-';
btm_buffer[3] = (file_current->permissions & S_IXUSR) ? 'x' : '-';
btm_buffer[4] = (file_current->permissions & S_IRGRP) ? 'r' : '-';
btm_buffer[5] = (file_current->permissions & S_IWGRP) ? 'w' : '-';
btm_buffer[6] = (file_current->permissions & S_IXGRP) ? 'x' : '-';
btm_buffer[7] = (file_current->permissions & S_IROTH) ? 'r' : '-';
btm_buffer[8] = (file_current->permissions & S_IWOTH) ? 'w' : '-';
btm_buffer[9] = (file_current->permissions & S_IXOTH) ? 'x' : '-';
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_top);
pthread_cond_wait(&cond_top, &mutex_top);
free(top_buffer);
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
top_buffer = malloc(sizeof("cannot open directory"));
top_width = sizeof("cannot open directory");
top_buffer = "cannot open directory";
} else {
top_buffer = malloc(strlen(path)+1);
memcpy(top_buffer, path, strlen(path)+1);
top_width = strlen(top_buffer);
}
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);
unsigned int local_status = btm_status;
pthread_mutex_unlock(&mutex_btm);
if (local_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_file_count; i++) {
if ((mid_content[i].file_type & (FILE_TYPE_DIR)) != FILE_TYPE_DIR) {
total_dir_size += mid_content[i].file_size;
}
}
pthread_mutex_unlock(&mutex_mid);
if (path != NULL) {
/* sometimes NULL remains, need to do deeper analysis soon */
free(path);
path = NULL;
} else {
volatile static int debug_thread_btm;
debug_thread_btm++;
}
free(ui_btm_right_block);
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);
memset(btm_buffer, ' ', buffer_width/2);
}
memset(btm_buffer + (buffer_width/2), ' ', buffer_width/2);
btm_buffer[buffer_width] = '\0';
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-';
btm_buffer[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' : '-';
pthread_mutex_unlock(&mutex_btm);
}
pthread_exit(0);
}
@@ -290,11 +385,6 @@ void threading_init(){
rgt_content->file_name = malloc(sizeof(char));
rgt_content->file_name[0] = '\0';
file_current = malloc(sizeof(file));
file_current->file_type = 0;
file_current->file_size = 0;
file_current->file_name = malloc(sizeof(char));
file_current->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);
@@ -303,8 +393,11 @@ void threading_init(){
vol = pthread_mutex_init(&mutex_btm, NULL);
vol = pthread_mutex_init(&mutex_rgt, NULL);
vol = pthread_mutex_init(&mutex_selection, NULL);
vol = pthread_mutex_init(&mutex_wait, NULL);
vol = pthread_cond_init(&cond_wait, 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;

View File

@@ -1,10 +1,14 @@
#include <curses.h>
#include "threading.c"
void *thread_lft(void *data);
void *thread_mid(void *data);
void *thread_rgt(void *data);
void *thread_top(void *data);
void *thread_btm(void *data);
#ifndef THREADING_GUARD
#define THREADING_GUARD
#include "threading.c"
#endif
void *thread_lft();
void *thread_mid();
void *thread_rgt();
void *thread_top();
void *thread_btm();
void threading_init();
void threading_free();

View File

@@ -1,8 +1,12 @@
#include <curses.h>
#include <pthread.h>
#include <unistd.h>
#include "defines.h"
#include "defines.h"
#include "dir.h"
extern unsigned int terminal_height;
extern unsigned int terminal_width;
extern unsigned int status;
extern char *input;
@@ -40,15 +44,13 @@ void window_top(WINDOW *win){
wattroff(win, COLOR_PAIR(COLOR_PATH));
pthread_mutex_unlock(&mutex_top);
} else {
wprintw(win,"loading");
mvwaddstr(win, 0, terminal_width/2, "LOADING");
status |= STATUS_UPDATE_SCREEN_0;
}
}
void window_btm(WINDOW *win){
werase(win);
unsigned long local_width;
unsigned long local_height;
getmaxyx(win, local_height, local_width);
if (pthread_mutex_trylock(&mutex_btm) == 0) {
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
mvwprintw(win, 0, 0, "%s", btm_buffer);
@@ -57,58 +59,48 @@ void window_btm(WINDOW *win){
/*the printing of the input char is done in user_interactions*/
/*the printing of all possible inputs are done in user_interactions */
} else {
mvwprintw(win, local_height/2, local_width/2, "LOADING");
mvwaddstr(win, 0, terminal_width/2, "LOADING");
status |= STATUS_UPDATE_SCREEN_0;
}
}
void window_lft(WINDOW *win){
werase(win);
box(win, 0, 0);
unsigned long local_width;
unsigned long local_height;
getmaxyx(win, local_height, local_width);
if (pthread_mutex_trylock(&mutex_lft) == 0) {
print_dir(win, 0, &lft_file_count, lft_content);
pthread_mutex_unlock(&mutex_lft);
} else {
mvwprintw(win, local_height/2, local_width/2, "LOADING");
mvwaddstr(win, terminal_height/2, terminal_width/8, "LOADING");
status |= STATUS_UPDATE_SCREEN_0;
}
}
void window_mid(WINDOW *win){
werase(win);
box(win, 0, 0);
unsigned long local_width;
unsigned long local_height;
getmaxyx(win, local_height, local_width);
if (pthread_mutex_trylock(&mutex_mid) == 0) {
if (mid_file_count == 0) {
mvwprintw(win, 0, 0, "empty");
mvwaddstr(win, 0, 0, "empty");
} else {
print_dir(win, 1, &mid_file_count, mid_content);
}
pthread_mutex_unlock(&mutex_mid);
} else {
mvwprintw(win, local_height/2, local_width/2, "LOADING");
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_0;
}
}
void window_rgt(WINDOW *win){
werase(win);
box(win, 0, 0);
unsigned long local_width;
unsigned long local_height;
getmaxyx(win, local_height, local_width);
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
if (rgt_file_count == 0) {
if (rgt_content[0].file_type == FILE_TYPE_OPEN_FILE) {
mvwprintw(win, 0, 0, "%s", rgt_buffer);
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 {
mvwprintw(win, 0, 0, "empty");
mvwaddstr(win, 0, 0, "empty");
}
@@ -117,7 +109,7 @@ void window_rgt(WINDOW *win){
}
pthread_mutex_unlock(&mutex_rgt);
} else {
mvwprintw(win, local_height/2, local_width/2, "LOADING");
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
status |= STATUS_UPDATE_SCREEN_0;
}
}