implemented open_with

This commit is contained in:
nova
2025-06-21 23:48:56 +02:00
parent f99035629a
commit e07ec0b413
5 changed files with 73 additions and 19 deletions

View File

@ -19,16 +19,21 @@ extern file *lft_content;
extern file *rgt_content;
extern file file_current;
extern char *rgt_buffer;
extern char *btm_buffer;
extern unsigned int status;
void open_with_pass_2();
void user_interactions(char *input) {
void user_interactions(char *input, WINDOW *win_b) {
void (*func_ptr)();
unsigned long i = 0;
if (status & STATUS_OPEN_WITH) {
open_with_pass_2(win_b);
}
for (i = 0; i < binding_count; i++) {
if (*input == key_binding[i].key) {
if (*input == key_binding[i].key[0]) {
func_ptr = key_binding[i].func;
func_ptr();
}
@ -100,3 +105,41 @@ void jump_top(){
pthread_mutex_unlock(&mutex_selection);
}
void open_with(){
echo();
btm_buffer = concat("open \"", file_current.file_name);
btm_buffer = concat(btm_buffer, "\" with:");
status |= (STATUS_UPDATE_SCREEN_0 | STATUS_OPEN_WITH);
}
void open_with_pass_2(WINDOW *win_b){
unsigned long local_width;
unsigned long local_height;
getmaxyx(win_b, local_height, local_width);
echo();
curs_set(1);
char *str = malloc(50);
timeout(-1); /* negative numbers block until enter is pressed */
mvwgetstr(win_b, local_height-1, 0, str);
timeout(10);
char *cmd = concat(str, " ./\"");
cmd = concat(cmd, file_current.file_name);
cmd = concat(cmd, "\"");
system(cmd);
noecho();
curs_set(0);
status &= ~(STATUS_OPEN_WITH);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
free(btm_buffer);
btm_buffer = cmd;
free(str);
}