153 lines
4.1 KiB
C
153 lines
4.1 KiB
C
#define _POSIX_C_SOURCE 200809L
|
|
#include <curses.h>
|
|
#include <pthread.h>
|
|
#include <stdlib.h>
|
|
#include <sys/sysinfo.h>
|
|
#include "threading.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;
|
|
char input = 0;
|
|
|
|
void render_pass(WINDOW *wint, WINDOW *winb, WINDOW *winl, WINDOW *winm, WINDOW *winr);
|
|
void init();
|
|
|
|
|
|
int main() {
|
|
|
|
init();
|
|
|
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
|
WINDOW *win_t = newwin(1, terminal_width, 0, 0);
|
|
WINDOW *win_b = newwin(1, terminal_width, terminal_height-1, 0);
|
|
WINDOW *win_l = newwin(terminal_height-2, terminal_width/3, 1, 0);
|
|
WINDOW *win_m = newwin(terminal_height-2, terminal_width/3, 1, (terminal_width/3));
|
|
WINDOW *win_r = newwin(terminal_height-2, terminal_width/3, 1, ((terminal_width/3)*2));
|
|
|
|
pthread_t thread_b;
|
|
pthread_t thread_t;
|
|
pthread_t thread_l;
|
|
pthread_t thread_m;
|
|
pthread_t thread_r;
|
|
|
|
char threading = 0;
|
|
|
|
|
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
|
|
|
if (!(terminal_height == temp_heigth) || !(terminal_width == temp_width)) {
|
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RESIZE);
|
|
temp_width = terminal_width;
|
|
temp_heigth = terminal_height;
|
|
}
|
|
if (status & STATUS_RUN_BACKEND || threading) {
|
|
if (threading) {
|
|
pthread_cancel(thread_t);
|
|
pthread_cancel(thread_b);
|
|
pthread_cancel(thread_l);
|
|
pthread_cancel(thread_m);
|
|
pthread_cancel(thread_r);
|
|
threading = 0;
|
|
status &= ~STATUS_RUN_BACKEND;
|
|
status |= STATUS_UPDATE_SCREEN_0;
|
|
} else {
|
|
pthread_create(&thread_t, NULL, thread_top, win_t); /*top bar*/
|
|
pthread_create(&thread_b, NULL, thread_btm, win_b); /*bottom bar*/
|
|
pthread_create(&thread_m, NULL, thread_mid, win_m); /*parent_content slash win_l*/
|
|
pthread_create(&thread_l, NULL, thread_lft, win_l); /*current_content slash win_m*/
|
|
pthread_create(&thread_r, NULL, thread_rgt, win_r); /*child_content slash win_r*/
|
|
threading = 1;
|
|
}
|
|
}
|
|
if ((input = getch())) {
|
|
user_interactions(&input, &status, &settings);
|
|
}
|
|
|
|
render_pass(win_t, win_b, win_l, win_m, win_r);
|
|
|
|
}
|
|
threading_free();
|
|
|
|
pthread_join(thread_l, NULL);
|
|
pthread_join(thread_r, NULL);
|
|
pthread_join(thread_m, NULL);
|
|
pthread_join(thread_t, NULL);
|
|
pthread_join(thread_b, NULL);
|
|
|
|
curs_set(1);
|
|
endwin();
|
|
refresh();
|
|
return 0;
|
|
}
|
|
|
|
|
|
void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WINDOW *win_r){
|
|
|
|
if ((status & STATUS_UPDATE_SCREEN_MASK) & STATUS_UPDATE_SCREEN_RESIZE) {
|
|
status |= STATUS_LOCK_MASK;
|
|
|
|
/*TODO: check if deallocation of window and reallocation is faster than this or not */
|
|
|
|
werase(win_t);
|
|
werase(win_b);
|
|
werase(win_l);
|
|
werase(win_m);
|
|
werase(win_r);
|
|
|
|
wresize(win_t, 1, terminal_width);
|
|
wresize(win_b, terminal_height, terminal_width/3);
|
|
wresize(win_m, terminal_height-2, terminal_width/3);
|
|
wresize(win_l, terminal_height-2, terminal_width/3);
|
|
wresize(win_r, terminal_height-2, terminal_width/3);
|
|
|
|
mvwin(win_t, 0, 0);
|
|
mvwin(win_b, terminal_height-1, 0);
|
|
mvwin(win_l, 1, 0);
|
|
mvwin(win_m, 1, (terminal_width/3));
|
|
mvwin(win_r, 1, ((terminal_width/3)*2));
|
|
|
|
|
|
status &= ~STATUS_LOCK_MASK;
|
|
status |= STATUS_UPDATE_SCREEN_0;
|
|
}
|
|
|
|
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
|
status &= ~(STATUS_UPDATE_SCREEN_MASK);
|
|
window_top(win_t);
|
|
window_btm(win_b);
|
|
window_lft(win_l);
|
|
window_mid(win_m);
|
|
window_rgt(win_r);
|
|
wrefresh(win_t);
|
|
wrefresh(win_b);
|
|
wrefresh(win_l);
|
|
wrefresh(win_m);
|
|
wrefresh(win_r);
|
|
}
|
|
}
|
|
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
|
void init() {
|
|
|
|
initscr(); /*start ncurses*/
|
|
noecho(); /*hide keyboard input*/
|
|
timeout(50); /*blocking timeout of getch()*/
|
|
keypad(stdscr, TRUE);
|
|
curs_set(0);
|
|
|
|
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
|
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
|
|
|
threading_init(); /* found in threading.c */
|
|
|
|
|
|
}
|