mirror of
https://gittea.dev/nova/th.git
synced 2025-12-11 02:00:10 -05:00
Compare commits
14 Commits
67b99b1cec
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
217884d920 | ||
|
|
3a891388ed | ||
|
|
0bdb4a1a0a | ||
|
|
ddcf4d4105 | ||
|
|
be9436570c | ||
|
|
74166f7283 | ||
|
|
9a67b35ebe | ||
|
|
1e99e9d364 | ||
|
|
dd7f5634e2 | ||
|
|
5287c77648 | ||
|
|
5b7f017588 | ||
|
|
33d7761329 | ||
|
|
0970c43c37 | ||
|
|
79f8c82338 |
3
Makefile
3
Makefile
@@ -1,7 +1,6 @@
|
|||||||
CC := gcc
|
CC := gcc
|
||||||
CFLAGS := -Wall -Wextra -O2 -flto=auto
|
CFLAGS := -Wall -Wextra -O2 -flto=auto
|
||||||
CURSES := -lncursesw -ltinfow #utf8 support
|
CURSES := $(shell pkg-config --libs ncursesw)
|
||||||
#CURSES := -lncurses -tinfo #no utf8
|
|
||||||
CFLAGS_DEBUG := $(CFLAGS) -g
|
CFLAGS_DEBUG := $(CFLAGS) -g
|
||||||
CFLAGS_PROFILE := $(CFLAGS) -pg
|
CFLAGS_PROFILE := $(CFLAGS) -pg
|
||||||
GDB := gdb --tui ./th
|
GDB := gdb --tui ./th
|
||||||
|
|||||||
40
backend.c
40
backend.c
@@ -1,14 +1,40 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
char* concat(const char *s1, const char *s2){
|
#define concat(out, s1, s2, _free) { \
|
||||||
const size_t len1 = strlen(s1);
|
concat## _free(out, s1, s2); \
|
||||||
const size_t len2 = strlen(s2);
|
|
||||||
char *result = malloc(len1 + len2 + 1);
|
|
||||||
memcpy(result, s1, len1);
|
|
||||||
memcpy(result + len1, s2, len2 + 1);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define concat0(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
|
||||||
|
#define concat1(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s1); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
#define concat2(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s2); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
#define concat3(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s1); \
|
||||||
|
free(s2); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
|
||||||
char* smartstrcasestr(const char *haystack, const char *needle){
|
char* smartstrcasestr(const char *haystack, const char *needle){
|
||||||
char smart = 0;
|
char smart = 0;
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|||||||
@@ -5,5 +5,5 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
char* concat(const char *s1, const char *s2);
|
/*char* concat(const char *s1, const char *s2);*/
|
||||||
char* smartstrcasestr(const char *haystack, const char *needle);
|
char* smartstrcasestr(const char *haystack, const char *needle);
|
||||||
|
|||||||
16
config.h
16
config.h
@@ -1,6 +1,7 @@
|
|||||||
#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */
|
#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */
|
||||||
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching */
|
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching; depends on ueberzug */
|
||||||
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds of how often the directory should be reload */
|
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds between automatic refresh of dir contents */
|
||||||
|
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
#ifndef CONFIG_GUARD
|
#ifndef CONFIG_GUARD
|
||||||
@@ -82,6 +83,7 @@ static const binding key_binding[] = {
|
|||||||
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
||||||
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
||||||
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
||||||
|
{ "gu", jump_to_dir, "/usr", "jump to /usr" },
|
||||||
|
|
||||||
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
||||||
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
||||||
@@ -109,6 +111,11 @@ static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this define
|
|||||||
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
|
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
|
||||||
static const char ui_btm_text_storage_left[] = "total free";
|
static const char ui_btm_text_storage_left[] = "total free";
|
||||||
static const char ui_btm_current_dir_size[] = "sum of dir,";
|
static const char ui_btm_current_dir_size[] = "sum of dir,";
|
||||||
|
static const char ui_open_with_text_0[] = "open"; /*ui_open_with_text_0 \"selected_file\" ui_open_with_text_1*/
|
||||||
|
static const char ui_open_with_text_1[] = "with:";
|
||||||
|
static const char ui_rename_text_0[] = "rename"; /*ui_rename_text_0 \"selected_file\" ui_rename_text_1*/
|
||||||
|
static const char ui_rename_text_1[] = "to:";
|
||||||
|
static const char ui_delete_text[] = "delete:";
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
||||||
@@ -125,5 +132,10 @@ static const unsigned long mimetype_default_count;
|
|||||||
static const unsigned long file_extension_default_count;
|
static const unsigned long file_extension_default_count;
|
||||||
static const char size_unit[];
|
static const char size_unit[];
|
||||||
static const char size_unit_count;
|
static const char size_unit_count;
|
||||||
|
static const char ui_open_with_text_0[];
|
||||||
|
static const char ui_open_with_text_1[];
|
||||||
|
static const char ui_rename_text_0[];
|
||||||
|
static const char ui_rename_text_1[];
|
||||||
|
static const char ui_delete_text[];
|
||||||
#endif
|
#endif
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|||||||
27
dir.c
27
dir.c
@@ -83,11 +83,7 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
dir_content[i].file_size = file->st_size;
|
dir_content[i].file_size = file->st_size;
|
||||||
dir_content[i].permissions = file->st_mode;
|
dir_content[i].permissions = file->st_mode;
|
||||||
|
|
||||||
if (S_ISDIR(file->st_mode)) {
|
if (S_ISLNK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_DIR;
|
|
||||||
dir_content[i].color_pair = COLOR_DIR;
|
|
||||||
dir_content[i].file_size = get_dir_size(full_path);
|
|
||||||
} else if (S_ISLNK(file->st_mode)) {
|
|
||||||
stat(full_path, file);
|
stat(full_path, file);
|
||||||
if (S_ISDIR(file->st_mode)) {
|
if (S_ISDIR(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
||||||
@@ -97,6 +93,10 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
|
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
|
||||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
dir_content[i].color_pair = COLOR_SYMLINK;
|
||||||
}
|
}
|
||||||
|
} else if (S_ISDIR(file->st_mode)) {
|
||||||
|
dir_content[i].file_type = FILE_TYPE_DIR;
|
||||||
|
dir_content[i].color_pair = COLOR_DIR;
|
||||||
|
dir_content[i].file_size = get_dir_size(full_path);
|
||||||
} else if (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;
|
||||||
@@ -315,14 +315,6 @@ 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);
|
||||||
}
|
}
|
||||||
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 {
|
||||||
@@ -335,9 +327,6 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
|
|
||||||
char update_selected_file(){
|
char update_selected_file(){
|
||||||
char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed file */
|
char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed file */
|
||||||
if (mid_content->file_name[0] == '\0') { /* only happens if the current path is either empty or inaccessible */
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (selected_file_current >= mid_file_count) {
|
if (selected_file_current >= mid_file_count) {
|
||||||
selected_file_current = mid_file_count-1;
|
selected_file_current = mid_file_count-1;
|
||||||
}
|
}
|
||||||
@@ -352,7 +341,7 @@ char update_selected_file(){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
void dir_set_selected_file_current(unsigned long selected_file_current){
|
void dir_set_selected_file_current(unsigned long selected_file_current){
|
||||||
if (mid_content->file_name[0] != '\0') {
|
if (mid_content->file_name) {
|
||||||
current_dir->selected_file_current = selected_file_current;
|
current_dir->selected_file_current = selected_file_current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,7 +381,9 @@ void dir_init(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void recursive_delete(file current_file){
|
void recursive_delete(file current_file){
|
||||||
if (current_file.file_type & FILE_TYPE_DIR) {
|
if (S_ISLNK(current_file.permissions)) {
|
||||||
|
remove(current_file.file_name);
|
||||||
|
} else if (current_file.file_type & FILE_TYPE_DIR ) {
|
||||||
unsigned int file_modifiers_tmp = file_modifiers;
|
unsigned int file_modifiers_tmp = file_modifiers;
|
||||||
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
unsigned long current_file_count = get_dir_size(current_file.file_name);
|
unsigned long current_file_count = get_dir_size(current_file.file_name);
|
||||||
|
|||||||
@@ -85,8 +85,9 @@ char* text(char *path, unsigned long *file_size){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
char* generic(char *path){
|
char* generic(char *path){
|
||||||
char *cmd = concat("file ./\"", path);
|
char *cmd;
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, "file ./\"", path, 0);
|
||||||
|
concat(cmd, cmd, "\"", 1);
|
||||||
|
|
||||||
FILE *cmd_open = popen(cmd, "r");
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
|
|||||||
207
interactions.c
207
interactions.c
@@ -41,7 +41,6 @@ extern char *input;
|
|||||||
extern time_t *seed;
|
extern time_t *seed;
|
||||||
|
|
||||||
char search_buffer[INPUT_BUFFER_SIZE];
|
char search_buffer[INPUT_BUFFER_SIZE];
|
||||||
unsigned int timeout_time = 0;
|
|
||||||
unsigned int input_pass;
|
unsigned int input_pass;
|
||||||
unsigned long parsed_input_number;
|
unsigned long parsed_input_number;
|
||||||
yank yank_files = { 0 };
|
yank yank_files = { 0 };
|
||||||
@@ -65,34 +64,23 @@ void user_interactions() {
|
|||||||
char ch;
|
char ch;
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
unsigned long binding_matches = 0;
|
unsigned long binding_matches = 0;
|
||||||
static char binding_pass = 0;
|
|
||||||
|
|
||||||
|
|
||||||
ch = getch();
|
ch = getch();
|
||||||
if(ch != ERR) {
|
if(ch != ERR) {
|
||||||
timeout(10); /* blocking timeout of getch() */
|
|
||||||
input[input_pass] = ch;
|
input[input_pass] = ch;
|
||||||
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
|
||||||
input_pass++;
|
input_pass++;
|
||||||
if (ch == 27) { /* esc key */
|
if (ch == 27) { /* esc key */
|
||||||
memset(input, ' ', terminal_width);
|
|
||||||
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
|
||||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
timeout(100); /* blocking timeout of getch() */
|
|
||||||
}
|
}
|
||||||
binding_pass = 0;
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
} else {
|
|
||||||
timeout(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void (*func_ptr)(int, int);
|
void (*func_ptr)(int, int);
|
||||||
unsigned long number_length = 0;
|
unsigned long number_length = 0;
|
||||||
|
|
||||||
if (!binding_pass) {
|
|
||||||
parsed_input_number = 0;
|
parsed_input_number = 0;
|
||||||
while((*input >= '0') && (*input <= '9')) {
|
while((*input >= '0') && (*input <= '9')) {
|
||||||
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
||||||
@@ -100,25 +88,26 @@ void user_interactions() {
|
|||||||
number_length++;
|
number_length++;
|
||||||
}
|
}
|
||||||
input -= number_length;
|
input -= number_length;
|
||||||
binding_pass = 1;
|
|
||||||
|
|
||||||
char cmp_len = strlen(input);
|
char cmp_len = strlen(input);
|
||||||
if(strlen(input) < 1) {
|
if(strlen(input) < 1) {
|
||||||
cmp_len++;
|
cmp_len = 1;
|
||||||
}
|
}
|
||||||
for (i = 0; i < binding_count; i++) {
|
for (i = 0; i < binding_count; i++) {
|
||||||
|
if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
||||||
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
||||||
|
|
||||||
func_ptr = key_binding[i].func;
|
func_ptr = key_binding[i].func;
|
||||||
func_ptr(parsed_input_number, i);
|
func_ptr(parsed_input_number, i);
|
||||||
|
|
||||||
} else if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */
|
||||||
|
} else {
|
||||||
binding_matches++;
|
binding_matches++;
|
||||||
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
|
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
|
||||||
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "%s\t%s", key_binding[i].key, key_binding[i].comment);
|
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "%s\t%s", key_binding[i].key, key_binding[i].comment);
|
||||||
status |= STATUS_INPUT_MATCH;
|
status |= STATUS_INPUT_MATCH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (status & STATUS_INPUT_MATCH) {
|
if (status & STATUS_INPUT_MATCH) {
|
||||||
attron(A_UNDERLINE);
|
attron(A_UNDERLINE);
|
||||||
mvwprintw(stdscr, terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
|
mvwprintw(stdscr, terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
|
||||||
@@ -127,10 +116,8 @@ void user_interactions() {
|
|||||||
} else if (number_length != strlen(input)) {
|
} else if (number_length != strlen(input)) {
|
||||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
binding_pass = 0;
|
|
||||||
number_length = 0;
|
number_length = 0;
|
||||||
timeout(100); /* blocking timeout of getch() */
|
binding_matches = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int read_string(WINDOW *win, int y, int x, char *str){
|
int read_string(WINDOW *win, int y, int x, char *str){
|
||||||
@@ -169,7 +156,6 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
|||||||
}
|
}
|
||||||
str[pass] = '\0';
|
str[pass] = '\0';
|
||||||
|
|
||||||
timeout(100);
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@@ -195,7 +181,7 @@ void move_down(unsigned long passes){
|
|||||||
selected_file_current += passes;
|
selected_file_current += passes;
|
||||||
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
|
|
||||||
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);
|
||||||
@@ -212,7 +198,8 @@ void move_up(unsigned long passes){
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -250,9 +237,10 @@ void move_right(){
|
|||||||
if (extension != NULL) {
|
if (extension != NULL) {
|
||||||
for (i = 0; i < file_extension_default_count; i++) {
|
for (i = 0; i < file_extension_default_count; i++) {
|
||||||
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
||||||
char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
|
char *cmd;
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, file_extension_default_cmd[i].command, " ./\"", 0);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(cmd, cmd, "\"", 1);
|
||||||
|
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
@@ -269,10 +257,10 @@ void move_right(){
|
|||||||
for (i = 0; i < mimetype_default_count; i++) {
|
for (i = 0; i < mimetype_default_count; i++) {
|
||||||
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||||
|
|
||||||
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
|
char *cmd;
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, mimetype_default_cmd[i].command, " ./\"", 0);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(cmd, cmd, "\"", 1);
|
||||||
|
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
@@ -307,7 +295,7 @@ void jump_bottom(){
|
|||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0 - 1;
|
selected_file_current = 0 - 1;
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -315,7 +303,7 @@ void jump_top(){
|
|||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0;
|
selected_file_current = 0;
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -329,8 +317,11 @@ void open_with(){
|
|||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
btm_buffer = concat("open \"", mid_content[selected_file_current].file_name);
|
concat(btm_buffer, ui_open_with_text_0, " \"", 0);
|
||||||
btm_buffer = concat(btm_buffer, "\" with:");
|
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(btm_buffer, btm_buffer, "\" ", 1);
|
||||||
|
concat(btm_buffer, btm_buffer, ui_open_with_text_1, 1);
|
||||||
|
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
@@ -342,17 +333,20 @@ void open_with(){
|
|||||||
|
|
||||||
|
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
char *cmd = concat(str, " ./\"");
|
char *cmd;
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, str, " ./\"", 0);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(cmd, cmd, "\"", 1);
|
||||||
|
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
endwin();
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
FAIL("open_with", "creating subcommand failed unhandled");
|
FAIL("open_with", "creating subcommand failed unhandled");
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
@@ -372,8 +366,10 @@ void rename_hovered(){
|
|||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name);
|
concat(btm_buffer, ui_rename_text_0, " \"", 0);
|
||||||
btm_buffer = concat(btm_buffer, "\" to:");
|
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(btm_buffer, btm_buffer, "\" ", 1);
|
||||||
|
concat(btm_buffer, btm_buffer, ui_rename_text_1, 1);
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
@@ -384,10 +380,11 @@ void rename_hovered(){
|
|||||||
|
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
char *cmd = concat("mv ./\"", mid_content[selected_file_current].file_name);
|
char *cmd;
|
||||||
cmd = concat(cmd, "\" ./\"");
|
concat(cmd, "mv ./\"", mid_content[selected_file_current].file_name, 0);
|
||||||
cmd = concat(cmd, str);
|
concat(cmd, cmd, "\" ./\"", 1);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, str, 1);
|
||||||
|
concat(cmd, cmd, "\"", 1);
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
FAIL("rename_hovered", "mv or creating subcommand failed");
|
FAIL("rename_hovered", "mv or creating subcommand failed");
|
||||||
@@ -414,9 +411,9 @@ void delete(){
|
|||||||
char *file_str = "";
|
char *file_str = "";
|
||||||
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) {
|
||||||
file_str = concat(file_str, "\"");
|
concat(file_str, file_str, "\"", 0);
|
||||||
file_str = concat(file_str, mid_content[i].file_name);
|
concat(file_str, file_str, mid_content[i].file_name, 1);
|
||||||
file_str = concat(file_str, "\" ");
|
concat(file_str, file_str, "\" ", 1);
|
||||||
hits++;
|
hits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,13 +425,13 @@ void delete(){
|
|||||||
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3));
|
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3));
|
||||||
memset(btm_buffer, ' ', (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)));
|
memset(btm_buffer, ' ', (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)));
|
||||||
|
|
||||||
memcpy(btm_buffer, "delete: ",strlen("delete: "));
|
memcpy(btm_buffer, ui_delete_text ,strlen(ui_delete_text));
|
||||||
if (hits) {
|
if (hits) {
|
||||||
memcpy(btm_buffer + strlen("delete: "), file_str, strlen(file_str));
|
memcpy(btm_buffer + strlen(ui_delete_text)+1, file_str, strlen(file_str));
|
||||||
} else {
|
} else {
|
||||||
btm_buffer[strlen("delete: ")] = '"';
|
btm_buffer[strlen(ui_delete_text)+1] = '"';
|
||||||
memcpy(btm_buffer + strlen("delete: ") + sizeof(char), mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)-1);
|
memcpy(btm_buffer + strlen(ui_delete_text) +1 + sizeof(char), mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
||||||
btm_buffer[strlen("delete: ") + sizeof(char) + strlen(mid_content[selected_file_current].file_name)] = '"';
|
btm_buffer[strlen(ui_delete_text)+1 + sizeof(char) + strlen(mid_content[selected_file_current].file_name)] = '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3) - (terminal_width/3)) , "(y/N)", strlen("(y/N)"));
|
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3) - (terminal_width/3)) , "(y/N)", strlen("(y/N)"));
|
||||||
@@ -446,11 +443,11 @@ void delete(){
|
|||||||
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||||
memset(btm_buffer, ' ', BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
memset(btm_buffer, ' ', BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||||
|
|
||||||
memcpy(btm_buffer, "delete: ",strlen("delete: "));
|
memcpy(btm_buffer, ui_delete_text ,strlen(ui_delete_text));
|
||||||
|
|
||||||
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
|
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
|
||||||
/*lets hope im never gonna need to format something like this ever again*/
|
/*lets hope im never gonna need to format something like this ever again*/
|
||||||
memcpy(btm_buffer + strlen("delete: "), file_str,
|
memcpy(btm_buffer + strlen(ui_delete_text)+1, file_str,
|
||||||
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
|
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
|
||||||
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
|
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
|
||||||
strlen(file_str)));
|
strlen(file_str)));
|
||||||
@@ -473,9 +470,7 @@ void delete(){
|
|||||||
recursive_delete(mid_content[i]);
|
recursive_delete(mid_content[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(btm_buffer);
|
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
|
||||||
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
||||||
recursive_delete(mid_content[selected_file_current]);
|
recursive_delete(mid_content[selected_file_current]);
|
||||||
}
|
}
|
||||||
@@ -489,7 +484,6 @@ void delete(){
|
|||||||
free(file_str);
|
free(file_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout(10);
|
|
||||||
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);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
@@ -514,7 +508,7 @@ void makedir(){
|
|||||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
btm_buffer = concat(btm_buffer, str);
|
concat(btm_buffer, btm_buffer, str, 0);
|
||||||
mode_t mask = umask(0);
|
mode_t mask = umask(0);
|
||||||
mkdir(str, 0755); /*magic number from default permissions as created by mkdir*/
|
mkdir(str, 0755); /*magic number from default permissions as created by mkdir*/
|
||||||
umask(mask);
|
umask(mask);
|
||||||
@@ -544,7 +538,7 @@ void makefile(){
|
|||||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
btm_buffer = concat(btm_buffer, str);
|
concat(btm_buffer, btm_buffer, str, 0);
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
fp = fopen(str, "w");
|
fp = fopen(str, "w");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@@ -607,7 +601,7 @@ void jump_to_dir(unsigned long passes, int index){
|
|||||||
env_str[env_len-1] = '\0';
|
env_str[env_len-1] = '\0';
|
||||||
env_parsed = getenv(env_str);
|
env_parsed = getenv(env_str);
|
||||||
if (env_parsed) {
|
if (env_parsed) {
|
||||||
path = concat(env_parsed, (char*)key_binding[index].black_magic + env_len);
|
concat(path, env_parsed, (char*)key_binding[index].black_magic + env_len, 0);
|
||||||
} else {
|
} else {
|
||||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||||
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
||||||
@@ -653,29 +647,30 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
char *btm_buffer_tmp = btm_buffer;
|
char *btm_buffer_tmp = btm_buffer;
|
||||||
|
btm_buffer = "";
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int hits = 0;
|
unsigned int hits = 0;
|
||||||
char *file_str = "";
|
char *file_str = "";
|
||||||
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) {
|
||||||
file_str = concat(file_str, "\"");
|
concat(file_str, file_str, "\"", 0);
|
||||||
file_str = concat(file_str, mid_content[i].file_name);
|
concat(file_str, file_str, mid_content[i].file_name, 1);
|
||||||
file_str = concat(file_str, "\" ");
|
concat(file_str, file_str, "\" ", 1);
|
||||||
hits++;
|
hits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hits) {
|
if (hits) {
|
||||||
btm_buffer = concat(key_binding[index].black_magic, file_str);
|
concat(btm_buffer, key_binding[index].black_magic, file_str, 2);
|
||||||
} else {
|
} else {
|
||||||
btm_buffer = concat(key_binding[index].black_magic, "\"");
|
concat(btm_buffer, key_binding[index].black_magic, "\"", 0);
|
||||||
btm_buffer = concat(btm_buffer, mid_content[selected_file_current].file_name);
|
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
||||||
btm_buffer = concat(btm_buffer, "\"");
|
concat(btm_buffer, btm_buffer, "\"", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
btm_buffer = concat(btm_buffer, "?");
|
concat(btm_buffer, btm_buffer, "?", 1);
|
||||||
btm_buffer = concat(btm_buffer, "\n\n");
|
concat(btm_buffer, btm_buffer, "\n\n", 1);
|
||||||
btm_buffer = concat(btm_buffer, "(y/N)");
|
concat(btm_buffer, btm_buffer, "(y/N)", 1);
|
||||||
|
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
@@ -691,26 +686,24 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
/* the second loop is used to add "./", wich is not being printed" */
|
/* the second loop is used to add "./", wich is not being printed" */
|
||||||
char *cmd = malloc(sizeof(char));
|
char *cmd = malloc(sizeof(char));
|
||||||
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
||||||
|
endwin();
|
||||||
if (hits) {
|
if (hits) {
|
||||||
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) {
|
||||||
free(cmd);
|
free(cmd);
|
||||||
cmd = concat((char*)key_binding[index].black_magic, " \"");
|
concat(cmd, (char*)key_binding[index].black_magic, " \"", 0);
|
||||||
cmd = concat(cmd, mid_content[i].file_name);
|
concat(cmd, cmd, mid_content[i].file_name, 1);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, "\"", 1);
|
||||||
if (system(cmd) != 0) {
|
if (system(cmd) != 0) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(btm_buffer);
|
|
||||||
memcpy(btm_buffer, "completed: ", strlen("completed: "));
|
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
cmd = concat((char*)key_binding[index].black_magic, " \"");
|
concat(cmd, (char*)key_binding[index].black_magic, " \"", 0);
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, "\"", 1);
|
||||||
if (system(cmd) != 0) {
|
if (system(cmd) != 0) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
}
|
}
|
||||||
@@ -719,20 +712,14 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
}
|
}
|
||||||
/*system(cmd);*/
|
/*system(cmd);*/
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
initscr();
|
||||||
|
|
||||||
} else {
|
|
||||||
free(btm_buffer);
|
|
||||||
memcpy(btm_buffer, "cancled deletion", strlen("cancled deletion"));
|
|
||||||
}
|
}
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = btm_buffer_tmp;
|
btm_buffer = btm_buffer_tmp;
|
||||||
|
|
||||||
timeout(10);
|
|
||||||
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);
|
||||||
|
|
||||||
if (hits) {
|
|
||||||
free(file_str);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
void yank_text(unsigned long passes, int index){
|
void yank_text(unsigned long passes, int index){
|
||||||
@@ -740,16 +727,16 @@ void yank_text(unsigned long passes, int index){
|
|||||||
char *cmd;
|
char *cmd;
|
||||||
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
|
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
|
||||||
char *path=getcwd(NULL, 0);
|
char *path=getcwd(NULL, 0);
|
||||||
cmd = concat("echo \"", path);
|
concat(cmd, "echo \"", path, 0);
|
||||||
cmd = concat(cmd, "/");
|
concat(cmd, cmd, "/", 1);
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
cmd = concat(cmd, "\" | ");
|
concat(cmd, cmd, "\" | ", 1);
|
||||||
cmd = concat(cmd, clipboard_cmd);
|
concat(cmd, cmd, clipboard_cmd, 1);
|
||||||
free(path);
|
free(path);
|
||||||
} else {
|
} else {
|
||||||
cmd = concat("echo \"", mid_content[selected_file_current].file_name);
|
concat(cmd, "echo \"", mid_content[selected_file_current].file_name, 0);
|
||||||
cmd = concat(cmd, "\" | ");
|
concat(cmd, cmd, "\" | ", 1);
|
||||||
cmd = concat(cmd, clipboard_cmd);
|
concat(cmd, cmd, clipboard_cmd, 1);
|
||||||
}
|
}
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
@@ -781,13 +768,13 @@ void yank_file(unsigned long passes, int index){
|
|||||||
yank_files.count = 1;
|
yank_files.count = 1;
|
||||||
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
|
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
|
||||||
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
||||||
memcpy(*yank_files.list, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
memcpy(*yank_files.list, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)+1);
|
||||||
} 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++) {
|
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);
|
||||||
memcpy(*yank_files.list, mid_content[i].file_name, strlen(mid_content[i].file_name));
|
memcpy(*yank_files.list, mid_content[i].file_name, strlen(mid_content[i].file_name)+1);
|
||||||
yank_files.list += 1;
|
yank_files.list += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -808,15 +795,15 @@ 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 -riv ", yank_files.path);
|
concat(cmd, "false | cp -ri ", yank_files.path, 0);
|
||||||
} else {
|
} else {
|
||||||
cmd = concat("mv ", yank_files.path);
|
concat(cmd, "mv ", yank_files.path, 0);
|
||||||
}
|
}
|
||||||
cmd = concat(cmd, "/");
|
concat(cmd, cmd, "/", 1);
|
||||||
cmd = concat(cmd, *yank_files.list);
|
concat(cmd, cmd, *yank_files.list, 1);
|
||||||
cmd = concat(cmd, " ./");
|
concat(cmd, cmd, " ./", 1);
|
||||||
cmd = concat(cmd, *yank_files.list);
|
concat(cmd, cmd, *yank_files.list, 1);
|
||||||
cmd = concat(cmd, " 2>&1");
|
concat(cmd, cmd, " 2>&1", 1);
|
||||||
char *line = malloc(INPUT_BUFFER_SIZE);
|
char *line = malloc(INPUT_BUFFER_SIZE);
|
||||||
FILE *cmd_open;
|
FILE *cmd_open;
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -826,19 +813,22 @@ void paste(){
|
|||||||
}
|
}
|
||||||
if (strstr(line, "are the same file")) {
|
if (strstr(line, "are the same file")) {
|
||||||
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
||||||
cmd = concat(cmd, "_");
|
concat(cmd, cmd, "_", 1);
|
||||||
cmd = concat(cmd, " 2>&1");
|
concat(cmd, cmd, " 2>&1", 1);
|
||||||
} else if ((strstr(line, "overwrite"))) {
|
} else if ((strstr(line, "overwrite"))) {
|
||||||
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
||||||
cmd = concat(cmd, "_");
|
concat(cmd, cmd, "_", 1);
|
||||||
cmd = concat(cmd, " 2>&1");
|
concat(cmd, cmd, " 2>&1", 1);
|
||||||
} else if ((strstr(line, "No such file or directory"))) {
|
} else if ((strstr(line, "No such file or directory"))) {
|
||||||
pclose(cmd_open);
|
pclose(cmd_open);
|
||||||
break;
|
break;
|
||||||
} else if (pclose(cmd_open) == 0) {
|
} else if ((strstr(line, "into itself"))) {
|
||||||
|
pclose(cmd_open);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pclose(cmd_open) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pclose(cmd_open);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
@@ -905,10 +895,9 @@ void search(){
|
|||||||
}
|
}
|
||||||
search_buffer[pass] = '\0';
|
search_buffer[pass] = '\0';
|
||||||
|
|
||||||
timeout(10);
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
|
|
||||||
|
|||||||
42
main.c
42
main.c
@@ -7,6 +7,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#include "config.h"
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "window.c"
|
#include "window.c"
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
@@ -21,6 +22,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;
|
||||||
|
char *global_path;
|
||||||
time_t *seed;
|
time_t *seed;
|
||||||
|
|
||||||
WINDOW *win_t;
|
WINDOW *win_t;
|
||||||
@@ -35,7 +37,6 @@ char *terminal_width_empty_line; /* used in user_interactions */
|
|||||||
void render_pass();
|
void render_pass();
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
init();
|
init();
|
||||||
@@ -58,7 +59,6 @@ int main(){
|
|||||||
pthread_t thread_m;
|
pthread_t thread_m;
|
||||||
pthread_t thread_r;
|
pthread_t thread_r;
|
||||||
|
|
||||||
char threading = 0;
|
|
||||||
terminal_width_empty_line = malloc(terminal_width);
|
terminal_width_empty_line = malloc(terminal_width);
|
||||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||||
time_t t;
|
time_t t;
|
||||||
@@ -72,6 +72,16 @@ int main(){
|
|||||||
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
||||||
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
||||||
|
|
||||||
|
|
||||||
|
/* running through all once manually in order to get an as fast as possible first render on the screen */
|
||||||
|
pthread_cond_signal(&cond_top);
|
||||||
|
pthread_cond_signal(&cond_mid);
|
||||||
|
pthread_cond_signal(&cond_lft);
|
||||||
|
user_interactions();
|
||||||
|
render_pass();
|
||||||
|
timeout(SETTINGS_CURSES_TIMEOUT);
|
||||||
|
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||||
|
|
||||||
@@ -80,21 +90,18 @@ int main(){
|
|||||||
temp_width = terminal_width;
|
temp_width = terminal_width;
|
||||||
temp_heigth = terminal_height;
|
temp_heigth = terminal_height;
|
||||||
}
|
}
|
||||||
if (threading) {
|
|
||||||
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
|
||||||
threading = 0;
|
|
||||||
}
|
|
||||||
if (status & STATUS_RUN_BACKEND) {
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
|
global_path = getcwd(NULL, 0);
|
||||||
pthread_cond_signal(&cond_top);
|
pthread_cond_signal(&cond_top);
|
||||||
pthread_cond_signal(&cond_mid);
|
pthread_cond_signal(&cond_mid);
|
||||||
pthread_cond_signal(&cond_lft);
|
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;
|
} else {
|
||||||
|
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
||||||
}
|
}
|
||||||
user_interactions();
|
user_interactions();
|
||||||
|
|
||||||
|
|
||||||
render_pass();
|
render_pass();
|
||||||
|
|
||||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||||
@@ -112,16 +119,6 @@ int main(){
|
|||||||
threading_free();
|
threading_free();
|
||||||
free(start_path);
|
free(start_path);
|
||||||
|
|
||||||
/*
|
|
||||||
if (threading) {
|
|
||||||
pthread_join(thread_l, NULL);
|
|
||||||
pthread_join(thread_r, NULL);
|
|
||||||
pthread_join(thread_m, NULL);
|
|
||||||
pthread_join(thread_t, NULL);
|
|
||||||
pthread_join(thread_b, NULL);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
delwin(win_l);
|
delwin(win_l);
|
||||||
delwin(win_m);
|
delwin(win_m);
|
||||||
delwin(win_r);
|
delwin(win_r);
|
||||||
@@ -143,9 +140,6 @@ void render_pass(){
|
|||||||
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*TODO: check if deallocation of window and reallocation is faster than this or not */
|
|
||||||
|
|
||||||
|
|
||||||
wresize(win_t, 1, terminal_width);
|
wresize(win_t, 1, terminal_width);
|
||||||
wresize(win_l, terminal_height-2, terminal_width/8);
|
wresize(win_l, terminal_height-2, terminal_width/8);
|
||||||
wresize(win_m, terminal_height-2, (terminal_width/2)-(terminal_width/8));
|
wresize(win_m, terminal_height-2, (terminal_width/2)-(terminal_width/8));
|
||||||
@@ -183,7 +177,10 @@ void init() {
|
|||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
initscr(); /* start ncurses */
|
initscr(); /* start ncurses */
|
||||||
noecho(); /* hide keyboard input */
|
noecho(); /* hide keyboard input */
|
||||||
timeout(0); /* blocking timeout of getch() */
|
timeout(10); /* blocking timeout of getch(), using 10 rather than SETTINGS_CURSES_TIMEOUT to cause a faster first render
|
||||||
|
regardless on SETTINGS_CURSES_TIMEOUT, 10 was taken arbitrary.
|
||||||
|
if the blocking is too low, the first render happens delayed, however even this delay causes a quicker than
|
||||||
|
(compute time of threads) + timeout */
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
||||||
@@ -202,6 +199,7 @@ void init() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ESCDELAY = 10;
|
ESCDELAY = 10;
|
||||||
|
global_path = getcwd(NULL, 0);
|
||||||
char *start_path = getcwd(NULL, 0);
|
char *start_path = getcwd(NULL, 0);
|
||||||
setenv("START_PATH", start_path, 0);
|
setenv("START_PATH", start_path, 0);
|
||||||
free(start_path);
|
free(start_path);
|
||||||
|
|||||||
52
threading.c
52
threading.c
@@ -47,6 +47,7 @@ volatile unsigned long selected_file_current = 0;
|
|||||||
volatile unsigned long selected_file_last = 0;
|
volatile unsigned long selected_file_last = 0;
|
||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
|
extern char *global_path;
|
||||||
|
|
||||||
unsigned int btm_status;
|
unsigned int btm_status;
|
||||||
|
|
||||||
@@ -58,13 +59,15 @@ void *thread_mid(){
|
|||||||
pthread_cond_wait(&cond_mid, &mutex_mid);
|
pthread_cond_wait(&cond_mid, &mutex_mid);
|
||||||
unsigned int local_status = status;
|
unsigned int local_status = status;
|
||||||
|
|
||||||
char *path;
|
if (global_path == NULL) {
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
|
||||||
mid_content = malloc(sizeof(file));
|
mid_content = malloc(sizeof(file));
|
||||||
mid_content->file_name = "cannot open directory";
|
mid_content->file_name = "cannot open directory";
|
||||||
mid_file_count = 1;
|
mid_file_count = 1;
|
||||||
} else {
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char *path = malloc(strlen(global_path)+1);
|
||||||
|
memcpy(path, global_path, strlen(global_path)+1);
|
||||||
|
|
||||||
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
@@ -99,7 +102,6 @@ void *thread_mid(){
|
|||||||
pthread_cond_signal(&cond_rgt);
|
pthread_cond_signal(&cond_rgt);
|
||||||
pthread_cond_signal(&cond_btm);
|
pthread_cond_signal(&cond_btm);
|
||||||
|
|
||||||
}
|
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
}
|
}
|
||||||
@@ -112,13 +114,18 @@ void *thread_lft(){
|
|||||||
pthread_cond_wait(&cond_lft, &mutex_lft);
|
pthread_cond_wait(&cond_lft, &mutex_lft);
|
||||||
unsigned int local_status = status;
|
unsigned int local_status = status;
|
||||||
|
|
||||||
char *path;
|
if (global_path == NULL) {
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
|
||||||
lft_content = malloc(sizeof(file));
|
lft_content = malloc(sizeof(file));
|
||||||
lft_content[0].file_name = "cannot open directory";
|
lft_content[0].file_name = "cannot open directory";
|
||||||
lft_file_count = 1;
|
lft_file_count = 1;
|
||||||
} else {
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char *path = malloc(strlen(global_path)+1);
|
||||||
|
memcpy(path, global_path, strlen(global_path)+1);
|
||||||
|
|
||||||
|
if (strcmp(path, "/") != 0) {
|
||||||
|
path[strrchr(path, '/')-path+1] = '\0';
|
||||||
path[strrchr(path, '/')-path] = '\0';
|
path[strrchr(path, '/')-path] = '\0';
|
||||||
path[0] = '/';
|
path[0] = '/';
|
||||||
|
|
||||||
@@ -129,8 +136,11 @@ void *thread_lft(){
|
|||||||
memset(lft_content, '\0', lft_file_count * sizeof(file));
|
memset(lft_content, '\0', lft_file_count * sizeof(file));
|
||||||
get_dir_content(path, &lft_file_count, lft_content);
|
get_dir_content(path, &lft_file_count, lft_content);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
lft_file_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
}
|
}
|
||||||
@@ -230,18 +240,17 @@ void *thread_top(){
|
|||||||
|
|
||||||
free(top_buffer);
|
free(top_buffer);
|
||||||
|
|
||||||
char *path;
|
if(global_path == NULL) {
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
|
||||||
top_buffer = malloc(sizeof("cannot open directory"));
|
top_buffer = malloc(sizeof("cannot open directory"));
|
||||||
top_width = sizeof("cannot open directory");
|
top_width = sizeof("cannot open directory");
|
||||||
top_buffer = "cannot open directory";
|
top_buffer = "cannot open directory";
|
||||||
} else {
|
pthread_mutex_unlock(&mutex_top);
|
||||||
top_buffer = malloc(strlen(path)+1);
|
continue;
|
||||||
memcpy(top_buffer, path, strlen(path)+1);
|
|
||||||
top_width = strlen(top_buffer);
|
|
||||||
}
|
}
|
||||||
|
top_buffer = malloc(strlen(global_path)+1);
|
||||||
|
memcpy(top_buffer, global_path, strlen(global_path)+1);
|
||||||
|
top_width = strlen(top_buffer);
|
||||||
|
|
||||||
free(path);
|
|
||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
@@ -271,14 +280,6 @@ void *thread_btm(){
|
|||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
|
|
||||||
if (path != NULL) {
|
|
||||||
/* sometimes NULL remains, need to do deeper analysis soon */
|
|
||||||
free(path);
|
|
||||||
path = NULL;
|
|
||||||
} else {
|
|
||||||
volatile static int debug_thread_btm;
|
|
||||||
debug_thread_btm++;
|
|
||||||
}
|
|
||||||
free(ui_btm_right_block);
|
free(ui_btm_right_block);
|
||||||
|
|
||||||
path = getcwd(NULL, 0);
|
path = getcwd(NULL, 0);
|
||||||
@@ -345,7 +346,8 @@ void *thread_btm(){
|
|||||||
|
|
||||||
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
|
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
|
||||||
|
|
||||||
btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-';
|
btm_buffer[0] = (S_ISLNK(mid_content[selected_file_current].permissions)) ? 'l':
|
||||||
|
(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' : '-';
|
||||||
btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-';
|
btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-';
|
||||||
|
|||||||
Reference in New Issue
Block a user