Compare commits
5 Commits
d33ac88de2
...
20fee198ae
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20fee198ae | ||
|
|
632904fd89 | ||
|
|
dd5307b411 | ||
|
|
41933eb6d0 | ||
|
|
0a45d1e3e8 |
3
colors.c
3
colors.c
@@ -102,8 +102,7 @@ void colors_init() {
|
||||
while (getline(&line, &size, dircolors) != -1) {
|
||||
fg = 7;
|
||||
bg = 0;
|
||||
if (line[0] == '.') {
|
||||
extension = strtok(line, " ");
|
||||
if (line[0] == '.' && (extension = strtok(line, " ")) != NULL) {
|
||||
colors[i].file_extension = malloc(strlen(extension)+1);
|
||||
memcpy(colors[i].file_extension, extension, strlen(extension)+1);
|
||||
|
||||
|
||||
18
config.h
18
config.h
@@ -118,11 +118,11 @@ static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this define
|
||||
|
||||
static const char ui_btm_text_storage_left[] = "total free";
|
||||
static const char ui_btm_current_dir_size[] = "sum of dir,";
|
||||
static const char ui_open_with_text_0[] = "open"; /*ui_open_with_text_0 \"selected_file\" ui_open_with_text_1*/
|
||||
static const char ui_open_with_text_1[] = "with:";
|
||||
static const char ui_rename_text_0[] = "rename"; /*ui_rename_text_0 \"selected_file\" ui_rename_text_1*/
|
||||
static const char ui_rename_text_1[] = "to:";
|
||||
static const char ui_delete_text[] = "delete:";
|
||||
static const char ui_open_with_text[] = "open "SETTINGS_COMMAND_REPLACE_STR" with:";
|
||||
static const char ui_rename_text[] = "rename "SETTINGS_COMMAND_REPLACE_STR" to:";
|
||||
static const char ui_mkdir_text[] = "mkdir:";
|
||||
static const char ui_touch_text[] = "touch:";
|
||||
static const char ui_delete_text[] = "delete: "SETTINGS_COMMAND_REPLACE_STR;
|
||||
|
||||
/* {{{ */
|
||||
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
||||
@@ -139,10 +139,10 @@ static const unsigned long mimetype_default_count;
|
||||
static const unsigned long file_extension_default_count;
|
||||
static const char size_unit[];
|
||||
static const char size_unit_count;
|
||||
static const char ui_open_with_text_0[];
|
||||
static const char ui_open_with_text_1[];
|
||||
static const char ui_rename_text_0[];
|
||||
static const char ui_rename_text_1[];
|
||||
static const char ui_open_with_text[];
|
||||
static const char ui_rename_text[];
|
||||
static const char ui_mkdir_text[];
|
||||
static const char ui_touch_text[];
|
||||
static const char ui_delete_text[];
|
||||
#endif
|
||||
/* }}} */
|
||||
|
||||
71
dir.c
71
dir.c
@@ -28,20 +28,22 @@ unsigned long get_dir_size(char *path){
|
||||
DIR *dir = opendir(path);
|
||||
unsigned long entry_count = 0;
|
||||
struct dirent *entry;
|
||||
if (dir && file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||
while ((entry=readdir(dir))) {
|
||||
entry_count++;
|
||||
}
|
||||
/* removes files "." and ".." */
|
||||
entry_count -= 2;
|
||||
} else if (dir) {
|
||||
while ((entry=readdir(dir))) {
|
||||
if (entry->d_name[0] != '.') {
|
||||
if (dir) {
|
||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||
while ((entry=readdir(dir))) {
|
||||
entry_count++;
|
||||
}
|
||||
}
|
||||
/* removes files "." and ".." */
|
||||
entry_count -= 2;
|
||||
} else {
|
||||
while ((entry=readdir(dir))) {
|
||||
if (entry->d_name[0] != '.') {
|
||||
entry_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
closedir(dir);
|
||||
return entry_count;
|
||||
|
||||
}
|
||||
@@ -308,37 +310,60 @@ void dir_changed(){
|
||||
}
|
||||
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||
|
||||
} else {
|
||||
/*this path should only ever happen on changing the path for the first time
|
||||
*at least i hope so*/
|
||||
/**/
|
||||
|
||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
||||
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
||||
current_linked_dir->next->next = NULL;
|
||||
current_linked_dir->next->index = 0;
|
||||
|
||||
mid_dir.current_file = mid_dir.file_list;
|
||||
}
|
||||
|
||||
}
|
||||
void change_dir(){
|
||||
void change_dir(char *new_path){
|
||||
|
||||
char *old_path = getcwd(NULL, 0);
|
||||
current_linked_dir = list_beginning;
|
||||
while (current_linked_dir->next != NULL) {
|
||||
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
||||
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||
break;
|
||||
} else {
|
||||
current_linked_dir = current_linked_dir->next;
|
||||
}
|
||||
}
|
||||
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
||||
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
||||
} else {
|
||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
||||
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
||||
current_linked_dir->next->next = NULL;
|
||||
current_linked_dir->next->index = mid_dir.current_file - mid_dir.file_list;
|
||||
}
|
||||
|
||||
chdir(new_path);
|
||||
char *new_path_real = getcwd(NULL, 0);
|
||||
|
||||
current_linked_dir = list_beginning;
|
||||
while (current_linked_dir->next != NULL) {
|
||||
if(strcmp(current_linked_dir->path, new_path_real) == 0) {
|
||||
break;
|
||||
} else {
|
||||
current_linked_dir = current_linked_dir->next;
|
||||
}
|
||||
}
|
||||
if(strcmp(current_linked_dir->path, new_path_real) != 0) {
|
||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||
current_linked_dir = current_linked_dir->next;
|
||||
current_linked_dir->path = malloc(strlen(new_path_real)+1);
|
||||
memcpy(current_linked_dir->path, new_path_real, strlen(new_path_real)+1);
|
||||
current_linked_dir->next = NULL;
|
||||
current_linked_dir->index = 0;
|
||||
/*TODO(2026-05-25T22:49:30)
|
||||
*handle if new_path == "..", should this case be true, focus the index on which the old_path falls on*/
|
||||
}
|
||||
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||
|
||||
free(old_path);
|
||||
free(new_path_real);
|
||||
|
||||
}
|
||||
|
||||
void dir_init(){
|
||||
|
||||
@@ -128,18 +128,18 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
||||
break;
|
||||
} else if (ch == '\t') { /* tab */
|
||||
memcpy(str + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
||||
mvwaddstr(win, y, x +pass, mid_dir.current_file->file_name);
|
||||
mvwaddstr(win, y, x + pass, mid_dir.current_file->file_name);
|
||||
pass += strlen(mid_dir.current_file->file_name);
|
||||
} else if (ch == 127) { /* backspace */
|
||||
if (pass > 0) {
|
||||
pass--;
|
||||
mvwdelch(win, y, pass);
|
||||
mvwdelch(win, y, x + pass);
|
||||
}
|
||||
} else if (ch == 27) { /* esc key */
|
||||
err = 1;
|
||||
break;
|
||||
} else {
|
||||
mvwaddch(win, y, x +pass, ch);
|
||||
mvwaddch(win, y, x + pass, ch);
|
||||
str[pass] = ch;
|
||||
pass++;
|
||||
}
|
||||
@@ -184,12 +184,7 @@ void move_up(unsigned long passes){
|
||||
void move_left(unsigned long passes){
|
||||
unsigned long i;
|
||||
for (i = 0; i < passes; i++) {
|
||||
change_dir();
|
||||
if (chdir("..") != 0) {
|
||||
/* TODO(2025-07-09T00:30:05) fix */
|
||||
FAIL("move_left", "unhandled error of chdir");
|
||||
}
|
||||
dir_changed();
|
||||
change_dir("..");
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
|
||||
@@ -197,17 +192,11 @@ void move_left(unsigned long passes){
|
||||
void move_right(){
|
||||
|
||||
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||
change_dir();
|
||||
if (chdir(mid_dir.current_file->file_name) != 0) {
|
||||
/* TODO(2026-05-05T20:12:14) fix */
|
||||
FAIL("move_right", "unhandled error of chdir");
|
||||
}
|
||||
dir_changed();
|
||||
change_dir(mid_dir.current_file->file_name);
|
||||
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
||||
chdir(".");
|
||||
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
|
||||
if (system(cmd)) {
|
||||
}
|
||||
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
|
||||
if (system(cmd)) {
|
||||
}
|
||||
} else {
|
||||
char *mime = get_mimetype(mid_dir.current_file);
|
||||
char *extension = mid_dir.current_file->file_name;
|
||||
@@ -301,10 +290,30 @@ void delete(){
|
||||
TODO;
|
||||
}
|
||||
void makedir(){
|
||||
TODO;
|
||||
wclear(win_b);
|
||||
file tmp;
|
||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||
mvwprintw(win_b, 0, 0, ui_mkdir_text);
|
||||
if (read_string(win_b, 0, strlen(ui_mkdir_text)+1, tmp.file_name) == 0) {
|
||||
char *cmd = parse_cmd("mkdir ", &tmp);
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
}
|
||||
free(tmp.file_name);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void makefile(){
|
||||
TODO;
|
||||
wclear(win_b);
|
||||
file tmp;
|
||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||
mvwprintw(win_b, 0, 0, ui_touch_text);
|
||||
if (read_string(win_b, 0, strlen(ui_touch_text)+1, tmp.file_name) == 0) {
|
||||
char *cmd = parse_cmd("touch ", &tmp);
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
}
|
||||
free(tmp.file_name);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void enter_shell(unsigned long passes, int index){
|
||||
(void)passes; /*remove compiler warning*/
|
||||
|
||||
Reference in New Issue
Block a user