mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
Compare commits
36 Commits
5afabfb412
...
main
Author | SHA1 | Date | |
---|---|---|---|
![]() |
df726e2f32 | ||
![]() |
140457e4b7 | ||
![]() |
23654741bc | ||
![]() |
fa544204ba | ||
![]() |
61023ce42e | ||
![]() |
3fa16fd8b2 | ||
![]() |
ac6d0e8408 | ||
![]() |
731bfe722a | ||
![]() |
3082fed378 | ||
![]() |
23ff0b07ec | ||
![]() |
c2d88f4909 | ||
![]() |
0b98e8eb68 | ||
![]() |
87ae2a5e8f | ||
![]() |
f0ad6295f7 | ||
![]() |
e979209de3 | ||
![]() |
8fade0c4a8 | ||
![]() |
333d4d1df6 | ||
![]() |
c6763233bf | ||
![]() |
7ee16c8f4a | ||
![]() |
b32848ad3d | ||
![]() |
4d9dc46691 | ||
![]() |
8dcf88baea | ||
![]() |
8839f737c5 | ||
![]() |
36012b1a71 | ||
![]() |
4784ec3f64 | ||
![]() |
d3e46846cd | ||
![]() |
21a11d8be1 | ||
![]() |
b46d2da308 | ||
![]() |
fe781c2d3c | ||
![]() |
fb1af6d2d2 | ||
![]() |
14948ba573 | ||
![]() |
e0a5871bc2 | ||
![]() |
395c5fcb09 | ||
![]() |
525f205d67 | ||
![]() |
c923497f01 | ||
![]() |
69f9a609e5 |
4
Makefile
4
Makefile
@@ -3,6 +3,7 @@ CFLAGS := -Wall -Wextra -O2 -flto=auto
|
|||||||
CURSES := -lncursesw -ltinfow #utf8 support
|
CURSES := -lncursesw -ltinfow #utf8 support
|
||||||
#CURSES := -lncurses -tinfo #no utf8
|
#CURSES := -lncurses -tinfo #no utf8
|
||||||
CFLAGS_DEBUG := $(CFLAGS) -g
|
CFLAGS_DEBUG := $(CFLAGS) -g
|
||||||
|
CFLAGS_PROFILE := $(CFLAGS) -pg
|
||||||
GDB := gdb --tui ./th
|
GDB := gdb --tui ./th
|
||||||
VALGRIND := valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --log-fd=9 9>>valgrind.log ./th
|
VALGRIND := valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --log-fd=9 9>>valgrind.log ./th
|
||||||
HELGRIND := valgrind --tool=helgrind --log-fd=9 9>>helgrind.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)
|
$(CC) ./main.c -o th -std=c89 $(CFLAGS_DEBUG) $(CURSES)
|
||||||
$(GDB)
|
$(GDB)
|
||||||
|
|
||||||
|
p:
|
||||||
|
$(CC) ./main.c -o th -std=c89 $(CFLAGS_PROFILE) $(CURSES)
|
||||||
|
|
||||||
v:
|
v:
|
||||||
$(CC) ./main.c -o th -std=c89 $(CFLAGS_DEBUG) $(CURSES)
|
$(CC) ./main.c -o th -std=c89 $(CFLAGS_DEBUG) $(CURSES)
|
||||||
$(VALGRIND)
|
$(VALGRIND)
|
||||||
|
36
config.h
36
config.h
@@ -1,10 +1,14 @@
|
|||||||
|
#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
|
#ifndef CONFIG_GUARD
|
||||||
#define CONFIG_GUARD
|
#define CONFIG_GUARD
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "sorting.h"
|
#include "sorting.h"
|
||||||
#include "interactions.h"
|
#include "interactions.h"
|
||||||
|
/* }}} */
|
||||||
#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */
|
|
||||||
|
|
||||||
static const mimetype mimetype_default_cmd[] = {
|
static const mimetype mimetype_default_cmd[] = {
|
||||||
/* mimetype shell command
|
/* mimetype shell command
|
||||||
@@ -40,9 +44,11 @@ static const binding key_binding[] = {
|
|||||||
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
|
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
|
||||||
{ "q", quit_program, NULL, "quit" },
|
{ "q", quit_program, NULL, "quit" },
|
||||||
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
{ " ", 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 */
|
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||||
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" },
|
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" },
|
||||||
{ "/", search, NULL, "search" },
|
{ "/", search, NULL, "search" },
|
||||||
|
{ ":", jmp_file_index, NULL, "jump to file on input number" },
|
||||||
{ "l", search_next, NULL, "search next" },
|
{ "l", search_next, NULL, "search next" },
|
||||||
{ "L", search_previous, NULL, "search previous" },
|
{ "L", search_previous, NULL, "search previous" },
|
||||||
|
|
||||||
@@ -55,6 +61,8 @@ static const binding key_binding[] = {
|
|||||||
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||||
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
||||||
* this means that it does not delete the hovered files if files are already selected */
|
* this means that it does not delete the hovered files if files are already selected */
|
||||||
|
{ "yn", yank_text, "name", "yank filename of hovered file" },
|
||||||
|
{ "yp", yank_text, "path", "yank path of hovered file" },
|
||||||
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
||||||
{ "dd", yank_file, "cut", "cut file/directory" },
|
{ "dd", yank_file, "cut", "cut file/directory" },
|
||||||
{ "pp", paste, NULL, "paste" },
|
{ "pp", paste, NULL, "paste" },
|
||||||
@@ -62,8 +70,11 @@ static const binding key_binding[] = {
|
|||||||
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
||||||
{ "gg", jump_top, NULL, "jump to first file in dir" },
|
{ "gg", jump_top, NULL, "jump to first file in dir" },
|
||||||
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
||||||
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
|
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" }, /* the path you started th in */
|
||||||
{ "gD", jump_to_dir, "$HOME/Downloads", "jump to $HOME/Downloads" },
|
{ "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" },
|
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
||||||
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
||||||
{ "gp", jump_to_dir, "/etc/portage", "jump to /etc/portage" },
|
{ "gp", jump_to_dir, "/etc/portage", "jump to /etc/portage" },
|
||||||
@@ -80,11 +91,10 @@ static const binding key_binding[] = {
|
|||||||
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
|
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
|
||||||
|
|
||||||
{ "on", order_by, sort_natural, "order natural" },
|
{ "on", order_by, sort_natural, "order natural" },
|
||||||
{ "or", not_implemented, "", "order reverse" },
|
{ "oe", order_by, sort_extension, "order extension" },
|
||||||
{ "oe", not_implemented, "", "order extension" },
|
|
||||||
{ "os", order_by, sort_size, "order size" },
|
{ "os", order_by, sort_size, "order size" },
|
||||||
{ "ot", order_by, sort_type, "order type" },
|
{ "ot", order_by, sort_type, "order type" },
|
||||||
{ "oz", order_by, sort_random, "order random" },
|
{ "or", order_by, sort_random, "order random" },
|
||||||
{ "oa", order_by, sort_alpha, "order alphabetically" },
|
{ "oa", order_by, sort_alpha, "order alphabetically" },
|
||||||
|
|
||||||
{ "mk", makedir, NULL, "create directory" },
|
{ "mk", makedir, NULL, "create directory" },
|
||||||
@@ -93,15 +103,27 @@ static const binding key_binding[] = {
|
|||||||
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
|
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
|
||||||
{ "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace key */
|
{ "\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 binding_count = sizeof(key_binding) / sizeof(binding);
|
||||||
static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
|
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 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
|
#else
|
||||||
|
static const char clipboard_cmd[];
|
||||||
static const mimetype mimetype_default_cmd[];
|
static const mimetype mimetype_default_cmd[];
|
||||||
static const extension file_extension_default_cmd[];
|
static const extension file_extension_default_cmd[];
|
||||||
static const binding key_binding[];
|
static const binding key_binding[];
|
||||||
static const unsigned long binding_count;
|
static const unsigned long binding_count;
|
||||||
static const unsigned long mimetype_default_count;
|
static const unsigned long mimetype_default_count;
|
||||||
static const unsigned long file_extension_default_count;
|
static const unsigned long file_extension_default_count;
|
||||||
|
static const char size_unit[];
|
||||||
|
static const char size_unit_count;
|
||||||
#endif
|
#endif
|
||||||
|
/* }}} */
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
||||||
#define STATUS_USER_ROOT 64
|
#define STATUS_USER_ROOT 64
|
||||||
#define STATUS_INPUT_MATCH 128
|
#define STATUS_INPUT_MATCH 128
|
||||||
|
#define STATUS_DELTA_TIME 256
|
||||||
|
|
||||||
#define SETTINGS_HAS_COLOR 1
|
#define SETTINGS_HAS_COLOR 1
|
||||||
|
|
||||||
|
216
dir.c
216
dir.c
@@ -5,12 +5,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "sorting.h"
|
#include "sorting.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern file *mid_content;
|
||||||
|
extern unsigned long mid_file_count;
|
||||||
extern unsigned int settings;
|
extern unsigned int settings;
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
@@ -31,25 +34,27 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
unsigned long get_dir_size(char *path){
|
unsigned long get_dir_size(char *path){
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
unsigned long entry_count = 0;
|
unsigned long entry_count = 0;
|
||||||
if (dir) {
|
struct dirent *entry;
|
||||||
struct dirent *entry;
|
if (dir && file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||||
while ((entry=readdir(dir))) {
|
while ((entry=readdir(dir))) {
|
||||||
if (entry->d_name[0] != '.' || (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
entry_count++;
|
||||||
|
}
|
||||||
|
/* removes files "." and ".." */
|
||||||
|
entry_count -= 2;
|
||||||
|
} else if (dir) {
|
||||||
|
while ((entry=readdir(dir))) {
|
||||||
|
if (entry->d_name[0] != '.') {
|
||||||
entry_count++;
|
entry_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
|
||||||
/* removes files "." and ".." */
|
|
||||||
entry_count -= 2;
|
|
||||||
}
|
}
|
||||||
|
closedir(dir);
|
||||||
return entry_count;
|
return entry_count;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
|
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
|
||||||
struct dirent **entry;
|
struct dirent **entry = NULL;
|
||||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
||||||
scandir(path, &entry, skip_dot, NULL);
|
scandir(path, &entry, skip_dot, NULL);
|
||||||
} else {
|
} else {
|
||||||
@@ -62,24 +67,20 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
} else {
|
} else {
|
||||||
dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1);
|
dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1);
|
||||||
strcpy(dir_content[i].file_name, entry[i]->d_name);
|
strcpy(dir_content[i].file_name, entry[i]->d_name);
|
||||||
dir_content[i].file_name[strlen(entry[i]->d_name)] = '\0';
|
|
||||||
|
|
||||||
|
|
||||||
struct stat *file;
|
struct stat *file;
|
||||||
file = malloc(sizeof(struct stat));
|
file = malloc(sizeof(struct stat));
|
||||||
memset(file, ' ', sizeof(struct stat));
|
|
||||||
|
|
||||||
/* using the full path allows using the same function for all windows */
|
/* using the full path allows using the same function for all windows */
|
||||||
unsigned long path_len = strlen(path);
|
|
||||||
char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/"));
|
char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/"));
|
||||||
memcpy(full_path, path, strlen(path));
|
memcpy(full_path, path, strlen(path));
|
||||||
memcpy(full_path + path_len, "/", sizeof("/"));
|
memcpy(full_path + strlen(path) + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
||||||
memcpy(full_path + path_len + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
full_path[strlen(path)] = '/';
|
||||||
|
|
||||||
lstat(full_path, file);
|
lstat(full_path, file);
|
||||||
|
|
||||||
dir_content[i].file_size = file->st_size;
|
dir_content[i].file_size = file->st_size;
|
||||||
dir_content[i].permissions = 1;
|
|
||||||
dir_content[i].permissions = file->st_mode;
|
dir_content[i].permissions = file->st_mode;
|
||||||
|
|
||||||
if (S_ISDIR(file->st_mode)) {
|
if (S_ISDIR(file->st_mode)) {
|
||||||
@@ -87,12 +88,30 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
dir_content[i].color_pair = COLOR_DIR;
|
dir_content[i].color_pair = COLOR_DIR;
|
||||||
dir_content[i].file_size = get_dir_size(full_path);
|
dir_content[i].file_size = get_dir_size(full_path);
|
||||||
} else if (S_ISLNK(file->st_mode)) {
|
} else if (S_ISLNK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_SYMLINK;
|
stat(full_path, file);
|
||||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
if (S_ISDIR(file->st_mode)) {
|
||||||
dir_content[i].file_size = get_dir_size(full_path);
|
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) {
|
} else if (file->st_mode & S_IXUSR) {
|
||||||
dir_content[i].file_type = FILE_TYPE_EXEC;
|
dir_content[i].file_type = FILE_TYPE_EXEC;
|
||||||
dir_content[i].color_pair = COLOR_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)) {
|
} else if (S_ISBLK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_BLOCK;
|
dir_content[i].file_type = FILE_TYPE_BLOCK;
|
||||||
dir_content[i].color_pair = COLOR_BLOCK;
|
dir_content[i].color_pair = COLOR_BLOCK;
|
||||||
@@ -104,19 +123,6 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
} else if (S_ISSOCK(file->st_mode)) {
|
} else if (S_ISSOCK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_SOCK;
|
dir_content[i].file_type = FILE_TYPE_SOCK;
|
||||||
dir_content[i].color_pair = COLOR_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 {
|
} else {
|
||||||
dir_content[i].file_type = COLOR_REGULAR;
|
dir_content[i].file_type = COLOR_REGULAR;
|
||||||
dir_content[i].color_pair = COLOR_REGULAR;
|
dir_content[i].color_pair = COLOR_REGULAR;
|
||||||
@@ -124,7 +130,7 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
char *extension = strrchr(entry[i]->d_name, '.');
|
char *extension = strrchr(entry[i]->d_name, '.');
|
||||||
if (extension) {
|
if (extension) {
|
||||||
for (j = 0; j < color_count; j++) {
|
for (j = 0; j < color_count; j++) {
|
||||||
if (!strcmp(colors[j].file_extension, extension)) {
|
if (!strncmp(colors[j].file_extension, extension, strlen(colors[j].file_extension))) {
|
||||||
dir_content[i].color_pair = colors[j].color_pair;
|
dir_content[i].color_pair = colors[j].color_pair;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,7 +147,10 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
for (i = 0; i < *dir_file_count; i++) {
|
for (i = 0; i < *dir_file_count; i++) {
|
||||||
free(entry[i]);
|
free(entry[i]);
|
||||||
}
|
}
|
||||||
free(entry);
|
if (entry != NULL) {
|
||||||
|
free(entry);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,17 +167,16 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
float printed_size = 0;
|
float printed_size = 0;
|
||||||
char size_char = ' ';
|
char size_char = ' ';
|
||||||
char is_selected = 0;
|
char is_selected = 0;
|
||||||
static const char sizes[6] = { 'B', 'K', 'M', 'G', 'T', 'P' };
|
|
||||||
|
|
||||||
unsigned long offset_vertical = 0;
|
unsigned long offset_vertical = 0;
|
||||||
unsigned long offset_back = 0;
|
unsigned long offset_back = 0;
|
||||||
#if SETTINGS_LINE_NUMBERS == 0
|
#if SETTINGS_LINE_NUMBERS == 0
|
||||||
unsigned long offset_front = 0;
|
unsigned long offset_front = 0;
|
||||||
#else
|
#else
|
||||||
unsigned long offset_front = 2;
|
long offset_front = 2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned long offset_index = 2; /* only used for the index of the file itself */
|
long offset_index = 2; /* only used for the index of the file itself */
|
||||||
if (print_info) {
|
if (print_info) {
|
||||||
if (*dir_file_count > 9) {
|
if (*dir_file_count > 9) {
|
||||||
|
|
||||||
@@ -187,64 +195,33 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
offset_vertical = selected_file_current - (terminal_height/3)*2;
|
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++) {
|
for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) {
|
||||||
|
|
||||||
/* 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';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (print_info) {
|
if (print_info) {
|
||||||
file_size = dir_content[i].file_size;
|
file_size = dir_content[i].file_size;
|
||||||
char size_index = 0;
|
char size_index = -1;
|
||||||
while (file_size > 1) {
|
|
||||||
|
do {
|
||||||
printed_size=file_size;
|
printed_size=file_size;
|
||||||
file_size /= 1024;
|
file_size /= 1024;
|
||||||
size_index++;
|
size_index++;
|
||||||
if (size_index >= 6) {
|
} while (file_size > 1 && size_index < size_unit_count);
|
||||||
break;
|
size_char = size_unit[(unsigned)size_index];
|
||||||
}
|
|
||||||
}
|
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
||||||
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);
|
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1);
|
||||||
} else if (size_char =='B') {
|
} else if (size_char =='B') {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
||||||
} else {
|
} else {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
|
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) {
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
@@ -263,11 +240,42 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
wattroff(win, A_REVERSE);
|
wattroff(win, A_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* shortens the printed file name if it is too long
|
||||||
|
* example input: aaaaaaaa.txt
|
||||||
|
* example output: aaa~.txt
|
||||||
|
* if no extension is found, the name will truncate */
|
||||||
|
char *file_name = NULL;
|
||||||
|
unsigned long printable_size = (offset_back - is_selected - offset_front);
|
||||||
|
if (strlen(dir_content[i].file_name) > printable_size) {
|
||||||
|
char *extension = strrchr(dir_content[i].file_name, '.');
|
||||||
|
if (extension && extension != dir_content[i].file_name) {
|
||||||
|
file_name = malloc(printable_size);
|
||||||
|
printable_size -= strlen(extension);
|
||||||
|
|
||||||
|
memcpy(file_name, dir_content[i].file_name, printable_size);
|
||||||
|
memcpy(file_name + printable_size-1, extension, strlen(extension));
|
||||||
|
file_name[printable_size + strlen(extension)-1] = '\0';
|
||||||
|
file_name[printable_size - 2] = '~';
|
||||||
|
} else {
|
||||||
|
file_name = malloc(printable_size-1);
|
||||||
|
memcpy(file_name, dir_content[i].file_name, printable_size);
|
||||||
|
file_name[printable_size-2] = '~';
|
||||||
|
file_name[printable_size-1] = '\0';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
file_name = malloc(strlen(dir_content[i].file_name)+1);
|
||||||
|
memcpy(file_name, dir_content[i].file_name, strlen(dir_content[i].file_name)+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mvwaddstr(win, i-offset_vertical, 0, bg);
|
mvwaddstr(win, i-offset_vertical, 0, bg);
|
||||||
if(print_info) {
|
if(print_info) {
|
||||||
#if SETTINGS_LINE_NUMBERS == 2
|
#if SETTINGS_LINE_NUMBERS == 2
|
||||||
long i_ = (selected_file_current) - i;
|
long i_ = (selected_file_current) - i;
|
||||||
offset_index = !((selected_file_current) - i);
|
offset_index = 0;
|
||||||
while(i_) {
|
while(i_) {
|
||||||
offset_index++;
|
offset_index++;
|
||||||
i_ /= 10;
|
i_ /= 10;
|
||||||
@@ -275,6 +283,13 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
long relative_index = selected_file_current - i;
|
long relative_index = selected_file_current - i;
|
||||||
if (relative_index < 0) {
|
if (relative_index < 0) {
|
||||||
relative_index = relative_index * -1;
|
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);
|
mvwprintw(win, i-offset_vertical, offset_front-offset_index-1, "%ld", relative_index);
|
||||||
|
|
||||||
@@ -289,9 +304,8 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
|
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) {
|
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
||||||
}else if (size_char =='B') {
|
}else if (size_char =='B') {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
||||||
@@ -300,9 +314,15 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
|
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
|
||||||
free(file_name);
|
|
||||||
}
|
}
|
||||||
|
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) {
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
wattroff(win, COLOR_PAIR(8));
|
wattroff(win, COLOR_PAIR(8));
|
||||||
} else {
|
} else {
|
||||||
@@ -370,3 +390,33 @@ void dir_init(){
|
|||||||
current_dir = visited_dirs;
|
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, ¤t_file_count, current_dir);
|
||||||
|
if (chdir(current_file.file_name) != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < current_file_count; i++) {
|
||||||
|
recursive_delete(current_dir[i]);
|
||||||
|
free(current_dir[i].file_name);
|
||||||
|
}
|
||||||
|
free(current_dir);
|
||||||
|
if (chdir("..") != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
remove(current_file.file_name);
|
||||||
|
file_modifiers = file_modifiers_tmp;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
remove(current_file.file_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
dir.h
1
dir.h
@@ -10,3 +10,4 @@ char update_selected_file();
|
|||||||
void dir_set_selected_file_current(unsigned long selected_file_current);
|
void dir_set_selected_file_current(unsigned long selected_file_current);
|
||||||
unsigned long dir_get_selected_file_current();
|
unsigned long dir_get_selected_file_current();
|
||||||
void dir_init();
|
void dir_init();
|
||||||
|
void recursive_delete(file current_file);
|
||||||
|
@@ -1,9 +1,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "backend.h"
|
|
||||||
|
|
||||||
|
#include "backend.h"
|
||||||
|
#include "defines.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
static FILE *ueberzug = NULL;
|
static FILE *ueberzug = NULL;
|
||||||
|
#endif
|
||||||
extern unsigned int terminal_height;
|
extern unsigned int terminal_height;
|
||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
char previewd;
|
char previewd;
|
||||||
@@ -43,14 +48,19 @@ char* preview_file(char *file_name, unsigned long file_size){
|
|||||||
|
|
||||||
|
|
||||||
char *mime = get_mimetype(file_name);
|
char *mime = get_mimetype(file_name);
|
||||||
|
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (strstr(mime, "text")) {
|
if (strstr(mime, "text")) {
|
||||||
file_buffer = text(file_name, &file_size);
|
file_buffer = text(file_name, &file_size);
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
} else if (strstr(mime, "image")) {
|
} else if (strstr(mime, "image")) {
|
||||||
file_buffer = generic(file_name);
|
file_buffer = generic(file_name);
|
||||||
images_print(file_name);
|
images_print(file_name);
|
||||||
previewd = 1;
|
previewd = 1;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
file_buffer = generic(file_name);
|
file_buffer = generic(file_name);
|
||||||
}
|
}
|
||||||
@@ -74,28 +84,6 @@ char* text(char *path, unsigned long *file_size){
|
|||||||
return "failed reading file";
|
return "failed reading file";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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\": \"remove\", \
|
|
||||||
\"identifier\": \"preview\"}\n");
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
char* generic(char *path){
|
char* generic(char *path){
|
||||||
char *cmd = concat("file ./\"", path);
|
char *cmd = concat("file ./\"", path);
|
||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, "\"");
|
||||||
@@ -111,6 +99,38 @@ char* generic(char *path){
|
|||||||
return "failed executing shell command \"file\"";
|
return "failed executing shell command \"file\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ueberzug_init(){
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
ueberzug = popen("ueberzug layer -s ", "w");
|
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
|
||||||
|
@@ -1,9 +1,13 @@
|
|||||||
#ifndef PREVIEW_GUARD
|
#ifndef PREVIEW_GUARD
|
||||||
#define PREVIEW_GUARD
|
#define PREVIEW_GUARD
|
||||||
#include "file_previews.c"
|
#include "file_previews.c"
|
||||||
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char* preview_file(char *file_name, unsigned long file_size);
|
char* preview_file(char *file_name, unsigned long file_size);
|
||||||
char* get_mimetype(char *path);
|
char* get_mimetype(char *path);
|
||||||
void images_clear();
|
void images_clear();
|
||||||
void ueberzug_init();
|
void ueberzug_init();
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
|
void ueberzug_close();
|
||||||
|
#endif
|
||||||
|
257
interactions.c
257
interactions.c
@@ -1,7 +1,9 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "file_previews.h"
|
#include "file_previews.h"
|
||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
@@ -17,6 +19,7 @@ extern unsigned int file_modifiers;
|
|||||||
extern pthread_mutex_t mutex_selection;
|
extern pthread_mutex_t mutex_selection;
|
||||||
extern pthread_mutex_t mutex_rgt;
|
extern pthread_mutex_t mutex_rgt;
|
||||||
extern pthread_mutex_t mutex_mid;
|
extern pthread_mutex_t mutex_mid;
|
||||||
|
extern pthread_mutex_t mutex_btm;
|
||||||
extern pthread_cond_t cond_rgt;
|
extern pthread_cond_t cond_rgt;
|
||||||
extern file *mid_content;
|
extern file *mid_content;
|
||||||
extern file *lft_content;
|
extern file *lft_content;
|
||||||
@@ -35,14 +38,15 @@ extern unsigned int status;
|
|||||||
extern char *start_path;
|
extern char *start_path;
|
||||||
extern char *input;
|
extern char *input;
|
||||||
|
|
||||||
|
extern time_t *seed;
|
||||||
|
|
||||||
char search_buffer[255];
|
char search_buffer[255];
|
||||||
unsigned int timeout_time = 0;
|
unsigned int timeout_time = 0;
|
||||||
unsigned int input_pass;
|
unsigned int input_pass;
|
||||||
int parsed_input_number;
|
unsigned long parsed_input_number;
|
||||||
yank yank_files = { 0 };
|
yank yank_files = { 0 };
|
||||||
|
|
||||||
int read_string(WINDOW *win, int y, int x, char *str);
|
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 void render_pass();
|
||||||
extern int (*order_func)();
|
extern int (*order_func)();
|
||||||
|
|
||||||
@@ -66,7 +70,7 @@ void user_interactions() {
|
|||||||
|
|
||||||
ch = getch();
|
ch = getch();
|
||||||
if(ch != ERR) {
|
if(ch != ERR) {
|
||||||
timeout(1); /* blocking timeout of getch() */
|
timeout(10); /* blocking timeout of getch() */
|
||||||
input[input_pass] = ch;
|
input[input_pass] = ch;
|
||||||
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
||||||
input_pass++;
|
input_pass++;
|
||||||
@@ -79,6 +83,8 @@ void user_interactions() {
|
|||||||
}
|
}
|
||||||
binding_pass = 0;
|
binding_pass = 0;
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
} else {
|
||||||
|
timeout(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -115,7 +121,7 @@ void user_interactions() {
|
|||||||
}
|
}
|
||||||
if (status & STATUS_INPUT_MATCH) {
|
if (status & STATUS_INPUT_MATCH) {
|
||||||
attron(A_UNDERLINE);
|
attron(A_UNDERLINE);
|
||||||
mvaddstr(terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
|
mvwprintw(stdscr, terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
|
||||||
attroff(A_UNDERLINE);
|
attroff(A_UNDERLINE);
|
||||||
status &= ~STATUS_INPUT_MATCH;
|
status &= ~STATUS_INPUT_MATCH;
|
||||||
} else if (number_length != strlen(input)) {
|
} else if (number_length != strlen(input)) {
|
||||||
@@ -163,36 +169,25 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
|||||||
}
|
}
|
||||||
str[pass] = '\0';
|
str[pass] = '\0';
|
||||||
|
|
||||||
timeout(10);
|
timeout(100);
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
return err;
|
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(){
|
void quit_program(){
|
||||||
status = STATUS_QUIT_PROGRAM;
|
status = STATUS_QUIT_PROGRAM;
|
||||||
}
|
}
|
||||||
void toggle_selection(){
|
void select_all(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
mid_content[selected_file_current].status ^= FILE_STATUS_SELECTED;
|
unsigned long i;
|
||||||
status |= (STATUS_UPDATE_SCREEN_MASK);
|
for(i = 0; i < mid_file_count; i++) {
|
||||||
|
mid_content[i].status ^= FILE_STATUS_SELECTED;
|
||||||
|
}
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
void move_down(int passes){
|
void move_down(unsigned long passes){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
if (passes == 0) {
|
if (passes == 0) {
|
||||||
passes++;
|
passes++;
|
||||||
@@ -205,7 +200,7 @@ void move_down(int passes){
|
|||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
void move_up(int passes){
|
void move_up(unsigned long passes){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
if (passes == 0) {
|
if (passes == 0) {
|
||||||
passes++;
|
passes++;
|
||||||
@@ -222,11 +217,11 @@ void move_up(int passes){
|
|||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
void move_left(int passes){
|
void move_left(unsigned long passes){
|
||||||
if (passes == 0) {
|
if (passes == 0) {
|
||||||
passes++;
|
passes++;
|
||||||
}
|
}
|
||||||
int i;
|
unsigned long i;
|
||||||
for (i = 0; i < passes; i++) {
|
for (i = 0; i < passes; i++) {
|
||||||
if (chdir("..") != 0) {
|
if (chdir("..") != 0) {
|
||||||
/* TODO(2025-07-09T00:30:05) fix */
|
/* TODO(2025-07-09T00:30:05) fix */
|
||||||
@@ -241,7 +236,7 @@ void move_right(){
|
|||||||
if (mid_content->file_name[0] == '\0') {
|
if (mid_content->file_name[0] == '\0') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mid_content[selected_file_current].file_type == FILE_TYPE_DIR || mid_content[selected_file_current].file_type == FILE_TYPE_SYMLINK) {
|
if (mid_content[selected_file_current].file_type &= FILE_TYPE_DIR) {
|
||||||
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
||||||
FAIL("move_right", "unhandled error of chdir");
|
FAIL("move_right", "unhandled error of chdir");
|
||||||
} else {
|
} else {
|
||||||
@@ -252,20 +247,22 @@ void move_right(){
|
|||||||
char match = 0;
|
char match = 0;
|
||||||
char *mime = get_mimetype(mid_content[selected_file_current].file_name);
|
char *mime = get_mimetype(mid_content[selected_file_current].file_name);
|
||||||
char *extension = strrchr(mid_content[selected_file_current].file_name, '.');
|
char *extension = strrchr(mid_content[selected_file_current].file_name, '.');
|
||||||
for (i = 0; i < file_extension_default_count; i++) {
|
if (extension != NULL) {
|
||||||
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
for (i = 0; i < file_extension_default_count; i++) {
|
||||||
char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
|
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
|
||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||||
|
cmd = concat(cmd, "\"");
|
||||||
|
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
/*do nothing*/
|
/*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;
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (match == 0) {
|
if (match == 0) {
|
||||||
@@ -299,6 +296,15 @@ void toggle_hidden_files(){
|
|||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_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(){
|
void jump_bottom(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0 - 1;
|
selected_file_current = 0 - 1;
|
||||||
@@ -317,6 +323,8 @@ void jump_top(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void open_with(){
|
void open_with(){
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
btm_buffer = concat("open \"", mid_content[selected_file_current].file_name);
|
btm_buffer = concat("open \"", mid_content[selected_file_current].file_name);
|
||||||
btm_buffer = concat(btm_buffer, "\" with:");
|
btm_buffer = concat(btm_buffer, "\" with:");
|
||||||
|
|
||||||
@@ -341,6 +349,10 @@ void open_with(){
|
|||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, "\"");
|
||||||
|
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
|
images_clear();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
FAIL("open_with", "creating subcommand failed unhandled");
|
FAIL("open_with", "creating subcommand failed unhandled");
|
||||||
}
|
}
|
||||||
@@ -356,6 +368,7 @@ void open_with(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void rename_hovered(){
|
void rename_hovered(){
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name);
|
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name);
|
||||||
btm_buffer = concat(btm_buffer, "\" to:");
|
btm_buffer = concat(btm_buffer, "\" to:");
|
||||||
@@ -365,7 +378,9 @@ void rename_hovered(){
|
|||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
render_pass();
|
render_pass();
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
local_height = getmaxy(win_b);
|
local_height = getmaxy(win_b);
|
||||||
@@ -387,6 +402,7 @@ void rename_hovered(){
|
|||||||
};
|
};
|
||||||
btm_buffer = cmd;
|
btm_buffer = cmd;
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
|
||||||
@@ -395,7 +411,8 @@ void rename_hovered(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void delete(){
|
void delete(){
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int hits = 0;
|
unsigned int hits = 0;
|
||||||
char *file_str = " ";
|
char *file_str = " ";
|
||||||
@@ -424,8 +441,9 @@ void delete(){
|
|||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
render_pass();
|
render_pass();
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
timeout(-1); /* negative numbers block until enter is pressed */
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
||||||
@@ -433,32 +451,22 @@ void delete(){
|
|||||||
|
|
||||||
if (ch == 'y' || ch == 'Y') {
|
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 */
|
/* 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) {
|
if (hits) {
|
||||||
int j = 2;
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
error = remove(mid_content[i].file_name);
|
recursive_delete(mid_content[i]);
|
||||||
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++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = concat("deleted: ", file_str);
|
btm_buffer = concat("deleted: ", file_str);
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
error = remove(mid_content[selected_file_current].file_name);
|
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
||||||
if (error != 0) {
|
recursive_delete(mid_content[selected_file_current]);
|
||||||
mvaddstr(terminal_height-2, 0, "could not delete: " );
|
}
|
||||||
mvaddstr(terminal_height-2, strlen("could not delete: "), mid_content[i].file_name);
|
remove(mid_content[selected_file_current].file_name);
|
||||||
btm_buffer = " ";
|
btm_buffer = concat("deleted: \"", mid_content[selected_file_current].file_name);
|
||||||
} else {
|
btm_buffer = concat(btm_buffer, "\"");
|
||||||
btm_buffer = concat("deleted: \"", mid_content[selected_file_current].file_name);
|
|
||||||
btm_buffer = concat(btm_buffer, "\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*system(cmd);*/
|
/*system(cmd);*/
|
||||||
@@ -474,15 +482,22 @@ void delete(){
|
|||||||
if (hits) {
|
if (hits) {
|
||||||
free(file_str);
|
free(file_str);
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void makedir(){
|
void makedir(){
|
||||||
btm_buffer = "create dir: ";
|
pthread_mutex_lock(&mutex_btm);
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
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();
|
render_pass();
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
local_height = getmaxy(win_b);
|
local_height = getmaxy(win_b);
|
||||||
@@ -499,14 +514,20 @@ void makedir(){
|
|||||||
}
|
}
|
||||||
free(str);
|
free(str);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
void makefile(){
|
void makefile(){
|
||||||
btm_buffer = "create file: ";
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
|
memcpy(btm_buffer, "create file: ", strlen("create file: "));
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
render_pass();
|
render_pass();
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
local_height = getmaxy(win_b);
|
local_height = getmaxy(win_b);
|
||||||
@@ -522,15 +543,19 @@ void makefile(){
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
free(str);
|
free(str);
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(){
|
void update(){
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
}
|
}
|
||||||
void enter_shell(int passes, int index){
|
void enter_shell(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
|
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
|
images_clear();
|
||||||
|
#endif
|
||||||
endwin();
|
endwin();
|
||||||
if (system(key_binding[index].black_magic) != 0) {
|
if (system(key_binding[index].black_magic) != 0) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
@@ -538,14 +563,14 @@ void enter_shell(int passes, int index){
|
|||||||
initscr();
|
initscr();
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
}
|
}
|
||||||
void not_implemented(int passes, int index){
|
void not_implemented(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
|
|
||||||
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
|
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
|
||||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
|
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
|
||||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
||||||
}
|
}
|
||||||
void jump_to_dir(int passes, int index){
|
void jump_to_dir(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
|
|
||||||
char *ch = (char*)key_binding[index].black_magic;
|
char *ch = (char*)key_binding[index].black_magic;
|
||||||
@@ -602,14 +627,20 @@ void jump_to_dir(int passes, int index){
|
|||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
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;
|
(void)passes;
|
||||||
|
|
||||||
|
free(seed);
|
||||||
|
seed = NULL;
|
||||||
|
seed = malloc(sizeof(time_t));
|
||||||
|
*seed = time(NULL);
|
||||||
|
|
||||||
order_func = key_binding[index].black_magic;
|
order_func = key_binding[index].black_magic;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_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;
|
(void)passes;
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int hits = 0;
|
unsigned int hits = 0;
|
||||||
@@ -640,7 +671,9 @@ void cmd_on_selected(int passes, int index){
|
|||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
render_pass();
|
render_pass();
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
|
|
||||||
timeout(-1); /* negative numbers block until enter is pressed */
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
@@ -664,7 +697,7 @@ void cmd_on_selected(int passes, int index){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = concat("completed: ", key_binding[index].black_magic);
|
memcpy(btm_buffer, "completed: ", strlen("completed: "));
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
@@ -682,7 +715,7 @@ void cmd_on_selected(int passes, int index){
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = "cancled deletion";
|
memcpy(btm_buffer, "cancled deletion", strlen("cancled deletion"));
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout(10);
|
timeout(10);
|
||||||
@@ -691,18 +724,41 @@ void cmd_on_selected(int passes, int index){
|
|||||||
if (hits) {
|
if (hits) {
|
||||||
free(file_str);
|
free(file_str);
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
void yank_file(int passes, int index){
|
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;
|
(void)passes;
|
||||||
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
if (yank_files.status & YANK_IS_USED) {
|
if (yank_files.status & YANK_IS_USED) {
|
||||||
free(yank_files.path);
|
|
||||||
for (i = 0; i < yank_files.count; i++) {
|
for (i = 0; i < yank_files.count; i++) {
|
||||||
free(yank_files.list[i]);
|
free(yank_files.list[i]);
|
||||||
}
|
}
|
||||||
free(yank_files.list);
|
free(yank_files.list);
|
||||||
|
free(yank_files.path);
|
||||||
yank_files.count = 0;
|
yank_files.count = 0;
|
||||||
|
yank_files.status = 0;
|
||||||
}
|
}
|
||||||
yank_files.path=getcwd(NULL, 0);
|
yank_files.path=getcwd(NULL, 0);
|
||||||
yank_files.count = 0;
|
yank_files.count = 0;
|
||||||
@@ -719,7 +775,7 @@ void yank_file(int passes, int index){
|
|||||||
strcpy(*yank_files.list, mid_content[selected_file_current].file_name);
|
strcpy(*yank_files.list, mid_content[selected_file_current].file_name);
|
||||||
} else {
|
} else {
|
||||||
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
||||||
for (i = 0; i < mid_file_count && i < yank_files.count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
||||||
strcpy(*yank_files.list, mid_content[i].file_name);
|
strcpy(*yank_files.list, mid_content[i].file_name);
|
||||||
@@ -743,34 +799,56 @@ void paste(){
|
|||||||
/*TODO(2025-08-14T22:10:44) escape path*/
|
/*TODO(2025-08-14T22:10:44) escape path*/
|
||||||
char *cmd;
|
char *cmd;
|
||||||
if (yank_files.status & YANK_COPY) {
|
if (yank_files.status & YANK_COPY) {
|
||||||
cmd = concat("false | cp -r -i ", yank_files.path);
|
cmd = concat("false | cp -riv ", yank_files.path);
|
||||||
} else {
|
} else {
|
||||||
cmd = concat("mv ", yank_files.path);
|
cmd = concat("mv ", yank_files.path);
|
||||||
}
|
}
|
||||||
cmd = concat(cmd, "/");
|
cmd = concat(cmd, "/");
|
||||||
cmd = concat(cmd, *yank_files.list);
|
cmd = concat(cmd, *yank_files.list);
|
||||||
cmd = concat(cmd, " ./");
|
cmd = concat(cmd, " ./");
|
||||||
mvprintw(i, 0, cmd);
|
cmd = concat(cmd, *yank_files.list);
|
||||||
if (system(cmd) != 0) {
|
cmd = concat(cmd, " 2>&1");
|
||||||
cmd = concat(cmd, *yank_files.list);
|
char *line = malloc(255);
|
||||||
while (1) {
|
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, "_");
|
||||||
if (system(cmd) == 0) {
|
cmd = concat(cmd, " 2>&1");
|
||||||
break;
|
} 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.list -= yank_files.count;
|
yank_files.list -= yank_files.count;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
}
|
}
|
||||||
void search(){
|
void search(){
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
local_height = getmaxy(win_b);
|
local_height = getmaxy(win_b);
|
||||||
|
|
||||||
memset(search_buffer, '\0', 255);
|
memset(search_buffer, '\0', 255);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
render_pass();
|
render_pass();
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
|
|
||||||
@@ -828,6 +906,7 @@ void search(){
|
|||||||
update_selected_file();
|
update_selected_file();
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
void search_next(){
|
void search_next(){
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
@@ -856,3 +935,25 @@ void search_previous(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
@@ -7,10 +7,11 @@
|
|||||||
void user_interactions();
|
void user_interactions();
|
||||||
void quit_program();
|
void quit_program();
|
||||||
void toggle_selection();
|
void toggle_selection();
|
||||||
|
void select_all();
|
||||||
void move_right();
|
void move_right();
|
||||||
void move_up(int passes);
|
void move_up(unsigned long passes);
|
||||||
void move_down(int passes);
|
void move_down(unsigned long passes);
|
||||||
void move_left(int passes);
|
void move_left(unsigned long passes);
|
||||||
void jump_bottom();
|
void jump_bottom();
|
||||||
void jump_top();
|
void jump_top();
|
||||||
void toggle_hidden_files();
|
void toggle_hidden_files();
|
||||||
@@ -20,13 +21,15 @@ void delete();
|
|||||||
void makedir();
|
void makedir();
|
||||||
void makefile();
|
void makefile();
|
||||||
void update();
|
void update();
|
||||||
void enter_shell(int passes, int index);
|
void enter_shell(unsigned long passes, int index);
|
||||||
void not_implemented(int passes, int index);
|
void not_implemented(unsigned long passes, int index);
|
||||||
void jump_to_dir(int passes, int index);
|
void jump_to_dir(unsigned long passes, int index);
|
||||||
void order_by(int passes, int index);
|
void order_by(unsigned long passes, int index);
|
||||||
void cmd_on_selected(int passes, int index);
|
void cmd_on_selected(unsigned long passes, int index);
|
||||||
void yank_file(int passes, int index);
|
void yank_text(unsigned long passes, int index);
|
||||||
|
void yank_file(unsigned long passes, int index);
|
||||||
void paste();
|
void paste();
|
||||||
void search();
|
void search();
|
||||||
void search_next();
|
void search_next();
|
||||||
void search_previous();
|
void search_previous();
|
||||||
|
void jmp_file_index();
|
||||||
|
35
main.c
35
main.c
@@ -21,7 +21,7 @@ unsigned int settings;
|
|||||||
unsigned int file_modifiers;
|
unsigned int file_modifiers;
|
||||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
char *start_path;
|
char *start_path;
|
||||||
time_t seed;
|
time_t *seed;
|
||||||
|
|
||||||
WINDOW *win_t;
|
WINDOW *win_t;
|
||||||
WINDOW *win_b;
|
WINDOW *win_b;
|
||||||
@@ -60,6 +60,11 @@ int main(){
|
|||||||
|
|
||||||
char threading = 0;
|
char threading = 0;
|
||||||
terminal_width_empty_line = malloc(terminal_width);
|
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_t, NULL, thread_top, &status); /*top bar*/
|
||||||
pthread_create(&thread_l, NULL, thread_lft, &status); /*parent_content slash win_l*/
|
pthread_create(&thread_l, NULL, thread_lft, &status); /*parent_content slash win_l*/
|
||||||
@@ -76,13 +81,13 @@ int main(){
|
|||||||
temp_heigth = terminal_height;
|
temp_heigth = terminal_height;
|
||||||
}
|
}
|
||||||
if (threading) {
|
if (threading) {
|
||||||
status &= ~(STATUS_RELOAD_DIRECTORY);
|
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
||||||
threading = 0;
|
threading = 0;
|
||||||
}
|
}
|
||||||
if (status & STATUS_RUN_BACKEND) {
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
pthread_cond_signal(&cond_top);
|
pthread_cond_signal(&cond_top);
|
||||||
pthread_cond_signal(&cond_mid);
|
pthread_cond_signal(&cond_mid);
|
||||||
pthread_cond_signal(&cond_btm);
|
pthread_cond_signal(&cond_lft);
|
||||||
status &= ~(STATUS_RUN_BACKEND);
|
status &= ~(STATUS_RUN_BACKEND);
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
threading = 1;
|
threading = 1;
|
||||||
@@ -92,17 +97,30 @@ int main(){
|
|||||||
|
|
||||||
render_pass();
|
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();
|
threading_free();
|
||||||
free(start_path);
|
free(start_path);
|
||||||
|
|
||||||
if (threading) {
|
/*
|
||||||
|
if (threading) {
|
||||||
pthread_join(thread_l, NULL);
|
pthread_join(thread_l, NULL);
|
||||||
pthread_join(thread_r, NULL);
|
pthread_join(thread_r, NULL);
|
||||||
pthread_join(thread_m, NULL);
|
pthread_join(thread_m, NULL);
|
||||||
pthread_join(thread_t, NULL);
|
pthread_join(thread_t, NULL);
|
||||||
pthread_join(thread_b, NULL);
|
pthread_join(thread_b, NULL);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
delwin(win_l);
|
delwin(win_l);
|
||||||
delwin(win_m);
|
delwin(win_m);
|
||||||
@@ -183,14 +201,17 @@ void init() {
|
|||||||
|
|
||||||
threading_init(); /* found in threading.c */
|
threading_init(); /* found in threading.c */
|
||||||
colors_init(); /* in colors.c */
|
colors_init(); /* in colors.c */
|
||||||
ueberzug_init(); /* in file_previews.c */
|
|
||||||
dir_init(); /*in dir.c */
|
dir_init(); /*in dir.c */
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
|
ueberzug_init(); /* in file_previews.c */
|
||||||
|
#endif
|
||||||
|
|
||||||
ESCDELAY = 10;
|
ESCDELAY = 10;
|
||||||
char *start_path = getcwd(NULL, 0);
|
char *start_path = getcwd(NULL, 0);
|
||||||
setenv("START_PATH", start_path, 0);
|
setenv("START_PATH", start_path, 0);
|
||||||
free(start_path);
|
free(start_path);
|
||||||
time(&seed);
|
|
||||||
srand(seed);
|
seed = malloc(sizeof(time_t));
|
||||||
|
*seed = time(NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
265
sorting.c
265
sorting.c
@@ -4,167 +4,200 @@
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
extern time_t seed;
|
extern time_t *seed;
|
||||||
extern unsigned int settings;
|
|
||||||
extern unsigned int file_modifiers;
|
|
||||||
|
|
||||||
int skip_hidden_files(const struct dirent *entry){
|
int skip_hidden_files(const struct dirent *entry){
|
||||||
|
|
||||||
if (entry->d_name[0] == '.') {
|
if (entry->d_name[0] == '.') {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int skip_dot(const struct dirent *entry){
|
int skip_dot(const struct dirent *entry){
|
||||||
|
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sort_natural(const void *file0_, const void *file1_){
|
int sort_natural(const void *file0, const void *file1){
|
||||||
file *file0 = (file*)file0_;
|
|
||||||
file *file1 = (file*)file1_;
|
|
||||||
|
|
||||||
unsigned char *a = file0->file_name;
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
unsigned char *b = file1->file_name;
|
|
||||||
|
|
||||||
if (file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!(file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
unsigned long num0 = 0;
|
const unsigned char *a = (unsigned char*)((file*)file0)->file_name;
|
||||||
unsigned long num1 = 0;
|
const unsigned char *b = (unsigned char*)((file*)file1)->file_name;
|
||||||
/* bitwise OR a with ' ' turns turns caps into small letters
|
|
||||||
* while doing this on all chars may cause unexpected behaviour on the extended ascii set,
|
long parsed_number0 = 0;
|
||||||
* for now i dont care */
|
long parsed_number1 = 0;
|
||||||
while ((*a | ' ') == (*b | ' ') && *a != '\0') {
|
char is_num = 0;
|
||||||
if ((*a >= '0') && (*a <= '9')) {
|
char result = 0;
|
||||||
while((*a >= '0') && (*a <= '9')) {
|
|
||||||
num0 = (num0 * 10) + (*a - '0');
|
do {
|
||||||
|
|
||||||
|
if ((*a <= '9') && (*a >= '0')) {
|
||||||
|
parsed_number0 = 0;
|
||||||
|
do {
|
||||||
|
parsed_number0 = (parsed_number0 * 10) + (*a - '0');
|
||||||
a++;
|
a++;
|
||||||
}
|
} while((*a <= '9') && (*a >= '0'));
|
||||||
while((*b >= '0') && (*b <= '9')) {
|
is_num |= 1;
|
||||||
num1 = (num1 * 10) + (*b - '0');
|
}
|
||||||
|
if ((*b <= '9') && (*b >= '0')) {
|
||||||
|
parsed_number1 = 0;
|
||||||
|
do {
|
||||||
|
parsed_number1 = (parsed_number1 * 10) + (*b - '0');
|
||||||
b++;
|
b++;
|
||||||
}
|
} while((*b <= '9') && (*b >= '0'));
|
||||||
if (num0 != num1) {
|
is_num |= 2;
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
a++;
|
|
||||||
b++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (num0 == num1) {
|
|
||||||
if (*a == '\0') {
|
|
||||||
a--;
|
|
||||||
}
|
|
||||||
if (*b == '\0') {
|
|
||||||
b--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char c0;
|
if (is_num) {
|
||||||
unsigned char c1;
|
if (is_num == 1) {
|
||||||
/* in this case we actually check for a through z as otherwise unicode characters get ordered wrongly */
|
if (*b > '9') {
|
||||||
if (*a >= 'A' && *a <= 'Z') {
|
result = -1;
|
||||||
c0 = (*a | ' ');
|
} else {
|
||||||
} else {
|
result = 1;
|
||||||
c0 = *a;
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
if (*b >= 'A' && *b <= 'Z') {
|
|
||||||
c1 = (*b | ' ');
|
unsigned char aa = ((*a >= 'A') && (*a <= 'Z')) ? (*a | ' ') : *a;
|
||||||
} else {
|
unsigned char bb = ((*b >= 'A') && (*b <= 'Z')) ? (*b | ' ') : *b;
|
||||||
c1 = *b;
|
/*using a simple aa - bb would occasionaly cause underflows with wide chars*/
|
||||||
}
|
result = ((aa == bb) ? 0 : ((aa > bb) ? 1 : -1 ));
|
||||||
if (c0 > c1) {
|
a++;
|
||||||
return 1;
|
b++;
|
||||||
} else if (c0 < c1) {
|
} while (result == 0);
|
||||||
return -1;
|
|
||||||
} else {
|
return result;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else if (num0 > num1) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int sort_alpha(const void *file0, const void *file1){
|
int sort_alpha(const void *file0, const void *file1){
|
||||||
char *file_name0 = ((file*)file0)->file_name;
|
|
||||||
char *file_name1 = ((file*)file1)->file_name;
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return strcmp(file_name0, file_name1);
|
|
||||||
}
|
|
||||||
int sort_random(const void *file0_, const void *file1_){
|
|
||||||
file *file0 = (file*)file0_;
|
|
||||||
file *file1 = (file*)file1_;
|
|
||||||
if (file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!(file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int random = rand();
|
|
||||||
if (random & 1) {
|
return strcmp(((file*)file0)->file_name, ((file*)file1)->file_name);
|
||||||
return 1;
|
}
|
||||||
} else {
|
int sort_random(const void *file0, const void *file1){
|
||||||
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_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 << (i + (((time_t)&seed)%5));
|
||||||
|
} else {
|
||||||
|
num ^= (time_t)&seed;
|
||||||
|
num ^= num >> (i + (((time_t)&num)%5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num ^= getpid();
|
||||||
|
|
||||||
|
return ((num%3) - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
int sort_type(const void *file0, const void *file1){
|
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;
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
char *file_name0 = ((file*)file0)->file_name;
|
return -1;
|
||||||
char *file_name1 = ((file*)file1)->file_name;
|
}
|
||||||
if (file_type0 == file_type1) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return strcasecmp(file_name0, file_name1);
|
return 1;
|
||||||
} else if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
}
|
||||||
|
|
||||||
|
if (((file*)file0)->file_type > ((file*)file1)->file_type) {
|
||||||
return -1;
|
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;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
if (file_type0 > file_type1) {
|
return sort_natural(file0, file1);
|
||||||
return -1;
|
|
||||||
} else if (file_type0 < file_type1) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return strcasecmp(file_name0, file_name1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int sort_size(const void *file0, const void *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;
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
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) {
|
|
||||||
return -1;
|
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;
|
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 {
|
} else {
|
||||||
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
return sort_natural(file0, file1);
|
||||||
return -1;
|
}
|
||||||
} else if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
}
|
||||||
return 1;
|
int sort_extension(const void *file0, const void *file1){
|
||||||
} else {
|
|
||||||
if (file_size0 > file_size1) {
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (file_size0 < file_size1) {
|
}
|
||||||
return 1;
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
} else {
|
return 1;
|
||||||
return strcasecmp(file_name0, file_name1);
|
}
|
||||||
}
|
|
||||||
}
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
134
threading.c
134
threading.c
@@ -6,7 +6,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "file_previews.h"
|
#include "file_previews.h"
|
||||||
|
|
||||||
@@ -46,12 +48,15 @@ volatile unsigned long selected_file_last = 0;
|
|||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
|
|
||||||
|
unsigned int btm_status;
|
||||||
|
|
||||||
void *thread_mid(void *data){
|
|
||||||
|
void *thread_mid(){
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
pthread_cond_wait(&cond_mid, &mutex_mid);
|
pthread_cond_wait(&cond_mid, &mutex_mid);
|
||||||
|
unsigned int local_status = status;
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
if((path=getcwd(NULL, 0)) == NULL) {
|
||||||
@@ -61,7 +66,7 @@ void *thread_mid(void *data){
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
free(mid_content[i].file_name);
|
free(mid_content[i].file_name);
|
||||||
@@ -90,8 +95,9 @@ void *thread_mid(void *data){
|
|||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btm_status = local_status;
|
||||||
pthread_cond_signal(&cond_rgt);
|
pthread_cond_signal(&cond_rgt);
|
||||||
pthread_cond_signal(&cond_lft);
|
pthread_cond_signal(&cond_btm);
|
||||||
|
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
@@ -99,12 +105,12 @@ void *thread_mid(void *data){
|
|||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
void *thread_lft(void *data){
|
void *thread_lft(){
|
||||||
unsigned int local_status = *(unsigned int*)data;
|
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_lft);
|
pthread_mutex_lock(&mutex_lft);
|
||||||
pthread_cond_wait(&cond_lft, &mutex_lft);
|
pthread_cond_wait(&cond_lft, &mutex_lft);
|
||||||
|
unsigned int local_status = status;
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
if((path=getcwd(NULL, 0)) == NULL) {
|
||||||
@@ -132,9 +138,7 @@ void *thread_lft(void *data){
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void *thread_rgt(void *data){
|
void *thread_rgt(){
|
||||||
unsigned int local_status = *(unsigned int*)data;
|
|
||||||
(void)local_status;
|
|
||||||
|
|
||||||
file file_current;
|
file file_current;
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
@@ -157,8 +161,10 @@ void *thread_rgt(void *data){
|
|||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
if (mid_content[selected_file_current].permissions & S_IRUSR) {
|
if (mid_content[selected_file_current].permissions & S_IRUSR) {
|
||||||
if (file_current.file_type == FILE_TYPE_DIR || file_current.file_type == FILE_TYPE_SYMLINK) {
|
if (file_current.file_type &= FILE_TYPE_DIR) {
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < rgt_file_count; i++) {
|
for (i = 0; i < rgt_file_count; i++) {
|
||||||
@@ -177,7 +183,7 @@ void *thread_rgt(void *data){
|
|||||||
free(rgt_buffer);
|
free(rgt_buffer);
|
||||||
rgt_buffer = malloc(sizeof(char));
|
rgt_buffer = malloc(sizeof(char));
|
||||||
rgt_buffer[0] = '\0';
|
rgt_buffer[0] = '\0';
|
||||||
} else {
|
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) {
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < rgt_file_count; i++) {
|
for (i = 0; i < rgt_file_count; i++) {
|
||||||
@@ -216,9 +222,7 @@ void *thread_rgt(void *data){
|
|||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
void *thread_top(void *data){
|
void *thread_top(){
|
||||||
unsigned int local_status = *(unsigned int*)data;
|
|
||||||
(void)local_status;
|
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_top);
|
pthread_mutex_lock(&mutex_top);
|
||||||
@@ -232,7 +236,8 @@ void *thread_top(void *data){
|
|||||||
top_width = sizeof("cannot open directory");
|
top_width = sizeof("cannot open directory");
|
||||||
top_buffer = "cannot open directory";
|
top_buffer = "cannot open directory";
|
||||||
} else {
|
} else {
|
||||||
top_buffer = getcwd(NULL, 0);
|
top_buffer = malloc(strlen(path)+1);
|
||||||
|
memcpy(top_buffer, path, strlen(path)+1);
|
||||||
top_width = strlen(top_buffer);
|
top_width = strlen(top_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,19 +246,105 @@ void *thread_top(void *data){
|
|||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
void *thread_btm(void *data){
|
void *thread_btm(){
|
||||||
unsigned int local_status = *(unsigned int*)data;
|
char *path = NULL;
|
||||||
(void)local_status;
|
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)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
pthread_cond_wait(&cond_btm, &mutex_btm);
|
pthread_cond_wait(&cond_btm, &mutex_btm);
|
||||||
|
unsigned int local_status = btm_status;
|
||||||
|
|
||||||
|
|
||||||
free(btm_buffer);
|
if (local_status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
|
||||||
int buffer_width = terminal_width;
|
/*{{{ parse storage info; the fold of shame*/
|
||||||
btm_buffer = malloc(buffer_width);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
memset(btm_buffer, 0, buffer_width);
|
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[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-';
|
||||||
btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-';
|
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[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-';
|
||||||
@@ -266,6 +357,7 @@ void *thread_btm(void *data){
|
|||||||
btm_buffer[9] = (mid_content[selected_file_current].permissions & S_IXOTH) ? 'x' : '-';
|
btm_buffer[9] = (mid_content[selected_file_current].permissions & S_IXOTH) ? 'x' : '-';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
|
10
threading.h
10
threading.h
@@ -5,10 +5,10 @@
|
|||||||
#include "threading.c"
|
#include "threading.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *thread_lft(void *data);
|
void *thread_lft();
|
||||||
void *thread_mid(void *data);
|
void *thread_mid();
|
||||||
void *thread_rgt(void *data);
|
void *thread_rgt();
|
||||||
void *thread_top(void *data);
|
void *thread_top();
|
||||||
void *thread_btm(void *data);
|
void *thread_btm();
|
||||||
void threading_init();
|
void threading_init();
|
||||||
void threading_free();
|
void threading_free();
|
||||||
|
Reference in New Issue
Block a user