1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-21 18:30:15 -04:00

Compare commits

...

3 Commits

Author SHA1 Message Date
nova
37d82bebf8 fixed N repetitions of movenment keys 2025-08-12 22:35:31 +02:00
nova
8b02e8e4e6 fixed visible cursor after exiting a sub program 2025-08-12 22:10:36 +02:00
nova
7526a9e6e5 implementation of jump_to_dir 2025-08-12 21:59:34 +02:00
2 changed files with 97 additions and 49 deletions

View File

@@ -35,53 +35,56 @@ static const binding key_binding[] = {
* 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 */
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
{ "q", quit_program, NULL, "quit" },
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
{ "/", not_implemented, NULL, "search" },
{ "q", quit_program, NULL, "quit" },
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" },
{ "/", not_implemented, NULL, "search" },
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
{ "t", move_down, NULL, "move down" },
{ "n", move_up, NULL, "move up" },
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
{ "t", move_down, NULL, "move down" },
{ "n", move_up, NULL, "move up" },
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
{ "dD", 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 */
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
{ "dD", 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 */
{ "G", jump_bottom, NULL, "jump to last file in dir" },
{ "gg", jump_top, NULL, "jump to first file in dir" },
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
{ "go", jump_to_dir, "/opt", "jump to /opt" },
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
{ "gv", jump_to_dir, "/var", "jump to /var" },
{ "G", jump_bottom, NULL, "jump to last file in dir" },
{ "gg", jump_top, NULL, "jump to first file in dir" },
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
{ "gD", jump_to_dir, "$HOME/Downloads", "jump to $HOME/Downloads" },
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
{ "go", jump_to_dir, "/opt", "jump to /opt" },
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
{ "gv", jump_to_dir, "/var", "jump to /var" },
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
{ "on", order_by, sort_natural, "order natural" },
{ "or", not_implemented, "", "order reverse" },
{ "oe", not_implemented, "", "order extension" },
{ "os", order_by, sort_size, "order size" },
{ "ot", order_by, sort_type, "order type" },
{ "oz", order_by, sort_random, "order random" },
{ "oa", order_by, sort_alpha, "order alphabetically" },
{ "on", order_by, sort_natural, "order natural" },
{ "or", not_implemented, "", "order reverse" },
{ "oe", not_implemented, "", "order extension" },
{ "os", order_by, sort_size, "order size" },
{ "ot", order_by, sort_type, "order type" },
{ "oz", order_by, sort_random, "order random" },
{ "oa", order_by, sort_alpha, "order alphabetically" },
{ "mk", makedir, NULL, "create directory" },
{ "mf", makefile, NULL, "create file" },
{ "mk", makedir, NULL, "create directory" },
{ "mf", makefile, NULL, "create file" },
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
{ "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace/delete key */
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
{ "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace key */
};
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension);

View File

@@ -77,16 +77,15 @@ void user_interactions() {
memset(input, 0, 255);
input_pass = 0;
timeout(100); /* blocking timeout of getch() */
status |= STATUS_UPDATE_SCREEN_0;
}
binding_pass = 0;
status |= STATUS_UPDATE_SCREEN_0;
status |= STATUS_UPDATE_SCREEN_0;
}
void (*func_ptr)(int, int);
int number_length = 0;
unsigned long number_length = 0;
if (!binding_pass) {
parsed_input_number = 0;
@@ -94,7 +93,6 @@ void user_interactions() {
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
input++;
number_length++;
mvaddch(terminal_height-5, 5, number_length+48);
}
input -= number_length;
binding_pass = 1;
@@ -109,7 +107,7 @@ void user_interactions() {
func_ptr = key_binding[i].func;
func_ptr(parsed_input_number, i);
} else if (strncmp(input+number_length, key_binding[i].key, cmp_len) == 0) {
} else if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
binding_matches++;
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "%s\t%s", key_binding[i].key, key_binding[i].comment);
@@ -121,7 +119,7 @@ void user_interactions() {
mvaddstr(terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
attroff(A_UNDERLINE);
status &= ~STATUS_INPUT_MATCH;
} else {
} else if (number_length != strlen(input)) {
memset(input, 0, 255);
input_pass = 0;
binding_pass = 0;
@@ -249,6 +247,7 @@ void move_right(){
if (system(cmd) == -1) {
/*do nothing*/
}
curs_set(1); /*for some reason, 1 here turns it invisible once again */
match = 1;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
break;
@@ -269,6 +268,7 @@ void move_right(){
if (system(cmd) == -1) {
/*do nothing*/
}
curs_set(1); /*for some reason, 1 here turns it invisible once again */
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
break;
@@ -519,11 +519,56 @@ void not_implemented(int passes, int index){
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
}
void jump_to_dir(int passes, int index){
if ((char*)key_binding[index].black_magic) {
if (chdir(getenv((char*)key_binding[index].black_magic+1)) != 0) {
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
char *ch = (char*)key_binding[index].black_magic;
char slash = 0;
unsigned int env_len = 0;
while (*ch != '\0') {
if (*ch == '/') {
slash = 1;
break;
}
}
env_len++;
ch++;
}
char *env_str = NULL;
char *env_parsed = NULL;
char *path = NULL;
ch = (char*)key_binding[index].black_magic;
if (*ch == '/') {
path = malloc(strlen((char*)key_binding[index].black_magic));
strcpy(path, (char*)key_binding[index].black_magic);
} else if (slash) {
env_str = malloc(env_len * sizeof(char));
memcpy(env_str, (char*)key_binding[index].black_magic +1, env_len);
env_str[env_len-1] = '\0';
env_parsed = getenv(env_str);
if (env_parsed) {
path = concat(env_parsed, (char*)key_binding[index].black_magic + env_len);
} else {
path = malloc(strlen((char*)key_binding[index].black_magic));
strcpy(path, (char*)key_binding[index].black_magic);
}
} else {
env_parsed = getenv((char*)key_binding[index].black_magic +1);
if (env_parsed) {
path = malloc(strlen(env_parsed)+1);
strcpy(path, env_parsed);
} else {
path = malloc(strlen((char*)key_binding[index].black_magic));
strcpy(path, (char*)key_binding[index].black_magic);
}
}
if (chdir(path) != 0) {
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
}
/*env_parsed shall not be modified (read: free'd) - the man page*/
if (env_str) {
free(env_str);
}
if(path) {
free(path);
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void order_by(int passes, int index){