102 lines
3.0 KiB
C
102 lines
3.0 KiB
C
#include <curses.h>
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <sys/sysinfo.h>
|
|
#include "window.h"
|
|
#include "interactions.h"
|
|
#include "defines.h"
|
|
|
|
unsigned int terminal_height;
|
|
unsigned int terminal_width;
|
|
unsigned int temp_heigth = 0; //used for screen refresh
|
|
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
|
|
file_data *content_l; //content of parent dir, used in left window
|
|
file_data *content_m; //content of current dir, used in main window
|
|
file_data *content_r; //content of child dir, used in right window
|
|
char *path = ".";
|
|
char input = 0;
|
|
|
|
|
|
void init();
|
|
|
|
|
|
int main() {
|
|
initscr(); //start ncurses
|
|
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));
|
|
|
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
|
getmaxyx(stdscr, temp_heigth, temp_width);
|
|
|
|
if (status & STATUS_RUN_BACKEND) {
|
|
pthread_t populate_l;
|
|
pthread_t populate_m;
|
|
pthread_t populate_r;
|
|
|
|
pthread_create(&populate_l, NULL, populate_dir, (void*)0); //parent_content slash win_l
|
|
pthread_create(&populate_m, NULL, populate_dir, (void*)1); //current_content slash win_m
|
|
pthread_create(&populate_r, NULL, populate_dir, (void*)2); //child_content slash win_r
|
|
|
|
pthread_join(populate_l, NULL);
|
|
pthread_join(populate_m, NULL);
|
|
pthread_join(populate_r, NULL);
|
|
status ^= STATUS_RUN_BACKEND;
|
|
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_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);
|
|
}
|
|
|
|
wmove(stdscr,0,0);
|
|
//status &= ~STATUS_UPDATE_SCREEN_MASK;
|
|
status = 0;
|
|
}
|
|
|
|
|
|
if ((input = getch())) {
|
|
user_interactions(&input, &status, &settings);
|
|
}
|
|
}
|
|
free(content_l);
|
|
free(content_m);
|
|
free(content_r);
|
|
|
|
|
|
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 | FILE_MODIFIERS_SORT_BITMASK);
|
|
file_modifiers = FILE_MODIFIERS_SORT_BITMASK;
|
|
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
|
|
content_l = (file_data*)calloc(1, sizeof(file_data)); //allocation in order to allow a more streamlined backend
|
|
content_m = (file_data*)calloc(1, sizeof(file_data));
|
|
content_r = (file_data*)calloc(1, sizeof(file_data));
|
|
|
|
}
|