implemented open_with
This commit is contained in:
17
config.h
17
config.h
@ -10,16 +10,17 @@ 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 */
|
||||
{ "\n", open_with }, /* enter/return/new line/whatever you call it */
|
||||
|
||||
{ 'g', jump_top },
|
||||
{ 'G', jump_bottom },
|
||||
{ "gg", jump_top },
|
||||
{ "G", jump_bottom },
|
||||
|
||||
{ 'a', toggle_hidden_files },
|
||||
{ "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,7 @@
|
||||
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
||||
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
||||
#define STATUS_USER_ROOT 64
|
||||
#define STATUS_OPEN_WITH 128
|
||||
|
||||
#define SETTINGS_HAS_COLOR 1
|
||||
|
||||
@ -49,7 +50,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 +70,7 @@ typedef struct Mimetype {
|
||||
char *command;
|
||||
} mimetype;
|
||||
typedef struct Binding {
|
||||
char key;
|
||||
char* key;
|
||||
void (*func)();
|
||||
} binding;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,4 @@ void move_left();
|
||||
void jump_bottom();
|
||||
void jump_top();
|
||||
void toggle_hidden_files();
|
||||
void open_with();
|
||||
|
21
main.c
21
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_OPEN_WITH)) {
|
||||
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_OPEN_WITH) {
|
||||
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_OPEN_WITH) {
|
||||
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)*/
|
||||
|
Reference in New Issue
Block a user