added blackmagic (funcptr/string modifiers on actions)
This commit is contained in:
@ -14,6 +14,8 @@ extern unsigned int file_modifiers;
|
|||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
unsigned long file_offset;
|
unsigned long file_offset;
|
||||||
|
int (*order_func)() = sort_natural;
|
||||||
|
|
||||||
|
|
||||||
char* concat(const char *s1, const char *s2){
|
char* concat(const char *s1, const char *s2){
|
||||||
const size_t len1 = strlen(s1);
|
const size_t len1 = strlen(s1);
|
||||||
@ -128,7 +130,8 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
free(file);
|
free(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qsort(dir_content, *dir_file_count, sizeof(file), sort_natural);
|
|
||||||
|
qsort(dir_content, *dir_file_count, sizeof(file), order_func);
|
||||||
|
|
||||||
for (i = 0; i < *dir_file_count; i++) {
|
for (i = 0; i < *dir_file_count; i++) {
|
||||||
free(entry[i]);
|
free(entry[i]);
|
||||||
|
75
config.h
75
config.h
@ -1,5 +1,6 @@
|
|||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "interactions.h"
|
#include "interactions.h"
|
||||||
|
#include "sorting.h"
|
||||||
|
|
||||||
static mimetype mimetype_default_cmd[] = {
|
static mimetype mimetype_default_cmd[] = {
|
||||||
/* mimetype shell command
|
/* mimetype shell command
|
||||||
@ -17,54 +18,56 @@ static mimetype mimetype_default_cmd[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static binding key_binding[] = {
|
static binding key_binding[] = {
|
||||||
/*key action comment*/
|
/*key action blackmagic comment*/
|
||||||
/*you cannot add bindings that include other bindings in its entirety
|
/*you cannot add bindings that include other bindings in its entirety
|
||||||
* possible: mk, mf
|
* possible: mk, mf
|
||||||
* not possible: gg, ggg
|
* not possible: gg, ggg
|
||||||
* trying to use ggg will always fail as it will execute gg first instead, resetting the input buffer, thus never reaching ggg */
|
* trying to use ggg will always fail as it will execute gg first instead, resetting the input buffer, thus never reaching ggg */
|
||||||
{ "q", quit_program, "quit" },
|
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
|
||||||
{ " ", toggle_selection, "toggle file selection" }, /* on hovered file/directory */
|
{ "q", quit_program, NULL, "quit" },
|
||||||
{ "e", update, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
||||||
{ "/", not_implemented, "search" },
|
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||||
|
{ "/", not_implemented, NULL, "search" },
|
||||||
|
|
||||||
{ "h", move_right, "move right" }, /* moves one dir up */
|
{ "h", move_right, NULL, "move right" }, /* moves one dir up */
|
||||||
{ "t", move_down, "move down" },
|
{ "t", move_down, NULL, "move down" },
|
||||||
{ "n", move_up, "move up" },
|
{ "n", move_up, NULL ,"move up" },
|
||||||
{ "s", move_left, "move left" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
{ "s", move_left, NULL, "move left" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||||
|
|
||||||
{ "\n", open_with, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
|
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
|
||||||
{ "r", rename_hovered, "rename hovered file" }, /* renames currently hovered file/directory */
|
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||||
{ "d", delete, "delete file" }, /* deletes currently hovered OR selected file/directory
|
{ "d", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
||||||
* this means that it does not delete the hovered files if files are already selected */
|
* this means that it does not delete the hovered files if files are already selected */
|
||||||
|
|
||||||
{ "G", jump_bottom, "jump to last file in dir" },
|
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
||||||
{ "gg", jump_top, "jump to file 0" },
|
{ "gg", jump_top, NULL, "jump to file 0" },
|
||||||
{ "gh", not_implemented, "jump to ~/" },
|
{ "gh", jump_to_dir, "~/", "jump to ~/" },
|
||||||
{ "gd", not_implemented, "jump to /dev" },
|
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
||||||
{ "ge", not_implemented, "jump to /etc" },
|
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
||||||
{ "gm", not_implemented, "jump to /mnt" },
|
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
|
||||||
{ "go", not_implemented, "jump to /opt" },
|
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
||||||
{ "gt", not_implemented, "jump to /tmp" },
|
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
||||||
{ "gv", not_implemented, "jump to /var" },
|
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
||||||
|
|
||||||
{ "u7", not_implemented, "unzip 7z" },
|
{ "u7", not_implemented, "", "unzip 7z" },
|
||||||
{ "ub", not_implemented, "unzip bz2" },
|
{ "ub", not_implemented, "", "unzip bz2" },
|
||||||
{ "ur", not_implemented, "unzip rar" },
|
{ "ur", not_implemented, "", "unzip rar" },
|
||||||
{ "ut", not_implemented, "unzip tar" },
|
{ "ut", not_implemented, "", "unzip tar" },
|
||||||
{ "ut", not_implemented, "unzip gzip" },
|
{ "ut", not_implemented, "", "unzip gzip" },
|
||||||
{ "uz", not_implemented, "unzip zip" },
|
{ "uz", not_implemented, "", "unzip zip" },
|
||||||
|
|
||||||
{ "on", not_implemented, "order natural" },
|
{ "on", order_by, sort_natural, "order natural" },
|
||||||
{ "or", not_implemented, "order reverse" },
|
{ "or", not_implemented, "", "order reverse" },
|
||||||
{ "oe", not_implemented, "order extension" },
|
{ "oe", not_implemented, "", "order extension" },
|
||||||
{ "os", not_implemented, "order size" },
|
{ "os", not_implemented, "", "order size" },
|
||||||
{ "ot", not_implemented, "order type" },
|
{ "ot", not_implemented, "", "order type" },
|
||||||
{ "oz", not_implemented, "order random" },
|
{ "oz", not_implemented, "", "order random" },
|
||||||
|
{ "oa", order_by, sort_alpha, "order random" },
|
||||||
|
|
||||||
{ "mk", makedir, "create directory" },
|
{ "mk", makedir, NULL, "create directory" },
|
||||||
{ "mf", makefile, "create file" },
|
{ "mf", makefile, NULL, "create file" },
|
||||||
|
|
||||||
{ "a", toggle_hidden_files, "toggle hidden files" },
|
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
|
||||||
};
|
};
|
||||||
static unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
static unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
||||||
static unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
|
static unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
|
||||||
|
@ -73,6 +73,7 @@ typedef struct Mimetype {
|
|||||||
typedef struct Binding {
|
typedef struct Binding {
|
||||||
char* key;
|
char* key;
|
||||||
void (*func)();
|
void (*func)();
|
||||||
|
void* black_magic;
|
||||||
char* comment;
|
char* comment;
|
||||||
} binding;
|
} binding;
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ extern char *terminal_width_empty_line;
|
|||||||
int read_string(WINDOW *win, int y, int x, char *str);
|
int read_string(WINDOW *win, int y, int x, char *str);
|
||||||
int strcmp_offset(char *in0, char *in1, char offset);
|
int strcmp_offset(char *in0, char *in1, char offset);
|
||||||
extern void render_pass();
|
extern void render_pass();
|
||||||
|
extern int (*order_func)();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void user_interactions() {
|
void user_interactions() {
|
||||||
@ -74,7 +76,7 @@ void user_interactions() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void (*func_ptr)(int);
|
void (*func_ptr)(int, int);
|
||||||
int number_length = 0;
|
int number_length = 0;
|
||||||
if (!binding_pass) {
|
if (!binding_pass) {
|
||||||
parsed_input_number = 0;
|
parsed_input_number = 0;
|
||||||
@ -95,7 +97,7 @@ void user_interactions() {
|
|||||||
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
||||||
|
|
||||||
func_ptr = key_binding[i].func;
|
func_ptr = key_binding[i].func;
|
||||||
func_ptr(parsed_input_number);
|
func_ptr(parsed_input_number, i);
|
||||||
|
|
||||||
memset(input, 0, 255);
|
memset(input, 0, 255);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
@ -464,3 +466,17 @@ void not_implemented(){
|
|||||||
mvaddstr(terminal_height-1, strlen(input), "\t");
|
mvaddstr(terminal_height-1, strlen(input), "\t");
|
||||||
mvaddstr(terminal_height-1, strlen(input) + strlen("\t"), "is not yet implemented");
|
mvaddstr(terminal_height-1, strlen(input) + strlen("\t"), "is not yet implemented");
|
||||||
}
|
}
|
||||||
|
void jump_to_dir(int passes, int index){
|
||||||
|
if (strcmp((char*)key_binding[index].black_magic, "~/") || strcmp((char*)key_binding[index].black_magic, "$HOME")) {
|
||||||
|
chdir(getenv("HOME"));
|
||||||
|
}
|
||||||
|
/* for some reason putting this in a else does not work */
|
||||||
|
chdir((char*)key_binding[index].black_magic);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
}
|
||||||
|
void order_by(int passes, int index){
|
||||||
|
|
||||||
|
order_func = key_binding[index].black_magic;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
|
}
|
||||||
|
@ -23,3 +23,5 @@ void makedir();
|
|||||||
void makefile();
|
void makefile();
|
||||||
void update();
|
void update();
|
||||||
void not_implemented();
|
void not_implemented();
|
||||||
|
void jump_to_dir(int passes, int index);
|
||||||
|
void order_by(int passes, int index);
|
||||||
|
Reference in New Issue
Block a user