Compare commits

...

6 Commits

Author SHA1 Message Date
nova
38338df254 code base good enough to actually progress 2025-04-17 01:17:13 +02:00
nova
931d7026ea last commit before large rewrite 2025-03-30 15:58:05 +02:00
nova
2a1d273bc0 basic sorting implemented, segfaults in natural sort 2025-03-13 18:45:36 +01:00
nova
d6a827ba74 added more status 2025-03-13 15:37:31 +01:00
nova
3269ced286 init function 2025-03-13 15:36:45 +01:00
nova
6e06b56a23 corrected interactions.h, file_modifiers no longer missing 2025-03-13 14:30:46 +01:00
12 changed files with 477 additions and 218 deletions

View File

@ -1,5 +1,5 @@
all:
gcc ./main.c -std=c99 -o th -lncurses -ltinfo -Wall
gcc ./main.c -std=c89 -o th -lncurses -ltinfo -Wall
d:
gcc -g -std=c99 ./main.c -o th -lncurses -ltinfo -Wall
gcc -g -std=c89 ./main.c -o th -lncurses -ltinfo -Wall && gdb --tui ./th

143
backend.c
View File

@ -1,112 +1,75 @@
#include <curses.h>
#include <string.h>
#include <strings.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include "defines.h"
#include "sorting.h"
extern unsigned int settings;
extern unsigned int file_modifiers;
extern char **content_l;
extern char **content_m;
extern char **content_r;
extern char *path;
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name){
void get_dir_size(char *path, unsigned long *dir_length_width, unsigned long *dir_width){
DIR *dir = opendir(path);
*longest_name = 256; //magic number originates out of readdir(), unless i implement my own name size function, thisll do
unsigned long index = 1; //always makes the array at least 1 big, used for metadata like the amount of files
if (dir) {
unsigned long entry_count = 0;
unsigned long max_length;
struct dirent *entry;
while ( (entry=readdir(dir)) ) {
if (entry->d_name[0] != '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
index++;
} else if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES){
index++;
}
}
}
*file_count = index;
closedir(dir);
}
void get_dir_content(char *path, unsigned long file_count, unsigned long longest_name, char **dir_content){
DIR *dir = opendir(path);
char content[file_count][longest_name];
memset(content,0,sizeof(content));
if (dir) {
int index = 1; //skip index 0 as it is used for metadata like file count
struct dirent *entry;
while ( (entry=readdir(dir)) ) {
if (entry->d_name[0] != '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
strcpy(dir_content[index], entry->d_name);
index++;
} else if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
strcpy(dir_content[index], entry->d_name);
index++;
while ((entry=readdir(dir))) {
if (entry->d_name[0] != '.' || (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
unsigned int current_length = 0;
unsigned int i = 0;
for (; entry->d_name[i] != '\0'; i++) {
current_length++;
}
if (current_length > max_length) {
/*dynamic filename length to save on memory*/
max_length = current_length;
}
entry_count++;
} else {
}
}
dir_length_width[0] = entry_count;
dir_length_width[1] = max_length;
}
closedir(dir);
}
void print_dir(WINDOW *win, char **dir_content){
for (unsigned long i = 1; i < *dir_content[0]; i++ ){ //skip index 0 as it is used for metadata like file count
wprintw(win, "%s",dir_content[i]);
wmove(win, i, 1);
}
}
// Comparison function to sort strings in ascending order
int compare(const void *a, const void *b) {
return strcasecmp(a, b);
}
void sort_dir(unsigned long *file_count, unsigned long *longest_name, char **dir_content){
char content[*file_count][*longest_name];
memset(content,0,sizeof(content));
if ((file_modifiers & FILE_MODIFIERS_SORT_BITMASK) == 0) {//natural; first dirs, then files
qsort(dir_content, *file_count, *longest_name, compare);
}
}
void *populate_dir(void *which){ // 0=left, 1=main, 2=right
char wh = (char)which;
unsigned long file_count = 0;
unsigned long longest_name = 0;
if (wh) {
if (wh == 1) {
free(content_m);
get_dir_size(path, &file_count, &longest_name);
content_m = calloc(file_count+1, sizeof(*content_m)); //index 0 is used for metadata like file count in dir
for (unsigned long i = 0; i<file_count+1; i++) {
content_m[i] = calloc(longest_name, sizeof(content_m[i]));
}
*content_m[0] = file_count;
get_dir_content(path, file_count, longest_name, content_m);
sort_dir(&file_count, &longest_name, content_m);
} else {
free(content_r);
get_dir_size(path, &file_count, &longest_name);
content_r = calloc(file_count+1, sizeof(*content_r));
for (unsigned long i = 0; i<file_count+1; i++) {
content_r[i] = calloc(longest_name, sizeof(content_r[i]));
}
*content_r[0] = file_count;
get_dir_content(path, file_count, longest_name, content_r);
}
void get_dir_content(char *path, unsigned long *dir_length_width, unsigned long *dir_width, char *dir_content){
struct dirent **entry;
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
dir_length_width[0] = scandir(path, &entry, NULL, alphasort);
} else {
free(content_l);
get_dir_size(path, &file_count, &longest_name);
content_l = calloc(file_count+1, sizeof(*content_l));
for (unsigned long i = 0; i<file_count+1; i++) {
content_l[i] = calloc(longest_name, sizeof(content_l));
}
*content_l[0] = file_count;
get_dir_content(path, file_count, longest_name, content_l);
dir_length_width[0] = scandir(path, &entry, skip_hidden_files, alphasort);
}
return NULL;
unsigned long i = 0;
for (i = 0; i < dir_length_width[0]; i++ ) {
if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
} else {
unsigned long j = 0;
for (; entry[i]->d_name[j] != '\0'; j++) {
dir_content[i * dir_length_width[1] + j] = entry[i]->d_name[j];
}
dir_width[i] = j;
}
}
for (i = 0; i < dir_length_width[0]; i++) {
free(entry[i]);
}
free(entry);
}
void print_dir(WINDOW *win, unsigned long *dir_length_width, unsigned long *file_width, char *dir_content){
unsigned long i = 0;
for (i = 0; i<dir_length_width[0]; i++) {
unsigned long j = 0;
for (j = 0; j < file_width[i]; j++){
mvwprintw(win, i, j, "%c", dir_content[i * dir_length_width[1] + j]);
}
}
}

View File

@ -2,8 +2,6 @@
#include "backend.c"
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name);
void get_dir_content(char *path, unsigned long file_count, unsigned long longest_name, char **dir_content);
void print_dir(WINDOW *win, char **dir_content);
void sort_dir(unsigned long *file_count, unsigned long *longest_name, char **dir_content);
void *populate_dir(void *dir);
void get_dir_size(char *path, unsigned long *dir_length_width, unsigned long *dir_width);
void get_dir_content(char *path, unsigned long *dir_length_width, unsigned long *dir_width, char *dir_content);
void print_dir(WINDOW *win, unsigned long *dir_length_width, unsigned long *width, char *dir_content);

View File

@ -1,5 +1,21 @@
#define STATUS_QUIT_PROGRAM 1
#define STATUS_RUN_BACKEND 2
#define STATUS_UPDATE_SCREEN_MASK 12 /* 1100*/
#define STATUS_UPDATE_SCREEN_0 4
#define STATUS_UPDATE_SCREEN_RESIZE 8
#define STATUS_LOCK_MASK 496
#define STATUS_LOCK_TOP 16
#define STATUS_LOCK_BTM 32
#define STATUS_LOCK_LFT 64
#define STATUS_LOCK_MID 128
#define STATUS_LOCK_RGT 256
#define FILE_MODIFIERS_HIDDEN_FILES 1
#define FILE_MODIFIERS_SORT_BITMASK 126 // 00000000000000000000000001111110
#define FILE_MODIFIERS_SORT_BITMASK 126 /* 00000000000000000000000001111110*/
#define FILE_MODIFIERS_SORT_ALPHABETIC 2
#define FILE_MODIFIERS_SORT_TYPE 4
#define FILE_MODIFIERS_SORT_EXTENSION 8
#define FILE_MODIFIERS_SORT_SIZE 16
#define FILE_MODIFIERS_SORT_RANDOM 32
#define FILE_MODIFIERS_SORT_REVERSE 64
/*FILE_MODIFIERS_SORT_NATURAL is when bitmask is 0*/

View File

@ -4,16 +4,26 @@
#include "defines.h"
extern unsigned int file_modifiers;
void user_interactions(char *input, unsigned int *status, unsigned int *settings, unsigned int *file_modifiers) {
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
if (*input == 'q') {
*status ^= STATUS_QUIT_PROGRAM;
} else if (*input == *"KEY_BACKSPACE") {
*file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
} else if (*input == 'a') {
*file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
} else if (*input == 'o') {
file_modifiers ^= FILE_MODIFIERS_SORT_BITMASK;
} else if (*input == 'e') {
file_modifiers ^= FILE_MODIFIERS_SORT_ALPHABETIC;
} else if (*input == 'u') {
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
} else if (*input == 'h') {
chdir("..");
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
} else {
}
else {
}
*status ^= STATUS_RUN_BACKEND;
}

171
main.c
View File

@ -1,81 +1,152 @@
#define _POSIX_C_SOURCE 200809L
#include <curses.h>
#include <pthread.h>
#include <unistd.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_heigth = 0; /*used for screen refresh*/
unsigned int temp_width = 0;
unsigned int settings;
unsigned int file_modifiers;
unsigned int status; //bit 0 = enable
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 = ".";
unsigned int status;
char input = 0;
void render_pass(WINDOW *wint, WINDOW *winb, WINDOW *winl, WINDOW *winm, WINDOW *winr);
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));
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
status ^= STATUS_RUN_BACKEND;
char input = 0;
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));
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));
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, 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);
}
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);
status ^= STATUS_RUN_BACKEND;
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, &file_modifiers);
user_interactions(&input, &status, &settings);
}
render_pass(win_t, win_b, win_l, win_m, win_r);
}
free(content_l);
free(content_m);
free(content_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 */
}

