extensionsto key_binding

This commit is contained in:
nova
2025-07-06 13:21:04 +02:00
parent 05ba7c82a0
commit 47470e4e64
4 changed files with 129 additions and 45 deletions

View File

@ -2,6 +2,7 @@
#include <pthread.h>
#include <dirent.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
@ -37,6 +38,7 @@ extern char *input;
unsigned int input_pass;
int parsed_input_number;
extern char *terminal_width_empty_line;
extern char *start_path;
int read_string(WINDOW *win, int y, int x, char *str);
int strcmp_offset(char *in0, char *in1, char offset);
@ -461,22 +463,99 @@ void makefile(){
void update(){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
}
void not_implemented(){
mvaddstr(terminal_height-1, 0, input);
mvaddstr(terminal_height-1, strlen(input), "\t");
mvaddstr(terminal_height-1, strlen(input) + strlen("\t"), "is not yet implemented");
void not_implemented(int passes, int index){
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
}
void jump_to_dir(int passes, int index){
if (strcmp((char*)key_binding[index].black_magic, "~/") || strcmp((char*)key_binding[index].black_magic, "$HOME")) {
chdir(getenv("HOME"));
if ((char*)key_binding[index].black_magic) {
chdir(getenv((char*)key_binding[index].black_magic+1));
} else {
chdir((char*)key_binding[index].black_magic);
}
/* for some reason putting this in a else does not work */
chdir((char*)key_binding[index].black_magic);
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);
}
void order_by(int passes, int index){
order_func = key_binding[index].black_magic;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void cmd_on_selected(int passes, int index){
unsigned int i = 0;
unsigned int hits = 0;
char *file_str = " ";
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
file_str = concat(file_str, "\"");
file_str = concat(file_str, mid_content[i].file_name);
file_str = concat(file_str, "\" ");
hits++;
}
}
if (hits) {
btm_buffer = concat(key_binding[index].black_magic, file_str);
} else {
btm_buffer = concat(key_binding[index].black_magic, "\"");
btm_buffer = concat(btm_buffer, file_current->file_name);
btm_buffer = concat(btm_buffer, "\"");
}
btm_buffer = concat(btm_buffer, "?");
btm_buffer = concat(btm_buffer, "\n\n");
btm_buffer = concat(btm_buffer, "(y/N)");
status = STATUS_UPDATE_SCREEN_0;
werase(win_b);
mvwin(win_b, terminal_height-6, 0);
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
render_pass();
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;
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
if (hits) {
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
cmd = concat((char*)key_binding[index].black_magic, " \"");
cmd = concat(cmd, mid_content[i].file_name);
cmd = concat(cmd, "\"");
system(cmd);
free(cmd);
}
}
free(btm_buffer);
btm_buffer = concat("completed: ", key_binding[index].black_magic);
} else {
free(btm_buffer);
cmd = concat((char*)key_binding[index].black_magic, " \"");
cmd = concat(cmd, file_current->file_name);
cmd = concat(cmd, "\"");
system(cmd);
mvaddstr(10,10, cmd);
}
/*system(cmd);*/
free(cmd);
} else {
free(btm_buffer);
btm_buffer = "cancled deletion";
}
timeout(10);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
if (hits) {
free(file_str);
}
}