diff --git a/main.c b/main.c index 8512d6b..f4cc36c 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,6 @@ #include +#include +#include #include "window.h" unsigned int terminal_height; @@ -14,9 +16,14 @@ int main() { WINDOW *win_r = newwin(terminal_height, terminal_width/3, terminal_height, ((terminal_width/3)*2)); while((ch = wgetch(win_m)) != 'q'){ getmaxyx(stdscr, terminal_height, terminal_width); + + pthread_t main_window_thread; + pthread_t left_window_thread; + pthread_t right_window_thread; window_left(win_l,0,0); window_main(win_m,0,(terminal_width/3)); window_right(win_r,0,((terminal_width/3)*2)); + wmove(stdscr,0,0); } diff --git a/th b/th new file mode 100755 index 0000000..ba3f269 Binary files /dev/null and b/th differ diff --git a/window.c b/window.c index 8f86345..b6c0fbf 100644 --- a/window.c +++ b/window.c @@ -1,14 +1,82 @@ #include "curses.h" +#include "string.h" +#include #include extern unsigned int terminal_height; extern unsigned int terminal_width; +void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name, char show_hidden) { + DIR *dir = opendir(path); + if (dir) { + unsigned long index = 0; + struct dirent *entry; + while ( entry=readdir(dir) ) { + if (entry->d_name[0] != '.' && !show_hidden) { + index++; + if ((unsigned long)sizeof(entry->d_name) > *longest_name) { + *longest_name = sizeof(entry->d_name); + } + } else if (show_hidden){ + index++; + if ((unsigned long*)sizeof(entry->d_name) > (unsigned long*)longest_name) { + longest_name = (unsigned long*)sizeof(entry->d_name); + } + } + } + *file_count = index; + } + closedir(dir); +} + +void get_dir_content(char *path, unsigned long file_count, unsigned long longest_name, char *dir_content[file_count], char show_hidden){ + DIR *dir = opendir(path); + char content[file_count][longest_name]; + memset(content,0,sizeof(content)); + if (dir) { + int index = 0; + struct dirent *entry; + while ( entry=readdir(dir) ) { + if (entry->d_name[0] != '.' && !show_hidden) { +// for (unsigned long i = 0; i < sizeof(entry->d_name)/sizeof(char); i++) { +// if ((entry->d_name[i]) != '\0'){ +// dir_content[index][i] = entry->d_name[i]; +// } else { +// break; +// } +// } + strcpy(dir_content[index], entry->d_name); + index++; + } else if (show_hidden){ + for (unsigned long i = 0; i < sizeof(entry->d_name)/sizeof(char); i++) { + if ((entry->d_name[i]) != '\0'){ + } else { + break; + } + } + index++; + } + } + } + closedir(dir); +} +void print_dir(WINDOW *win, unsigned long file_count, unsigned long longest_name, char **dir_content){ + char str[longest_name]; + for (unsigned long i = 0; i < (unsigned long)file_count; i++ ){ + strcpy(str, dir_content[i]); + wprintw(win, "%s",str); + wmove(win, i, 1); + } +} + + + void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x){ unsigned int local_width; unsigned int local_height; - DIR *path = opendir("."); + unsigned long file_count = 0; + unsigned long longest_name = 0; //{{{ size & positioning wresize(win, terminal_height, terminal_width/3); @@ -17,30 +85,31 @@ void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x){ wclear(win); //}}} - wmove(win, 0, 0); - if (path == NULL) { - wprintw(win, "Unable to read directory"); - } else { - int index = 0; - struct dirent *entry; - while ( entry=readdir(path) ) { - if (entry->d_name[0] != '.') { - wprintw(win, "%s", entry->d_name); - wmove(win, index, 1); - index++; - } - } + wmove(win, 1, 1); + wprintw(win, "meow"); + get_dir_size(".", &file_count, &longest_name, 0); + char **dir_content; + dir_content = calloc(file_count, sizeof(*dir_content)); + for (unsigned long i = 0; id_name[0] != '.') { - wprintw(win, "%s", entry->d_name); - wmove(win, index, 1); - index++; - } - } - } - closedir(path); box(win,0,0); @@ -71,6 +126,7 @@ void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x){ } void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x){ + wmove(win, 0, 0); unsigned int local_width; unsigned int local_height; diff --git a/window.h b/window.h index adc865d..7af01be 100644 --- a/window.h +++ b/window.h @@ -4,3 +4,9 @@ void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x); void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x); void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x); + +typedef struct window_data { + WINDOW *win; + unsigned int start_y; + unsigned int start_x; +} window_data;