implemented rename_hovered, custom input string loop
This commit is contained in:
112
interactions.c
112
interactions.c
@ -25,12 +25,19 @@ extern char *btm_buffer;
|
||||
|
||||
extern unsigned int status;
|
||||
void open_with_pass_2();
|
||||
void rename_hovered_pass_2();
|
||||
int read_string(char *str);
|
||||
|
||||
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);
|
||||
if (status & STATUS_INTERACTIONS_MASK) {
|
||||
if (status & STATUS_INTERACTIONS_OPEN_WITH) {
|
||||
open_with_pass_2(win_b);
|
||||
} else if (status & STATUS_INTERACTIONS_RENAME) {
|
||||
rename_hovered_pass_2(win_b);
|
||||
}
|
||||
|
||||
}
|
||||
for (i = 0; i < binding_count; i++) {
|
||||
if (*input == key_binding[i].key[0]) {
|
||||
@ -105,11 +112,39 @@ void jump_top(){
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
|
||||
void open_with(){
|
||||
int read_string(char *str){
|
||||
echo();
|
||||
curs_set(1);
|
||||
|
||||
timeout(-1); /* negative numbers block until enter is pressed */
|
||||
|
||||
unsigned int pass = 0;
|
||||
char ch;
|
||||
char err = 0;
|
||||
while(1) {
|
||||
ch = getch();
|
||||
if (ch == '\n') {
|
||||
err = 0;
|
||||
break;
|
||||
} else if (ch == 27) { /* esc key */
|
||||
err = 1;
|
||||
break;
|
||||
}
|
||||
str[pass] = ch;
|
||||
pass++;
|
||||
}
|
||||
str[pass] = '\0';
|
||||
|
||||
timeout(10);
|
||||
noecho();
|
||||
curs_set(0);
|
||||
|
||||
return err;
|
||||
}
|
||||
void open_with(){
|
||||
btm_buffer = concat("open \"", file_current.file_name);
|
||||
btm_buffer = concat(btm_buffer, "\" with:");
|
||||
status |= (STATUS_UPDATE_SCREEN_0 | STATUS_OPEN_WITH);
|
||||
status |= (STATUS_UPDATE_SCREEN_0 | STATUS_INTERACTIONS_OPEN_WITH);
|
||||
|
||||
}
|
||||
void open_with_pass_2(WINDOW *win_b){
|
||||
@ -118,28 +153,65 @@ void open_with_pass_2(WINDOW *win_b){
|
||||
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);
|
||||
/* TODO(2025-06-22T01:24:36) fix fixed buffer size */
|
||||
char *str = malloc(255);
|
||||
memset(str, ' ', 255);
|
||||
int err = read_string(str);
|
||||
|
||||
|
||||
char *cmd = concat(str, " ./\"");
|
||||
cmd = concat(cmd, file_current.file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
if (!err) {
|
||||
char *cmd = concat(str, " ./\"");
|
||||
cmd = concat(cmd, file_current.file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
|
||||
system(cmd);
|
||||
system(cmd);
|
||||
|
||||
noecho();
|
||||
curs_set(0);
|
||||
status &= ~(STATUS_OPEN_WITH);
|
||||
free(btm_buffer);
|
||||
btm_buffer = cmd;
|
||||
|
||||
}
|
||||
|
||||
status &= ~(STATUS_INTERACTIONS_MASK);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
free(btm_buffer);
|
||||
btm_buffer = cmd;
|
||||
|
||||
free(str);
|
||||
}
|
||||
|
||||
void rename_hovered(WINDOW *win_b){
|
||||
|
||||
btm_buffer = concat("rename \"", file_current.file_name);
|
||||
btm_buffer = concat(btm_buffer, "\" to:");
|
||||
status |= (STATUS_UPDATE_SCREEN_0 | STATUS_INTERACTIONS_RENAME);
|
||||
|
||||
}
|
||||
|
||||
void rename_hovered_pass_2(WINDOW *win_b){
|
||||
|
||||
unsigned long local_width;
|
||||
unsigned long local_height;
|
||||
getmaxyx(win_b, local_height, local_width);
|
||||
|
||||
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
||||
char *str = malloc(255);
|
||||
memset(str, ' ', 255);
|
||||
int err = read_string(str);
|
||||
|
||||
|
||||
if (!err) {
|
||||
char *cmd = concat("mv ./\"", file_current.file_name);
|
||||
cmd = concat(cmd, "\" ./\"");
|
||||
cmd = concat(cmd, str);
|
||||
cmd = concat(cmd, "\"");
|
||||
|
||||
system(cmd);
|
||||
btm_buffer = cmd;
|
||||
}
|
||||
|
||||
status &= ~(STATUS_INTERACTIONS_MASK);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
free(btm_buffer);
|
||||
|
||||
free(str);
|
||||
}
|
||||
|
Reference in New Issue
Block a user