diff --git a/defines.h b/defines.h index 5bc867f..1fc00cb 100644 --- a/defines.h +++ b/defines.h @@ -1,7 +1,3 @@ -#ifndef CONFIG_GUARD -#define CONFIG_GUARD -#include "config.h" -#endif #define STATUS_QUIT_PROGRAM 1 #define STATUS_RUN_BACKEND 2 @@ -52,9 +48,9 @@ #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 */ typedef struct File { char status; @@ -68,11 +64,14 @@ typedef struct Color { char *file_extension; short color_pair; } color; -typedef struct File_preview { - char *file_extension; - char *command; /* this will blindly execute any inserted shell command */ - /* commands with an '&' prefix are inbuild */ -} file_preview; +typedef struct Mimetype { + char *mimetype; + char *command; +} mimetype; +typedef struct Binding { + char key; + void (*func)(); +} binding; #endif diff --git a/interactions.c b/interactions.c index 0d4e886..b61f1ba 100644 --- a/interactions.c +++ b/interactions.c @@ -3,6 +3,7 @@ #include #include #include "defines.h" +#include "config.h" extern unsigned int file_modifiers; @@ -13,39 +14,60 @@ extern file *mid_content; extern file *lft_content; extern file *rgt_content; -void user_interactions(char *input, unsigned int *status, unsigned int *settings) { - if (*input == 'q') { - *status ^= STATUS_QUIT_PROGRAM; - } else if (*input == *"KEY_BACKSPACE") { - file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES; - } else if (*input == 'a') { - file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES; - *status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); - } else if (*input == 'o') { - file_modifiers ^= FILE_MODIFIERS_SORT_BITMASK; - } else if (*input == 'e') { - file_modifiers ^= FILE_MODIFIERS_SORT_ALPHABETIC; - } else if (*input == 'u') { - *status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); - } else if (*input == 'h') { - chdir(".."); - *status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); - } else if (*input == 't') { - pthread_mutex_lock(&mutex_selection); - /* capping the maximum file is done inside thread_mid */ - selected_file_current++; - *status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); - pthread_mutex_unlock(&mutex_selection); - } else if (*input == 'n') { - pthread_mutex_lock(&mutex_selection); - if (selected_file_current != 0) { - selected_file_current--; +extern unsigned int status; + +void quit_program(){ + status = STATUS_QUIT_PROGRAM; +} +void move_down(){ + pthread_mutex_lock(&mutex_selection); + /*capping the maximum file is done inside thread_mid */ + selected_file_current++; + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); + pthread_mutex_unlock(&mutex_selection); +} +void move_up(){ + pthread_mutex_lock(&mutex_selection); + if (selected_file_current != 0) { + selected_file_current--; + } + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); + pthread_mutex_unlock(&mutex_selection); +} +void move_right(){ + chdir(".."); + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); +} +void move_left(){ + chdir(mid_content[selected_file_current].file_name); + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); +} +void toggle_hidden_files(){ + file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES; + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); +} +void jump_bottom(){ + pthread_mutex_lock(&mutex_selection); + selected_file_current = 0 - 1; + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); + pthread_mutex_unlock(&mutex_selection); +} +void jump_top(){ + pthread_mutex_lock(&mutex_selection); + selected_file_current = 0; + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); + pthread_mutex_unlock(&mutex_selection); +} + + + +void user_interactions(char *input) { + void (*func_ptr)(); + unsigned long i = 0; + for (i = 0; i < binding_count; i++) { + if (*input == key_binding[i].key) { + func_ptr = key_binding[i].func; + func_ptr(); } - *status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); - pthread_mutex_unlock(&mutex_selection); - } else if (*input == 's') { - chdir(mid_content[selected_file_current].file_name); - *status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); - } else { } } diff --git a/interactions.h b/interactions.h index d4b0516..fb86a45 100644 --- a/interactions.h +++ b/interactions.h @@ -1,5 +1,17 @@ #include #include +#ifndef CONFIG_GUARD +#define CONFIG_GUARD #include "interactions.c" +#endif -void user_interactions(char *input, unsigned int *status, unsigned int *settings); + +void user_interactions(char *input); +void quit_program(); +void move_right(); +void move_up(); +void move_down(); +void move_left(); +void jump_bottom(); +void jump_top(); +void toggle_hidden_files(); diff --git a/main.c b/main.c index b4ba36e..3cff721 100644 --- a/main.c +++ b/main.c @@ -6,9 +6,9 @@ #include #include "threading.h" #include "window.h" -#include "interactions.h" #include "defines.h" #include "colors.h" +#include "interactions.h" unsigned int terminal_height; unsigned int terminal_width; @@ -24,7 +24,7 @@ void render_pass(WINDOW *wint, WINDOW *winb, WINDOW *winl, WINDOW *winm, WINDOW void init(); -int main() { +int main(){ init(); @@ -54,11 +54,13 @@ int main() { } if (status & STATUS_RUN_BACKEND || threading) { if (threading) { + /* temporary comment, somehow stops timing related crashes pthread_cancel(thread_t); pthread_cancel(thread_b); pthread_cancel(thread_l); pthread_cancel(thread_m); pthread_cancel(thread_r); + */ threading = 0; status &= ~STATUS_RUN_BACKEND; status &= ~STATUS_RELOAD_DIRECTORY; @@ -73,7 +75,7 @@ int main() { } } if ((input = getch())) { - user_interactions(&input, &status, &settings); + user_interactions(&input); timeout_time = 5; } else { timeout_time += 10; diff --git a/threading.c b/threading.c index 846a87d..31c0c57 100644 --- a/threading.c +++ b/threading.c @@ -29,7 +29,6 @@ unsigned long mid_file_count; unsigned long lft_file_count; unsigned long top_width; -extern file_preview file_previews[]; extern unsigned int status;