Compare commits
3 Commits
f99035629a
...
c29870998e
Author | SHA1 | Date | |
---|---|---|---|
|
c29870998e | ||
|
3eb1c0f93e | ||
|
e07ec0b413 |
19
config.h
19
config.h
@@ -10,16 +10,19 @@ static mimetype mimetype_default_cmd[] = {
|
||||
|
||||
static binding key_binding[] = {
|
||||
/*key action */
|
||||
{ 'q', quit_program },
|
||||
{ 'h', move_right },
|
||||
{ 't', move_down },
|
||||
{ 'n', move_up },
|
||||
{ 's', move_left },
|
||||
{ "q", quit_program },
|
||||
{ "h", move_right }, /* moves one dir up */
|
||||
{ "t", move_down },
|
||||
{ "n", move_up },
|
||||
{ "s", move_left }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||
|
||||
{ 'g', jump_top },
|
||||
{ 'G', jump_bottom },
|
||||
{ "\n", open_with }, /* opens the hovered file with an arbitrary command */
|
||||
{ "r", rename_hovered }, /* renames currently hovered file/directory */
|
||||
|
||||
{ 'a', toggle_hidden_files },
|
||||
{ "gg", jump_top },
|
||||
{ "G", jump_bottom },
|
||||
|
||||
{ "a", toggle_hidden_files },
|
||||
};
|
||||
static unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
||||
static unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
|
||||
|
@@ -7,6 +7,9 @@
|
||||
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
||||
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
||||
#define STATUS_USER_ROOT 64
|
||||
#define STATUS_INTERACTIONS_MASK 384
|
||||
#define STATUS_INTERACTIONS_OPEN_WITH 128
|
||||
#define STATUS_INTERACTIONS_RENAME 256
|
||||
|
||||
#define SETTINGS_HAS_COLOR 1
|
||||
|
||||
@@ -49,7 +52,6 @@
|
||||
#define FILE_TYPE_ORPHAN COLOR_ORPHAN
|
||||
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
|
||||
|
||||
|
||||
#ifndef STRUCT_GUARD
|
||||
#define STRUCT_GUARD
|
||||
/* complex types are good actually */
|
||||
@@ -70,7 +72,7 @@ typedef struct Mimetype {
|
||||
char *command;
|
||||
} mimetype;
|
||||
typedef struct Binding {
|
||||
char key;
|
||||
char* key;
|
||||
void (*func)();
|
||||
} binding;
|
||||
|
||||
|
129
interactions.c
129
interactions.c
@@ -19,16 +19,28 @@ 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 rename_hovered_pass_2();
|
||||
int read_string(WINDOW *win, int y, int x, char *str);
|
||||
|
||||
void user_interactions(char *input) {
|
||||
void user_interactions(char *input, WINDOW *win_b) {
|
||||
void (*func_ptr)();
|
||||
unsigned long i = 0;
|
||||
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) {
|
||||
if (*input == key_binding[i].key[0]) {
|
||||
func_ptr = key_binding[i].func;
|
||||
func_ptr();
|
||||
}
|
||||
@@ -100,3 +112,116 @@ void jump_top(){
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
|
||||
int read_string(WINDOW *win, int y, int x, char *str){
|
||||
noecho();
|
||||
curs_set(1);
|
||||
|
||||
timeout(-1); /* negative numbers block until enter is pressed */
|
||||
|
||||
unsigned int pass = 0;
|
||||
char ch;
|
||||
char err = 0;
|
||||
|
||||
wmove(win, y, x);
|
||||
while(1) {
|
||||
/*ch = mvwgetch(win, y, x + pass);*/
|
||||
ch = wgetch(win);
|
||||
if (ch == '\n') {
|
||||
err = 0;
|
||||
break;
|
||||
} else if (ch == 27) { /* esc key */
|
||||
err = 1;
|
||||
break;
|
||||
} else if (ch == 127) { /* backspace */
|
||||
if (pass > 0) {
|
||||
pass--;
|
||||
mvwdelch(win, y, pass);
|
||||
}
|
||||
} else {
|
||||
mvwaddch(win, y, x +pass, ch);
|
||||
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_INTERACTIONS_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);
|
||||
|
||||
|
||||
/* TODO(2025-06-22T01:24:36) fix fixed buffer size */
|
||||
char *str = malloc(255);
|
||||
memset(str, ' ', 255);
|
||||
int err = read_string(win_b, local_height - 1, 0 , str);
|
||||
|
||||
|
||||
if (!err) {
|
||||
char *cmd = concat(str, " ./\"");
|
||||
cmd = concat(cmd, file_current.file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
|
||||
system(cmd);
|
||||
|
||||
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(str);
|
||||
}
|
||||
|
||||
void rename_hovered(){
|
||||
|
||||
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(win_b, local_height - 1, 0, 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);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
void user_interactions(char *input);
|
||||
void user_interactions(char *input, WINDOW *win_b);
|
||||
void quit_program();
|
||||
void move_right();
|
||||
void move_up();
|
||||
@@ -15,3 +15,5 @@ void move_left();
|
||||
void jump_bottom();
|
||||
void jump_top();
|
||||
void toggle_hidden_files();
|
||||
void open_with();
|
||||
void rename_hovered();
|
||||
|
22
main.c
22
main.c
@@ -76,7 +76,7 @@ int main(){
|
||||
}
|
||||
}
|
||||
if ((input = getch())) {
|
||||
user_interactions(&input);
|
||||
user_interactions(&input, win_b);
|
||||
timeout_time = 5;
|
||||
} else {
|
||||
timeout_time += 10;
|
||||
@@ -112,7 +112,7 @@ int main(){
|
||||
|
||||
void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WINDOW *win_r){
|
||||
|
||||
if ((status & STATUS_UPDATE_SCREEN_MASK) & STATUS_UPDATE_SCREEN_RESIZE) {
|
||||
if (status & (STATUS_UPDATE_SCREEN_RESIZE | STATUS_INTERACTIONS_MASK)) {
|
||||
if (status & STATUS_UPDATE_SCREEN_RELOAD_FULL) {
|
||||
clear();
|
||||
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
||||
@@ -127,16 +127,25 @@ void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WIN
|
||||
werase(win_r);
|
||||
|
||||
wresize(win_t, 1, terminal_width);
|
||||
wresize(win_b, terminal_height, terminal_width/3);
|
||||
wresize(win_l, terminal_height-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);
|
||||
if(status & STATUS_INTERACTIONS_MASK) {
|
||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||
} else {
|
||||
wresize(win_b, 1, terminal_width);
|
||||
}
|
||||
|
||||
|
||||
mvwin(win_t, 0, 0);
|
||||
mvwin(win_b, terminal_height-1, 0);
|
||||
mvwin(win_l, 1, 0);
|
||||
mvwin(win_m, 1, (terminal_width/8));
|
||||
mvwin(win_r, 1, ((terminal_width/2)));
|
||||
if(status & STATUS_INTERACTIONS_MASK) {
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
} else {
|
||||
mvwin(win_b, terminal_height-1, 0);
|
||||
}
|
||||
|
||||
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
@@ -145,15 +154,15 @@ void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WIN
|
||||
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
||||
status &= ~(STATUS_UPDATE_SCREEN_MASK);
|
||||
window_top(win_t);
|
||||
window_btm(win_b);
|
||||
window_lft(win_l);
|
||||
window_mid(win_m);
|
||||
window_rgt(win_r);
|
||||
window_btm(win_b);
|
||||
wrefresh(win_t);
|
||||
wrefresh(win_b);
|
||||
wrefresh(win_l);
|
||||
wrefresh(win_m);
|
||||
wrefresh(win_r);
|
||||
wrefresh(win_b);
|
||||
}
|
||||
}
|
||||
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
||||
@@ -173,6 +182,7 @@ void init() {
|
||||
|
||||
threading_init(); /* found in threading.c */
|
||||
colors_init();
|
||||
ESCDELAY = 10;
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user