14
sorting.c Normal file
View File

@ -0,0 +1,14 @@
#include <curses.h>
#include <dirent.h>
#include "defines.h"
extern unsigned int settings;
extern unsigned int file_modifiers;
int skip_hidden_files(const struct dirent *entry){
if (entry->d_name[0] == '.') {
return 0;
}
return 1;
}

8
sorting.h Normal file
View File

@ -0,0 +1,8 @@
#include <curses.h>
#include <dirent.h>
#include "defines.h"
#include "sorting.c"
void sort_dir(unsigned long *dir_length_width, char *dir_content);
int skip_hidden_files(const struct dirent *entry);

153
threading.c Normal file
View File

@ -0,0 +1,153 @@
#include <curses.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "defines.h"
#include "backend.h"
pthread_mutex_t mutex_top;
pthread_mutex_t mutex_btm;
pthread_mutex_t mutex_lft;
pthread_mutex_t mutex_mid;
pthread_mutex_t mutex_rgt;
/* contains entire directory as 2d array
* may be changed in future to only include parts of the dir (currently includes entire dir) */
char *mid_content;
char *lft_content;
char *top_content; /* current path */
/* index 0 = file_count
* index 1 = longest_name */
unsigned long *mid_length_width;
unsigned long *lft_length_width;
unsigned long *top_length_width;
/* this array exists so that a file with a 3 char long name wont spend the same amount of time printing as a file with 200 chars
* should both exist in the same directory
* currently unused */
unsigned long *mid_file_name_width;
unsigned long *lft_file_name_width;
extern unsigned int status;
void *thread_mid(void *data){
pthread_mutex_lock(&mutex_mid);
free(mid_content);
free(mid_file_name_width);
free(mid_length_width);
mid_length_width = malloc(sizeof(char)*2);
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
mid_content = malloc(sizeof("cannot open directory"));
mid_length_width[0] = 1;
mid_length_width[1] = sizeof("cannot open directory");
mid_content = "cannot open directory";
} else {
get_dir_size(path, mid_length_width, mid_file_name_width);
mid_file_name_width = malloc(mid_length_width[0] * sizeof(unsigned long));
mid_content = malloc(mid_length_width[0] * mid_length_width[1] * sizeof(char));
memset(mid_content, ' ', mid_length_width[0] * mid_length_width[1] * sizeof(char));
get_dir_content(path, mid_length_width, mid_file_name_width, mid_content);
}
free(path);
pthread_mutex_unlock(&mutex_mid);
pthread_exit(NULL);
}
void *thread_lft(void *data){
pthread_mutex_lock(&mutex_lft);
free(lft_content);
free(lft_file_name_width);
free(lft_length_width);
lft_length_width = malloc(sizeof(char)*2);
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
lft_content = malloc(sizeof("cannot open directory"));
lft_length_width[0] = 1;
lft_length_width[1] = sizeof("cannot open directory");
lft_content = "cannot open directory";
} else {
char *parent ;
if((parent = malloc(strlen(path)+strlen("/..")+1)) != NULL){
parent[0] = '\0'; /* ensures empty string */
strcat(parent, path);
strcat(parent, "/..");
}
get_dir_size(parent, lft_length_width, lft_file_name_width);
lft_file_name_width = malloc(lft_length_width[0] * sizeof(unsigned long));
lft_content = malloc(lft_length_width[0] * lft_length_width[1] * sizeof(char));
memset(lft_content, ' ', lft_length_width[0] * lft_length_width[1] * sizeof(char));
get_dir_content(parent, lft_length_width, lft_file_name_width, lft_content);
free (parent);
}
free(path);
pthread_mutex_unlock(&mutex_lft);
pthread_exit(NULL);
}
void *thread_rgt(void *data){
pthread_exit(NULL);
}
void *thread_top(void *data){
pthread_mutex_lock(&mutex_top);
free(top_content);
free(top_length_width);
top_length_width = malloc(sizeof(char)*2);
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
top_content = malloc(sizeof("cannot open directory"));
top_length_width[0] = 1;
top_length_width[1] = sizeof("cannot open directory");
top_content = "cannot open directory";
} else {
top_content = getcwd(NULL, 0);
top_length_width[0] = 1;
top_length_width[1] = strlen(top_content);
}
free(path);
pthread_mutex_unlock(&mutex_top);
pthread_exit(NULL);
}
void *thread_btm(void *data){
pthread_exit(NULL);
}
void threading_init(){
mid_content = malloc(sizeof(char));
mid_file_name_width = malloc(sizeof(char));
mid_length_width = malloc(sizeof(char));
lft_content = malloc(sizeof(char));
lft_file_name_width = malloc(sizeof(char));
lft_length_width = malloc(sizeof(char));
top_length_width = malloc(sizeof(char));
top_content = malloc(sizeof(char));
pthread_mutex_init(&mutex_top, NULL);
pthread_mutex_init(&mutex_mid, NULL);
pthread_mutex_init(&mutex_lft, NULL);
}
void threading_free(){
free(mid_content);
free(mid_file_name_width);
free(mid_length_width);
pthread_mutex_destroy(&mutex_top);
pthread_mutex_destroy(&mutex_mid);
pthread_mutex_destroy(&mutex_lft);
}

