start of a major rewrite
This commit is contained in:
751
interactions.c
751
interactions.c
@@ -21,9 +21,7 @@ extern pthread_mutex_t mutex_rgt;
|
||||
extern pthread_mutex_t mutex_mid;
|
||||
extern pthread_mutex_t mutex_btm;
|
||||
extern pthread_cond_t cond_rgt;
|
||||
extern file *mid_content;
|
||||
extern file *lft_content;
|
||||
extern file *rgt_content;
|
||||
extern dir mid_dir;
|
||||
|
||||
extern unsigned int terminal_height;
|
||||
extern unsigned int terminal_width;
|
||||
@@ -32,7 +30,6 @@ extern WINDOW *win_b;
|
||||
|
||||
extern char *rgt_buffer;
|
||||
extern char *btm_buffer;
|
||||
extern unsigned long mid_file_count;
|
||||
|
||||
extern unsigned int status;
|
||||
extern char *start_path;
|
||||
@@ -46,16 +43,17 @@ unsigned long parsed_input_number;
|
||||
yank yank_files = { 0 };
|
||||
|
||||
extern void render_pass();
|
||||
extern void window_btm(WINDOW *win, char force_render);
|
||||
extern int (*order_func)();
|
||||
|
||||
|
||||
#define TODO noraw(); \
|
||||
endwin();\
|
||||
curs_set(1);\
|
||||
echo();\
|
||||
printf("TODO: %s at %d in %s \n", __func__, __LINE__, __FILE__);\
|
||||
exit(1);
|
||||
|
||||
void FAIL(char *function, char *str){
|
||||
noraw();
|
||||
endwin();
|
||||
curs_set(1);
|
||||
echo();
|
||||
printf("ERROR in function %s: %s", function, str);
|
||||
}
|
||||
void user_interactions() {
|
||||
@@ -74,7 +72,7 @@ void user_interactions() {
|
||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||
input_pass = 0;
|
||||
}
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
status |= STATUS_UPDATE_SCREEN_INTERACTION;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +85,9 @@ void user_interactions() {
|
||||
input++;
|
||||
number_length++;
|
||||
}
|
||||
if (parsed_input_number == 0) {
|
||||
parsed_input_number = 1;
|
||||
}
|
||||
input -= number_length;
|
||||
|
||||
char cmp_len = strlen(input);
|
||||
@@ -137,9 +138,9 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
||||
err = 0;
|
||||
break;
|
||||
} else if (ch == '\t') { /* tab */
|
||||
memcpy(str + pass, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
||||
mvwaddstr(win, y, x +pass, mid_content[selected_file_current].file_name);
|
||||
pass += strlen(mid_content[selected_file_current].file_name);
|
||||
memcpy(str + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
||||
mvwaddstr(win, y, x +pass, mid_dir.current_file->file_name);
|
||||
pass += strlen(mid_dir.current_file->file_name);
|
||||
} else if (ch == 127) { /* backspace */
|
||||
if (pass > 0) {
|
||||
pass--;
|
||||
@@ -163,385 +164,71 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
||||
void quit_program(){
|
||||
status = STATUS_QUIT_PROGRAM;
|
||||
}
|
||||
void update(){
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_MASK);
|
||||
}
|
||||
void select_all(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
unsigned long i;
|
||||
for(i = 0; i < mid_file_count; i++) {
|
||||
mid_content[i].status ^= FILE_STATUS_SELECTED;
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
TODO;
|
||||
}
|
||||
void move_down(unsigned long passes){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
if (passes == 0) {
|
||||
passes++;
|
||||
mid_dir.current_file = mid_dir.current_file + passes;
|
||||
if (mid_dir.current_file >= mid_dir.file_list + mid_dir.file_count - 1) {
|
||||
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||
}
|
||||
selected_file_current += passes;
|
||||
|
||||
update_selected_file();
|
||||
current_dir->selected_file_current = selected_file_current;
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_INTERACTION);
|
||||
}
|
||||
void move_up(unsigned long passes){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
if (passes == 0) {
|
||||
passes++;
|
||||
mid_dir.current_file = mid_dir.current_file - passes;
|
||||
if (mid_dir.current_file <= mid_dir.file_list) {
|
||||
mid_dir.current_file = mid_dir.file_list;
|
||||
}
|
||||
unsigned long tmp = selected_file_current;
|
||||
selected_file_current -= passes;
|
||||
if (tmp < selected_file_current) {
|
||||
selected_file_current = 0;
|
||||
}
|
||||
|
||||
update_selected_file();
|
||||
current_dir->selected_file_current = selected_file_current;
|
||||
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_INTERACTION);
|
||||
}
|
||||
void move_left(unsigned long passes){
|
||||
if (passes == 0) {
|
||||
passes++;
|
||||
}
|
||||
unsigned long i;
|
||||
for (i = 0; i < passes; i++) {
|
||||
if (chdir("..") != 0) {
|
||||
/* TODO(2025-07-09T00:30:05) fix */
|
||||
FAIL("move_left", "unhandled error of chdir");
|
||||
} else {
|
||||
selected_file_current = dir_get_selected_file_current();
|
||||
}
|
||||
}
|
||||
update_selected_file();
|
||||
current_dir->selected_file_current = selected_file_current;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||
update();
|
||||
|
||||
}
|
||||
void move_right(){
|
||||
if (mid_content->file_name[0] == '\0') {
|
||||
return;
|
||||
}
|
||||
if ((mid_content[selected_file_current].file_type & FILE_TYPE_DIR) == FILE_TYPE_DIR) {
|
||||
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
||||
FAIL("move_right", "unhandled error of chdir");
|
||||
} else {
|
||||
selected_file_current = dir_get_selected_file_current();
|
||||
}
|
||||
} else {
|
||||
unsigned long i = 0;
|
||||
char match = 0;
|
||||
char *mime = get_mimetype(&mid_content[selected_file_current]);
|
||||
char *extension = strrchr(mid_content[selected_file_current].file_name, '.');
|
||||
if (extension != NULL) {
|
||||
for (i = 0; i < file_extension_default_count; i++) {
|
||||
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
||||
char *cmd;
|
||||
cmd = parse_cmd(file_extension_default_cmd[i].command, &mid_content[selected_file_current]);
|
||||
printf("\n%s\n",cmd);
|
||||
|
||||
if (system(cmd) == -1) {
|
||||
/*do nothing*/
|
||||
}
|
||||
free(cmd);
|
||||
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
||||
match = 1;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match == 0) {
|
||||
for (i = 0; i < mimetype_default_count; i++) {
|
||||
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||
|
||||
char *cmd = parse_cmd(mimetype_default_cmd[i].command, &mid_content[selected_file_current]);
|
||||
if (system(cmd) == -1) {
|
||||
/*do nothing*/
|
||||
}
|
||||
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
free(mime);
|
||||
}
|
||||
update_selected_file();
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||
TODO;
|
||||
}
|
||||
void toggle_hidden_files(){
|
||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||
status |= (STATUS_RUN_BACKEND | 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);
|
||||
TODO;
|
||||
}
|
||||
void jump_bottom(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
selected_file_current = 0 - 1;
|
||||
update_selected_file();
|
||||
current_dir->selected_file_current = selected_file_current;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||
}
|
||||
void jump_top(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
selected_file_current = 0;
|
||||
update_selected_file();
|
||||
current_dir->selected_file_current = selected_file_current;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
mid_dir.current_file = mid_dir.file_list;
|
||||
}
|
||||
|
||||
void open_with(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
|
||||
char *btm_buffer_tmp = btm_buffer;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
concat(btm_buffer, ui_open_with_text_0, " \'", 0);
|
||||
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);
|
||||
|
||||
|
||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||
memset(str, ' ', INPUT_BUFFER_SIZE);
|
||||
str[INPUT_BUFFER_SIZE-1] = '\0';
|
||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0 , str);
|
||||
|
||||
|
||||
if (err == 0) {
|
||||
char *cmd;
|
||||
concat(cmd, str, " ./\'", 0);
|
||||
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||
concat(cmd, cmd, "\'", 1);
|
||||
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
images_clear();
|
||||
#endif
|
||||
|
||||
endwin();
|
||||
if (system(cmd) == -1) {
|
||||
FAIL("open_with", "creating subcommand failed unhandled");
|
||||
}
|
||||
initscr();
|
||||
}
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
free(btm_buffer);
|
||||
btm_buffer = btm_buffer_tmp;
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
|
||||
free(str);
|
||||
TODO;
|
||||
}
|
||||
|
||||
void rename_hovered(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
char *btm_buffer_tmp = btm_buffer;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
concat(btm_buffer, ui_rename_text_0, " \'", 0);
|
||||
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);
|
||||
|
||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||
memset(str, ' ', INPUT_BUFFER_SIZE);
|
||||
str[INPUT_BUFFER_SIZE-1] = '\0';
|
||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||
|
||||
|
||||
if (!err) {
|
||||
char *cmd;
|
||||
concat(cmd, "mv ./\'", mid_content[selected_file_current].file_name, 0);
|
||||
concat(cmd, cmd, "\' ./\'", 1);
|
||||
concat(cmd, cmd, str, 1);
|
||||
concat(cmd, cmd, "\'", 1);
|
||||
|
||||
if (system(cmd) == -1) {
|
||||
FAIL("rename_hovered", "mv or creating subcommand failed");
|
||||
};
|
||||
btm_buffer = cmd;
|
||||
}
|
||||
free(str);
|
||||
free(btm_buffer);
|
||||
btm_buffer = btm_buffer_tmp;
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
|
||||
TODO;
|
||||
}
|
||||
|
||||
void delete(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
char *btm_buffer_tmp = btm_buffer;
|
||||
|
||||
unsigned int i = 0;
|
||||
unsigned int hits = 0;
|
||||
char *file_str = "";
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
concat(file_str, file_str, "\'", 0);
|
||||
concat(file_str, file_str, mid_content[i].file_name, 1);
|
||||
concat(file_str, file_str, "\' ", 1);
|
||||
hits++;
|
||||
}
|
||||
}
|
||||
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width);
|
||||
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||
memset(btm_buffer, ' ', BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||
|
||||
memcpy(btm_buffer, ui_delete_text ,strlen(ui_delete_text));
|
||||
|
||||
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
|
||||
/*lets hope im never gonna need to format something like this ever again*/
|
||||
memcpy(btm_buffer + strlen(ui_delete_text)+1, file_str,
|
||||
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
|
||||
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
|
||||
strlen(file_str)));
|
||||
|
||||
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width - terminal_width) , "(y/N)", strlen("(y/N)"));
|
||||
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width-1] = '\0';
|
||||
|
||||
|
||||
|
||||
window_btm(win_b, 1);
|
||||
|
||||
timeout(-1); /* negative numbers block until enter is pressed */
|
||||
char ch = wgetch(win_b);
|
||||
|
||||
if (ch == 'y' || ch == 'Y') {
|
||||
if (hits) {
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
recursive_delete(mid_content[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
||||
recursive_delete(mid_content[selected_file_current]);
|
||||
}
|
||||
remove(mid_content[selected_file_current].file_name);
|
||||
|
||||
}
|
||||
}
|
||||
free(btm_buffer);
|
||||
btm_buffer = btm_buffer_tmp;
|
||||
if (hits) {
|
||||
free(file_str);
|
||||
}
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
TODO;
|
||||
}
|
||||
|
||||
void makedir(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
|
||||
char *btm_buffer_tmp = btm_buffer;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
btm_buffer = "create dir: ";
|
||||
|
||||
window_btm(win_b, 1);
|
||||
|
||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||
memset(str, ' ', INPUT_BUFFER_SIZE);
|
||||
str[INPUT_BUFFER_SIZE-1] = '\0';
|
||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||
|
||||
if (!err) {
|
||||
concat(btm_buffer, btm_buffer, str, 0);
|
||||
mode_t mask = umask(0);
|
||||
mkdir(str, 0755); /*magic number from default permissions as created by mkdir*/
|
||||
umask(mask);
|
||||
}
|
||||
free(str);
|
||||
free(btm_buffer);
|
||||
btm_buffer = btm_buffer_tmp;
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
TODO;
|
||||
}
|
||||
void makefile(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
char *btm_buffer_tmp = btm_buffer;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
btm_buffer = "create file: ";
|
||||
|
||||
window_btm(win_b, 1);
|
||||
|
||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||
memset(str, ' ', INPUT_BUFFER_SIZE);
|
||||
str[INPUT_BUFFER_SIZE-1] = '\0';
|
||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||
|
||||
if (!err) {
|
||||
concat(btm_buffer, btm_buffer, str, 0);
|
||||
FILE *fp;
|
||||
fp = fopen(str, "w");
|
||||
fclose(fp);
|
||||
}
|
||||
free(str);
|
||||
free(btm_buffer);
|
||||
btm_buffer = btm_buffer_tmp;
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
}
|
||||
|
||||
void update(){
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
TODO;
|
||||
}
|
||||
void enter_shell(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
images_clear();
|
||||
#endif
|
||||
endwin();
|
||||
if (system(key_binding[index].black_magic) != 0) {
|
||||
/*do nothing*/
|
||||
}
|
||||
initscr();
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
TODO;
|
||||
}
|
||||
void not_implemented(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
@@ -549,63 +236,10 @@ void not_implemented(unsigned long passes, int index){
|
||||
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
|
||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
|
||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
||||
TODO;
|
||||
}
|
||||
void jump_to_dir(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
|
||||
char *ch = (char*)key_binding[index].black_magic;
|
||||
char slash = 0;
|
||||
unsigned int env_len = 0;
|
||||
while (*ch != '\0') {
|
||||
if (*ch == '/') {
|
||||
slash = 1;
|
||||
break;
|
||||
}
|
||||
env_len++;
|
||||
ch++;
|
||||
}
|
||||
char *env_str = NULL;
|
||||
char *env_parsed = NULL;
|
||||
char *path = NULL;
|
||||
ch = (char*)key_binding[index].black_magic;
|
||||
if (*ch == '/') {
|
||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
||||
} else if (slash) {
|
||||
env_str = malloc(env_len * sizeof(char));
|
||||
memcpy(env_str, (char*)key_binding[index].black_magic +1, env_len);
|
||||
env_str[env_len-1] = '\0';
|
||||
env_parsed = getenv(env_str);
|
||||
if (env_parsed) {
|
||||
concat(path, env_parsed, (char*)key_binding[index].black_magic + env_len, 0);
|
||||
} else {
|
||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
||||
}
|
||||
} else {
|
||||
env_parsed = getenv((char*)key_binding[index].black_magic +1);
|
||||
if (env_parsed) {
|
||||
path = malloc(strlen(env_parsed)+1);
|
||||
memcpy(path, env_parsed, strlen(env_parsed)+1);
|
||||
} else {
|
||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
||||
}
|
||||
}
|
||||
if (chdir(path) != 0) {
|
||||
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
|
||||
} else {
|
||||
selected_file_current = dir_get_selected_file_current();
|
||||
}
|
||||
|
||||
/*env_parsed shall not be modified (read: free'd) - the man page*/
|
||||
if (env_str) {
|
||||
free(env_str);
|
||||
}
|
||||
if(path) {
|
||||
free(path);
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
TODO;
|
||||
}
|
||||
void order_by(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
@@ -613,314 +247,29 @@ void order_by(unsigned long passes, int index){
|
||||
seed = time(NULL);
|
||||
|
||||
order_func = key_binding[index].black_magic;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_INTERACTION | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void cmd_on_selected(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
char *btm_buffer_tmp = btm_buffer;
|
||||
btm_buffer = "";
|
||||
unsigned int i = 0;
|
||||
unsigned int hits = 0;
|
||||
char *file_str = "";
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
concat(file_str, file_str, "\'", 0);
|
||||
concat(file_str, file_str, mid_content[i].file_name, 1);
|
||||
concat(file_str, file_str, "\' ", 1);
|
||||
hits++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hits) {
|
||||
concat(btm_buffer, key_binding[index].black_magic, file_str, 2);
|
||||
} else {
|
||||
concat(btm_buffer, key_binding[index].black_magic, "\'", 0);
|
||||
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
||||
concat(btm_buffer, btm_buffer, "\'", 1);
|
||||
}
|
||||
|
||||
concat(btm_buffer, btm_buffer, "?", 1);
|
||||
concat(btm_buffer, btm_buffer, "\n\n", 1);
|
||||
concat(btm_buffer, btm_buffer, "(y/N)", 1);
|
||||
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
window_btm(win_b, 1);
|
||||
|
||||
timeout(-1); /* negative numbers block until enter is pressed */
|
||||
/* TODO(2025-07-06T07:22:49) fix fixed buffer size */
|
||||
char ch = wgetch(win_b);
|
||||
|
||||
if (ch == 'y' || ch == 'Y') {
|
||||
/* the second loop is used to add "./", wich is not being printed" */
|
||||
char *cmd = malloc(sizeof(char));
|
||||
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
||||
endwin();
|
||||
if (hits) {
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
free(cmd);
|
||||
concat(cmd, (char*)key_binding[index].black_magic, " \'", 0);
|
||||
concat(cmd, cmd, mid_content[i].file_name, 1);
|
||||
concat(cmd, cmd, "\'", 1);
|
||||
if (system(cmd) != 0) {
|
||||
/*do nothing*/
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
free(cmd);
|
||||
concat(cmd, (char*)key_binding[index].black_magic, " \'", 0);
|
||||
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||
concat(cmd, cmd, "\'", 1);
|
||||
if (system(cmd) != 0) {
|
||||
/*do nothing*/
|
||||
}
|
||||
mvaddstr(10,10, cmd);
|
||||
|
||||
}
|
||||
/*system(cmd);*/
|
||||
free(cmd);
|
||||
initscr();
|
||||
|
||||
}
|
||||
free(btm_buffer);
|
||||
btm_buffer = btm_buffer_tmp;
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
TODO;
|
||||
}
|
||||
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);
|
||||
concat(cmd, "echo \'", path, 0);
|
||||
concat(cmd, cmd, "/", 1);
|
||||
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||
concat(cmd, cmd, "\' | ", 1);
|
||||
concat(cmd, cmd, clipboard_cmd, 1);
|
||||
free(path);
|
||||
} else {
|
||||
concat(cmd, "echo \'", mid_content[selected_file_current].file_name, 0);
|
||||
concat(cmd, cmd, "\' | ", 1);
|
||||
concat(cmd, cmd, clipboard_cmd, 1);
|
||||
}
|
||||
if (system(cmd) == -1) {
|
||||
/*do nothing*/
|
||||
}
|
||||
free(cmd);
|
||||
TODO;
|
||||
}
|
||||
void yank_file(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
|
||||
unsigned long i;
|
||||
if (yank_files.status & YANK_IS_USED) {
|
||||
for (i = 0; i < yank_files.count; i++) {
|
||||
free(yank_files.list[i]);
|
||||
}
|
||||
free(yank_files.list);
|
||||
free(yank_files.path);
|
||||
yank_files.count = 0;
|
||||
yank_files.status = 0;
|
||||
}
|
||||
yank_files.path=getcwd(NULL, 0);
|
||||
yank_files.count = 0;
|
||||
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
yank_files.count++;
|
||||
}
|
||||
}
|
||||
if (yank_files.count == 0) {
|
||||
yank_files.count = 1;
|
||||
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
|
||||
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
||||
memcpy(*yank_files.list, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)+1);
|
||||
} else {
|
||||
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
||||
memcpy(*yank_files.list, mid_content[i].file_name, strlen(mid_content[i].file_name)+1);
|
||||
yank_files.list += 1;
|
||||
}
|
||||
}
|
||||
yank_files.list -= yank_files.count;
|
||||
}
|
||||
yank_files.status |= YANK_IS_USED;
|
||||
if (strncmp((char*)key_binding[index].black_magic, "cut", 3) == 0) {
|
||||
yank_files.status |= YANK_CUT;
|
||||
yank_files.status &= ~YANK_COPY;
|
||||
} else {
|
||||
yank_files.status |= YANK_COPY;
|
||||
yank_files.status &= ~YANK_CUT;
|
||||
}
|
||||
TODO;
|
||||
}
|
||||
void paste(){
|
||||
unsigned long i;
|
||||
for (i = 0; i < yank_files.count; i++) {
|
||||
char *cmd;
|
||||
if (yank_files.status & YANK_COPY) {
|
||||
concat(cmd, "false | cp -ri \'", yank_files.path, 0);
|
||||
} else {
|
||||
concat(cmd, "mv \'", yank_files.path, 0);
|
||||
}
|
||||
concat(cmd, cmd, "/", 1);
|
||||
concat(cmd, cmd, *yank_files.list, 1);
|
||||
concat(cmd, cmd, "\' ./", 1);
|
||||
concat(cmd, cmd, " 2>&1", 1);
|
||||
char *line = malloc(INPUT_BUFFER_SIZE);
|
||||
FILE *cmd_open;
|
||||
while (1) {
|
||||
cmd_open = popen(cmd, "r");
|
||||
if (fgets(line, INPUT_BUFFER_SIZE, cmd_open) == 0) {
|
||||
break;
|
||||
}
|
||||
if (strstr(line, "are the same file")) {
|
||||
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
||||
concat(cmd, cmd, "_", 1);
|
||||
concat(cmd, cmd, " 2>&1", 1);
|
||||
} else if ((strstr(line, "overwrite"))) {
|
||||
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
||||
concat(cmd, cmd, "_", 1);
|
||||
concat(cmd, cmd, " 2>&1", 1);
|
||||
} else if ((strstr(line, "No such file or directory"))) {
|
||||
pclose(cmd_open);
|
||||
break;
|
||||
} else if ((strstr(line, "into itself"))) {
|
||||
pclose(cmd_open);
|
||||
break;
|
||||
}
|
||||
if (pclose(cmd_open) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(cmd);
|
||||
|
||||
yank_files.list++;
|
||||
}
|
||||
yank_files.list -= yank_files.count;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
TODO;
|
||||
}
|
||||
void search(){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
|
||||
unsigned long local_height;
|
||||
local_height = getmaxy(win_b);
|
||||
memset(search_buffer, '\0', INPUT_BUFFER_SIZE);
|
||||
|
||||
window_btm(win_b, 1);
|
||||
|
||||
curs_set(1);
|
||||
|
||||
timeout(-1); /* negative numbers block until enter is pressed */
|
||||
|
||||
unsigned int pass = 0;
|
||||
char ch;
|
||||
|
||||
wmove(win_b, local_height-1, 1);
|
||||
while(1) {
|
||||
/*ch = mvwgetch(win, y, x + pass);*/
|
||||
werase(win_b);
|
||||
mvwaddch(win_b, local_height-1, 0, '/');
|
||||
mvwaddstr(win_b, local_height-1, 1, search_buffer);
|
||||
ch = wgetch(win_b);
|
||||
if (ch == '\n') {
|
||||
break;
|
||||
} else if (ch == '\t') { /* tab */
|
||||
memcpy(search_buffer, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
||||
mvwaddstr(win_b, local_height-1, pass, mid_content[selected_file_current].file_name);
|
||||
pass = strlen(mid_content[selected_file_current].file_name);
|
||||
} else if (ch == 127) { /* backspace */
|
||||
mvwdelch(win_b, local_height-1, 1);
|
||||
wdelch(win_b);
|
||||
if (pass != 0) {
|
||||
search_buffer[pass-1] = '\0';
|
||||
pass--;
|
||||
}
|
||||
} else if (ch == 27) { /* esc key */
|
||||
break;
|
||||
} else {
|
||||
search_buffer[pass] = ch;
|
||||
pass++;
|
||||
unsigned long i;
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
||||
selected_file_current = i;
|
||||
if (update_selected_file()) {
|
||||
pthread_cond_signal(&cond_rgt);
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
break;
|
||||
}
|
||||
render_pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
search_buffer[pass] = '\0';
|
||||
|
||||
curs_set(0);
|
||||
|
||||
current_dir->selected_file_current = selected_file_current;
|
||||
|
||||
update_selected_file();
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
TODO;
|
||||
}
|
||||
void search_next(){
|
||||
unsigned long i;
|
||||
for (i = selected_file_current+1; i < mid_file_count; i++) {
|
||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
||||
selected_file_current = i;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
update_selected_file();
|
||||
render_pass();
|
||||
break;
|
||||
}
|
||||
}
|
||||
TODO;
|
||||
}
|
||||
void search_previous(){
|
||||
unsigned long i;
|
||||
for (i = selected_file_current-1;; i--) {
|
||||
if(i > selected_file_current) {
|
||||
break;
|
||||
}
|
||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
||||
selected_file_current = i;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
update_selected_file();
|
||||
render_pass();
|
||||
break;
|
||||
}
|
||||
}
|
||||
TODO;
|
||||
}
|
||||
void jmp_file_index(){
|
||||
char *index = malloc(INPUT_BUFFER_SIZE);
|
||||
memset(index, ' ', INPUT_BUFFER_SIZE);
|
||||
index[INPUT_BUFFER_SIZE-1] = '\0';
|
||||
unsigned long local_height;
|
||||
local_height = getmaxy(win_b);
|
||||
read_string(win_b, local_height - 1, 0, index);
|
||||
|
||||
unsigned long new_index = 0;
|
||||
while((*index >= '0') && (*index <= '9')) {
|
||||
new_index = (new_index * 10) + (*index - '0');
|
||||
index++;
|
||||
}
|
||||
if (new_index > mid_file_count) {
|
||||
selected_file_current = mid_file_count;
|
||||
} else {
|
||||
selected_file_current = new_index;
|
||||
}
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||
update_selected_file();
|
||||
TODO;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user