user input now handled through function pointers, now defined in config.h
This commit is contained in:
19
defines.h
19
defines.h
@ -1,7 +1,3 @@
|
|||||||
#ifndef CONFIG_GUARD
|
|
||||||
#define CONFIG_GUARD
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define STATUS_QUIT_PROGRAM 1
|
#define STATUS_QUIT_PROGRAM 1
|
||||||
#define STATUS_RUN_BACKEND 2
|
#define STATUS_RUN_BACKEND 2
|
||||||
@ -52,9 +48,9 @@
|
|||||||
#define FILE_TYPE_ORPHAN COLOR_ORPHAN
|
#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 */
|
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
|
||||||
|
|
||||||
|
|
||||||
#ifndef STRUCT_GUARD
|
#ifndef STRUCT_GUARD
|
||||||
#define STRUCT_GUARD
|
#define STRUCT_GUARD
|
||||||
|
|
||||||
/* complex types are good actually */
|
/* complex types are good actually */
|
||||||
typedef struct File {
|
typedef struct File {
|
||||||
char status;
|
char status;
|
||||||
@ -68,11 +64,14 @@ typedef struct Color {
|
|||||||
char *file_extension;
|
char *file_extension;
|
||||||
short color_pair;
|
short color_pair;
|
||||||
} color;
|
} color;
|
||||||
typedef struct File_preview {
|
typedef struct Mimetype {
|
||||||
char *file_extension;
|
char *mimetype;
|
||||||
char *command; /* this will blindly execute any inserted shell command */
|
char *command;
|
||||||
/* commands with an '&' prefix are inbuild */
|
} mimetype;
|
||||||
} file_preview;
|
typedef struct Binding {
|
||||||
|
char key;
|
||||||
|
void (*func)();
|
||||||
|
} binding;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
@ -13,39 +14,60 @@ extern file *mid_content;
|
|||||||
extern file *lft_content;
|
extern file *lft_content;
|
||||||
extern file *rgt_content;
|
extern file *rgt_content;
|
||||||
|
|
||||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
|
extern unsigned int status;
|
||||||
if (*input == 'q') {
|
|
||||||
*status ^= STATUS_QUIT_PROGRAM;
|
void quit_program(){
|
||||||
} else if (*input == *"KEY_BACKSPACE") {
|
status = STATUS_QUIT_PROGRAM;
|
||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
}
|
||||||
} else if (*input == 'a') {
|
void move_down(){
|
||||||
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);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
/*capping the maximum file is done inside thread_mid */
|
/*capping the maximum file is done inside thread_mid */
|
||||||
selected_file_current++;
|
selected_file_current++;
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
} else if (*input == 'n') {
|
}
|
||||||
|
void move_up(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
if (selected_file_current != 0) {
|
if (selected_file_current != 0) {
|
||||||
selected_file_current--;
|
selected_file_current--;
|
||||||
}
|
}
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
} else if (*input == 's') {
|
}
|
||||||
|
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);
|
chdir(mid_content[selected_file_current].file_name);
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
} else {
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#ifndef CONFIG_GUARD
|
||||||
|
#define CONFIG_GUARD
|
||||||
#include "interactions.c"
|
#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();
|
||||||
|
6
main.c
6
main.c
@ -6,9 +6,9 @@
|
|||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "interactions.h"
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
|
#include "interactions.h"
|
||||||
|
|
||||||
unsigned int terminal_height;
|
unsigned int terminal_height;
|
||||||
unsigned int terminal_width;
|
unsigned int terminal_width;
|
||||||
@ -54,11 +54,13 @@ int main() {
|
|||||||
}
|
}
|
||||||
if (status & STATUS_RUN_BACKEND || threading) {
|
if (status & STATUS_RUN_BACKEND || threading) {
|
||||||
if (threading) {
|
if (threading) {
|
||||||
|
/* temporary comment, somehow stops timing related crashes
|
||||||
pthread_cancel(thread_t);
|
pthread_cancel(thread_t);
|
||||||
pthread_cancel(thread_b);
|
pthread_cancel(thread_b);
|
||||||
pthread_cancel(thread_l);
|
pthread_cancel(thread_l);
|
||||||
pthread_cancel(thread_m);
|
pthread_cancel(thread_m);
|
||||||
pthread_cancel(thread_r);
|
pthread_cancel(thread_r);
|
||||||
|
*/
|
||||||
threading = 0;
|
threading = 0;
|
||||||
status &= ~STATUS_RUN_BACKEND;
|
status &= ~STATUS_RUN_BACKEND;
|
||||||
status &= ~STATUS_RELOAD_DIRECTORY;
|
status &= ~STATUS_RELOAD_DIRECTORY;
|
||||||
@ -73,7 +75,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((input = getch())) {
|
if ((input = getch())) {
|
||||||
user_interactions(&input, &status, &settings);
|
user_interactions(&input);
|
||||||
timeout_time = 5;
|
timeout_time = 5;
|
||||||
} else {
|
} else {
|
||||||
timeout_time += 10;
|
timeout_time += 10;
|
||||||
|
@ -29,7 +29,6 @@ unsigned long mid_file_count;
|
|||||||
unsigned long lft_file_count;
|
unsigned long lft_file_count;
|
||||||
unsigned long top_width;
|
unsigned long top_width;
|
||||||
|
|
||||||
extern file_preview file_previews[];
|
|
||||||
|
|
||||||
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
|
Reference in New Issue
Block a user