implemented rename_hovered, custom input string loop
This commit is contained in:
4
config.h
4
config.h
@ -15,7 +15,9 @@ static binding key_binding[] = {
|
|||||||
{ "t", move_down },
|
{ "t", move_down },
|
||||||
{ "n", move_up },
|
{ "n", move_up },
|
||||||
{ "s", move_left }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
{ "s", move_left }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||||
{ "\n", open_with }, /* enter/return/new line/whatever you call it */
|
|
||||||
|
{ "\n", open_with }, /* opens the hovered file with an arbitrary command */
|
||||||
|
{ "r", rename_hovered }, /* renames currently hovered file/directory */
|
||||||
|
|
||||||
{ "gg", jump_top },
|
{ "gg", jump_top },
|
||||||
{ "G", jump_bottom },
|
{ "G", jump_bottom },
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
||||||
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
||||||
#define STATUS_USER_ROOT 64
|
#define STATUS_USER_ROOT 64
|
||||||
#define STATUS_OPEN_WITH 128
|
#define STATUS_INTERACTIONS_MASK 384
|
||||||
|
#define STATUS_INTERACTIONS_OPEN_WITH 128
|
||||||
|
#define STATUS_INTERACTIONS_RENAME 256
|
||||||
|
|
||||||
#define SETTINGS_HAS_COLOR 1
|
#define SETTINGS_HAS_COLOR 1
|
||||||
|
|
||||||
|
100
interactions.c
100
interactions.c
@ -25,12 +25,19 @@ extern char *btm_buffer;
|
|||||||
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
void open_with_pass_2();
|
void open_with_pass_2();
|
||||||
|
void rename_hovered_pass_2();
|
||||||
|
int read_string(char *str);
|
||||||
|
|
||||||
void user_interactions(char *input, WINDOW *win_b) {
|
void user_interactions(char *input, WINDOW *win_b) {
|
||||||
void (*func_ptr)();
|
void (*func_ptr)();
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
if (status & STATUS_OPEN_WITH) {
|
if (status & STATUS_INTERACTIONS_MASK) {
|
||||||
|
if (status & STATUS_INTERACTIONS_OPEN_WITH) {
|
||||||
open_with_pass_2(win_b);
|
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++) {
|
for (i = 0; i < binding_count; i++) {
|
||||||
if (*input == key_binding[i].key[0]) {
|
if (*input == key_binding[i].key[0]) {
|
||||||
@ -105,11 +112,39 @@ void jump_top(){
|
|||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_with(){
|
int read_string(char *str){
|
||||||
echo();
|
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("open \"", file_current.file_name);
|
||||||
btm_buffer = concat(btm_buffer, "\" with:");
|
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){
|
void open_with_pass_2(WINDOW *win_b){
|
||||||
@ -118,28 +153,65 @@ void open_with_pass_2(WINDOW *win_b){
|
|||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
getmaxyx(win_b, local_height, local_width);
|
getmaxyx(win_b, local_height, local_width);
|
||||||
|
|
||||||
echo();
|
|
||||||
curs_set(1);
|
|
||||||
|
|
||||||
char *str = malloc(50);
|
/* TODO(2025-06-22T01:24:36) fix fixed buffer size */
|
||||||
timeout(-1); /* negative numbers block until enter is pressed */
|
char *str = malloc(255);
|
||||||
mvwgetstr(win_b, local_height-1, 0, str);
|
memset(str, ' ', 255);
|
||||||
timeout(10);
|
int err = read_string(str);
|
||||||
|
|
||||||
|
|
||||||
|
if (!err) {
|
||||||
char *cmd = concat(str, " ./\"");
|
char *cmd = concat(str, " ./\"");
|
||||||
cmd = concat(cmd, file_current.file_name);
|
cmd = concat(cmd, file_current.file_name);
|
||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, "\"");
|
||||||
|
|
||||||
system(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);
|
free(btm_buffer);
|
||||||
btm_buffer = 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(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);
|
free(str);
|
||||||
}
|
}
|
||||||
|
@ -16,3 +16,4 @@ void jump_bottom();
|
|||||||
void jump_top();
|
void jump_top();
|
||||||
void toggle_hidden_files();
|
void toggle_hidden_files();
|
||||||
void open_with();
|
void open_with();
|
||||||
|
void rename_hovered();
|
||||||
|
7
main.c
7
main.c
@ -112,7 +112,7 @@ int main(){
|
|||||||
|
|
||||||
void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WINDOW *win_r){
|
void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WINDOW *win_r){
|
||||||
|
|
||||||
if (status & (STATUS_UPDATE_SCREEN_RESIZE | STATUS_OPEN_WITH)) {
|
if (status & (STATUS_UPDATE_SCREEN_RESIZE | STATUS_INTERACTIONS_MASK)) {
|
||||||
if (status & STATUS_UPDATE_SCREEN_RELOAD_FULL) {
|
if (status & STATUS_UPDATE_SCREEN_RELOAD_FULL) {
|
||||||
clear();
|
clear();
|
||||||
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
||||||
@ -130,7 +130,7 @@ void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WIN
|
|||||||
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));
|
||||||
wresize(win_r, terminal_height-2, terminal_width/2);
|
wresize(win_r, terminal_height-2, terminal_width/2);
|
||||||
if(status & STATUS_OPEN_WITH) {
|
if(status & STATUS_INTERACTIONS_MASK) {
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
} else {
|
} else {
|
||||||
wresize(win_b, 1, terminal_width);
|
wresize(win_b, 1, terminal_width);
|
||||||
@ -141,7 +141,7 @@ void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WIN
|
|||||||
mvwin(win_l, 1, 0);
|
mvwin(win_l, 1, 0);
|
||||||
mvwin(win_m, 1, (terminal_width/8));
|
mvwin(win_m, 1, (terminal_width/8));
|
||||||
mvwin(win_r, 1, ((terminal_width/2)));
|
mvwin(win_r, 1, ((terminal_width/2)));
|
||||||
if(status & STATUS_OPEN_WITH) {
|
if(status & STATUS_INTERACTIONS_MASK) {
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
} else {
|
} else {
|
||||||
mvwin(win_b, terminal_height-1, 0);
|
mvwin(win_b, terminal_height-1, 0);
|
||||||
@ -182,6 +182,7 @@ void init() {
|
|||||||
|
|
||||||
threading_init(); /* found in threading.c */
|
threading_init(); /* found in threading.c */
|
||||||
colors_init();
|
colors_init();
|
||||||
|
ESCDELAY = 10;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user