From 3269ced286a1997638175d076d4e7c5bd58925e8 Mon Sep 17 00:00:00 2001 From: nova Date: Thu, 13 Mar 2025 15:36:45 +0100 Subject: [PATCH] init function --- main.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index b2f81f4..63c98f7 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "window.h" #include "interactions.h" #include "defines.h" @@ -13,10 +14,15 @@ unsigned int temp_width = 0; unsigned int settings; unsigned int file_modifiers; unsigned int status; //bit 0 = enable +unsigned short cpu_cores; //amount of cores/threads the host system reports to have char **content_l; //content of parent dir, used in left window char **content_m; //content of current dir, used in main window char **content_r; //content of child dir, used in right window char *path = "."; +char input = 0; + + +void init(); int main() { @@ -24,17 +30,12 @@ int main() { timeout(50); //blocking timeout of getch() keypad(stdscr, TRUE); + init(); + getmaxyx(stdscr, terminal_height, terminal_width); WINDOW *winl = newwin(terminal_height, terminal_width/3, terminal_height, (terminal_width/3)); WINDOW *winm = newwin(terminal_height, terminal_width/3, 0, 0); WINDOW *winr = newwin(terminal_height, terminal_width/3, terminal_height, ((terminal_width/3)*2)); - file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES; - status ^= STATUS_RUN_BACKEND; - char input = 0; - - content_l = calloc(1, sizeof(*content_l)); //allocation in order to allow a more streamlined backend - content_m = calloc(1, sizeof(*content_m)); - content_r = calloc(1, sizeof(*content_r)); while(!(status & STATUS_QUIT_PROGRAM)){ getmaxyx(stdscr, temp_heigth, temp_width); @@ -51,19 +52,22 @@ int main() { pthread_join(populate_l, NULL); pthread_join(populate_m, NULL); pthread_join(populate_r, NULL); + status ^= STATUS_UPDATE_SCREEN_0; } getmaxyx(stdscr, terminal_height, terminal_width); temp_heigth -= terminal_height; temp_width -= terminal_width; - if (!temp_heigth || !temp_width || (status & STATUS_RUN_BACKEND)) { //updates screen - window_left(winl, 0, 0, content_l); - window_main(winm, 0, terminal_width/3, content_m); - window_right(winr, 0, (terminal_width/3)*2, content_r); - wmove(stdscr,0,0); + if (!temp_heigth || !temp_width || (status & STATUS_UPDATE_SCREEN_MASK)) { //updates screen + if (status & STATUS_UPDATE_SCREEN_0) { + window_left(winl, 0, 0, content_l); + window_main(winm, 0, terminal_width/3, content_m); + window_right(winr, 0, (terminal_width/3)*2, content_r); + } - status ^= STATUS_RUN_BACKEND; + wmove(stdscr,0,0); + status &= ~STATUS_UPDATE_SCREEN_MASK; } @@ -79,3 +83,16 @@ int main() { endwin(); return 0; } + +//this function exists for things done at startup (initialization, reading config, etc) +void init() { + + cpu_cores = get_nprocs(); + file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES; + status ^= STATUS_RUN_BACKEND; + + content_l = calloc(1, sizeof(*content_l)); //allocation in order to allow a more streamlined backend + content_m = calloc(1, sizeof(*content_m)); + content_r = calloc(1, sizeof(*content_r)); + +}