mirror of
https://gittea.dev/nova/th.git
synced 2025-10-22 10:50:15 -04:00
linked list to keep track of past directory indexes
This commit is contained in:
@@ -91,4 +91,10 @@ typedef struct Yank {
|
|||||||
char **list;
|
char **list;
|
||||||
unsigned long count;
|
unsigned long count;
|
||||||
} yank;
|
} yank;
|
||||||
|
typedef struct Linked_dir {
|
||||||
|
char *path;
|
||||||
|
unsigned long selected_file_current;
|
||||||
|
struct Linked_dir *next;
|
||||||
|
} linked_dir;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
36
dir.c
36
dir.c
@@ -19,6 +19,8 @@ extern volatile unsigned long selected_file_current;
|
|||||||
extern volatile unsigned long selected_file_last;
|
extern volatile unsigned long selected_file_last;
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
int (*order_func)() = sort_natural;
|
int (*order_func)() = sort_natural;
|
||||||
|
linked_dir *visited_dirs;
|
||||||
|
linked_dir *current_dir;
|
||||||
|
|
||||||
unsigned long get_dir_size(char *path);
|
unsigned long get_dir_size(char *path);
|
||||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
||||||
@@ -332,3 +334,37 @@ void update_selected_file(){
|
|||||||
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
||||||
file_current->status = mid_content[selected_file_current].status;
|
file_current->status = mid_content[selected_file_current].status;
|
||||||
}
|
}
|
||||||
|
void dir_set_selected_file_current(unsigned long selected_file_current){
|
||||||
|
current_dir->selected_file_current = selected_file_current;
|
||||||
|
mvwaddch(stdscr, 0,0, selected_file_current + '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long dir_get_selected_file_current(){
|
||||||
|
current_dir = visited_dirs;
|
||||||
|
char hit = 0;
|
||||||
|
char *path = getcwd(NULL, 0);
|
||||||
|
while(current_dir->next != NULL) {
|
||||||
|
if (strcmp(path, current_dir->path) == 0) {
|
||||||
|
hit = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current_dir = current_dir->next;
|
||||||
|
}
|
||||||
|
if (hit == 0) {
|
||||||
|
current_dir->next = malloc(sizeof(linked_dir));
|
||||||
|
current_dir->next->next = NULL;
|
||||||
|
current_dir->next->path = path;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
free(path);
|
||||||
|
return current_dir->selected_file_current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void dir_init(){
|
||||||
|
visited_dirs = malloc(sizeof(linked_dir));
|
||||||
|
visited_dirs->path = getcwd(NULL, 0);
|
||||||
|
visited_dirs->selected_file_current = 0;
|
||||||
|
visited_dirs->next = NULL;
|
||||||
|
current_dir = visited_dirs;
|
||||||
|
|
||||||
|
}
|
||||||
|
3
dir.h
3
dir.h
@@ -7,3 +7,6 @@ unsigned long get_dir_size(char *path);
|
|||||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
||||||
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
|
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
|
||||||
void update_selected_file();
|
void update_selected_file();
|
||||||
|
void dir_set_selected_file_current(unsigned long selected_file_current);
|
||||||
|
unsigned long dir_get_selected_file_current();
|
||||||
|
void dir_init();
|
||||||
|
@@ -197,6 +197,7 @@ void move_down(int passes){
|
|||||||
selected_file_current += passes;
|
selected_file_current += passes;
|
||||||
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
|
dir_set_selected_file_current(selected_file_current);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
@@ -213,6 +214,7 @@ void move_up(int passes){
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
|
dir_set_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);
|
||||||
@@ -226,6 +228,8 @@ void move_left(int passes){
|
|||||||
if (chdir("..") != 0) {
|
if (chdir("..") != 0) {
|
||||||
/* TODO(2025-07-09T00:30:05) fix */
|
/* TODO(2025-07-09T00:30:05) fix */
|
||||||
FAIL("move_left", "unhandled error of chdir");
|
FAIL("move_left", "unhandled error of chdir");
|
||||||
|
} else {
|
||||||
|
selected_file_current = dir_get_selected_file_current();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
@@ -234,6 +238,8 @@ void move_right(){
|
|||||||
if (file_current->file_type == FILE_TYPE_DIR || file_current->file_type == FILE_TYPE_SYMLINK) {
|
if (file_current->file_type == FILE_TYPE_DIR || file_current->file_type == FILE_TYPE_SYMLINK) {
|
||||||
if (chdir(file_current->file_name) != 0) {
|
if (chdir(file_current->file_name) != 0) {
|
||||||
FAIL("move_right", "unhandled error of chdir");
|
FAIL("move_right", "unhandled error of chdir");
|
||||||
|
} else {
|
||||||
|
selected_file_current = dir_get_selected_file_current();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
@@ -291,6 +297,7 @@ void jump_bottom(){
|
|||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0 - 1;
|
selected_file_current = 0 - 1;
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
|
dir_set_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);
|
||||||
}
|
}
|
||||||
@@ -298,6 +305,7 @@ void jump_top(){
|
|||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0;
|
selected_file_current = 0;
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
|
dir_set_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);
|
||||||
}
|
}
|
||||||
@@ -566,6 +574,8 @@ void jump_to_dir(int passes, int index){
|
|||||||
}
|
}
|
||||||
if (chdir(path) != 0) {
|
if (chdir(path) != 0) {
|
||||||
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
|
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
|
||||||
|
} else {
|
||||||
|
selected_file_current = dir_get_selected_file_current();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*env_parsed shall not be modified (read: free'd) - the man page*/
|
/*env_parsed shall not be modified (read: free'd) - the man page*/
|
||||||
@@ -774,8 +784,8 @@ void search(){
|
|||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
||||||
selected_file_current = i;
|
selected_file_current = i;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
render_pass();
|
render_pass();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
1
main.c
1
main.c
@@ -191,6 +191,7 @@ void init() {
|
|||||||
threading_init(); /* found in threading.c */
|
threading_init(); /* found in threading.c */
|
||||||
colors_init(); /* in colors.c */
|
colors_init(); /* in colors.c */
|
||||||
ueberzug_init(); /* in file_previews.c */
|
ueberzug_init(); /* in file_previews.c */
|
||||||
|
dir_init(); /*in dir.c */
|
||||||
|
|
||||||
ESCDELAY = 10;
|
ESCDELAY = 10;
|
||||||
char *start_path = getcwd(NULL, 0);
|
char *start_path = getcwd(NULL, 0);
|
||||||
|
Reference in New Issue
Block a user