10
threading.h Normal file
View File

@ -0,0 +1,10 @@
#include <curses.h>
#include "threading.c"
void *thread_lft(void *data);
void *thread_mid(void *data);
void *thread_rgt(void *data);
void *thread_top(void *data);
void *thread_btm(void *data);
void threading_init();
void threading_free();

134
window.c
View File

@ -1,72 +1,88 @@
#include <curses.h>
#include <dirent.h>
#include "backend.h"
#include <pthread.h>
#include "defines.h"
extern unsigned int terminal_height;
extern unsigned int terminal_width;
extern unsigned int status;
extern char *mid_content;
extern unsigned long *mid_width;
extern unsigned long *mid_length_width;
extern unsigned long *mid_file_name_width;
extern char *top_content;
extern unsigned long *top_length_width;
extern char *lft_content;
extern unsigned long *lft_width;
extern unsigned long *lft_length_width;
extern unsigned long *lft_file_name_width;
extern pthread_mutex_t mutex_top;
extern pthread_mutex_t mutex_btm;
extern pthread_mutex_t mutex_lft;
extern pthread_mutex_t mutex_mid;
extern pthread_mutex_t mutex_rgt;
void window_top(WINDOW *win){
unsigned long i = 0;
werase(win);
if (pthread_mutex_trylock(&mutex_top)) {
wprintw(win,"loading");
status |= STATUS_UPDATE_SCREEN_0;
void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
//WINDOW *win = (window_data)window_data.win;
unsigned int local_width;
unsigned int local_height;
//{{{ size & positioning
wresize(win, terminal_height, terminal_width/3);
getmaxyx(win, local_height, local_width);
mvwin(win, start_y, start_x);
wclear(win);
//}}}
wmove(win, 1, 1);
print_dir(win, dir_content);
box(win,0,0);
wrefresh(win);
} else {
for (i = 0; i<top_length_width[1]; i++) {
mvwprintw(win, 0, i, "%c", top_content[i]);
}
pthread_mutex_unlock(&mutex_top);
}
}
void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
unsigned int local_width;
unsigned int local_height;
//{{{ size & positioning
wresize(win, terminal_height, terminal_width/3);
getmaxyx(win, local_height, local_width);
mvwin(win, start_y, start_x);
wclear(win);
//}}}
wmove(win, 1, 1);
print_dir(win, dir_content);
box(win,0,0);
wrefresh(win);
void window_btm(WINDOW *win){
werase(win);
if (pthread_mutex_trylock(&mutex_btm)) {
} else {
pthread_mutex_unlock(&mutex_btm);
}
}
void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
void window_lft(WINDOW *win){
werase(win);
box(win, 0, 0);
wmove(win, 0, 0);
unsigned int local_width;
unsigned int local_height;
//{{{ size & positioning
wresize(win, terminal_height, terminal_width/3);
unsigned long local_width;
unsigned long local_height;
getmaxyx(win, local_height, local_width);
mvwin(win, start_y, start_x);
wclear(win);
//}}}
if (pthread_mutex_trylock(&mutex_lft)) {
mvwprintw(win, local_height/2, local_width/2, "LOADING");
status |= STATUS_UPDATE_SCREEN_0;
wmove(win, local_height/2, local_width/2);
wprintw(win, "%d,%d", local_height, local_width);
box(win,0,0);
wrefresh(win);
} else {
mvwprintw(win, local_height/2, local_width/2, "%ld %ld", lft_length_width[0], lft_length_width[1]);
print_dir(win, lft_length_width, lft_file_name_width, lft_content);
pthread_mutex_unlock(&mutex_lft);
}
}
void window_mid(WINDOW *win){
werase(win);
box(win, 0, 0);
unsigned long local_width;
unsigned long local_height;
getmaxyx(win, local_height, local_width);
if (pthread_mutex_trylock(&mutex_mid)) {
mvwprintw(win, local_height/2, local_width/2, "LOADING");
status |= STATUS_UPDATE_SCREEN_0;
} else {
mvwprintw(win, local_height/2, local_width/2, "%ld %ld", mid_length_width[0], mid_length_width[1]);
print_dir(win, mid_length_width, mid_file_name_width, mid_content);
pthread_mutex_unlock(&mutex_mid);
}
}
void window_rgt(WINDOW *win){
werase(win);
box(win, 0, 0);
if (pthread_mutex_trylock(&mutex_rgt)) {
} else {
pthread_mutex_unlock(&mutex_rgt);
}
}

View File

@ -1,7 +1,7 @@
#include <curses.h>
#include "window.c"
void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content);
void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content);
void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content);
void window_top(WINDOW *win);
void window_btm(WINDOW *win);
void window_lft(WINDOW *win);
void window_mid(WINDOW *win);
void window_rgt(WINDOW *win);