From 56bc1e4314fcd52e11fed39529a1e066f59b8b9c Mon Sep 17 00:00:00 2001 From: nova Date: Wed, 26 Feb 2025 14:01:23 +0100 Subject: [PATCH] working file printing --- main.c | 7 ++++ th | Bin 0 -> 16512 bytes window.c | 116 +++++++++++++++++++++++++++++++++++++++++-------------- window.h | 6 +++ 4 files changed, 99 insertions(+), 30 deletions(-) create mode 100755 th 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 0000000000000000000000000000000000000000..ba3f2691128a16068304dbbc108a3cc1bd4badd9 GIT binary patch literal 16512 zcmeHOdvH|Oc|R+$wh{v?9tIgOUOyDSV2yal5F2}WEL>8A2}Wr;eq0vq3T-Uys;d z=X|?&ue7PtN&iW8c6Pt>{l3RJ=R4<~bI;v#pAD>EQ{r+7PNm`@LEO+(h4@*pj59*` z#ZoZ|zjMXS;yS<+@bzo4lMa?B0n;+AR|-mY6_go+&QY*n$~7cPcEwV~4NAgPlq;U> z+?3V4lioU6=`m$_t~{@j3kMx01tg|+JBrQ7JSi3<4;E5xw_mrP?I>JiS2kbimn|=( zRClMiuQ9TP&L-M~Qst?v`{Gc#^9)>~e{n zLJ&r2@ZNoM2EuPPDQ@)dX+ZjtE)bqAf>Sx(0!_ud0y37L14Zx~;AkxUM~mqHpa>o* zg2#*Cj}^fu6sga@718f1g8!xnelu_{zRq+Rz*uqETLj-<1m9Hzf4T_1wFtflxEEh% zItXB_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4s*;ND~whmqDkNlnb8sG%P+NoEaOPf%uGt-%

Q{o=cttTY;3hK9}eP zO+JSLR)Pg)tag2=2u|;}jHN#lIK{KvpD&Ygw*&VULXulv#Lp`7gZM1)D^vvMx$xh1%wC;p z&uNn{9Dg@)7TuI*;mvR;m2-=VtNf!}?sGx>z)UwTRF5tCRCNL#jES!Y=^%RKGfKUm!9~YMeT( zk17?sZ~$3L%xnloL-aDjx<{ZDibTy;9P{Th`~|++^h*T%q5{tI3muQRYPh+zrA3#; zZy4|k2;lKLLYsP9!8GwAgc;bd8m~PRf8Rm9l#q*VTO^cdKpX7u8Whyeq<0^4U?AsP?^)<)Q?eWA84Xs$YZhj)TO-NZo z5HDExLOY`Hr)VOsB-_LBmPjmGz?hK5!;L{Q(7EQugz(8)`jGW)i-Dy~OSn$>65)2R za_soxF*zoE;Rdrl9&8Gm4Iy}APWdo{@pusRBn!@?s9;kB&XhU2L-^`qO-(eYejkaZ zOS)Rfgv| zhF2qlza(N@KJPb}-lY}sf4@x5@;3mby$0L!euU`(Euj4h#fj~CU+@iJRAsj3{S8yz z&p<^cJ-sq3oWP5&|QE?wYq_iTrU$$p@2@<=#@N3ltigGy`9o3#I5Rfk} z-|JVJ<=UR-IfV-0<&37+K&gDKo|Ce@v;Rq#lAZF{Q4;mrt{sl(0YmE$#gN<0^`hrA iTz6%uew&vly2s(1%Vk} #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;