file preview infrastructure & implementation of preview of text files
This commit is contained in:
14
window.c
14
window.c
@ -1,5 +1,6 @@
|
||||
#include <curses.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include "defines.h"
|
||||
|
||||
extern unsigned int status;
|
||||
@ -12,6 +13,7 @@ extern file *mid_content;
|
||||
extern file *lft_content;
|
||||
extern file *rgt_content;
|
||||
extern char *top_content;
|
||||
extern char *rgt_buffer;
|
||||
|
||||
extern unsigned long lft_file_count;
|
||||
extern unsigned long mid_file_count;
|
||||
@ -31,6 +33,7 @@ void window_top(WINDOW *win){
|
||||
if (pthread_mutex_trylock(&mutex_top)) {
|
||||
wprintw(win,"loading");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
|
||||
} else {
|
||||
wattron(win, COLOR_PAIR(COLOR_PATH));
|
||||
@ -42,6 +45,7 @@ void window_top(WINDOW *win){
|
||||
void window_btm(WINDOW *win){
|
||||
werase(win);
|
||||
if (pthread_mutex_trylock(&mutex_btm)) {
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
} else {
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
}
|
||||
@ -56,6 +60,7 @@ void window_lft(WINDOW *win){
|
||||
if (pthread_mutex_trylock(&mutex_lft)) {
|
||||
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
|
||||
} else {
|
||||
print_dir(win, &lft_file_count, lft_content);
|
||||
@ -72,6 +77,7 @@ void window_mid(WINDOW *win){
|
||||
if (pthread_mutex_trylock(&mutex_mid)) {
|
||||
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
|
||||
} else {
|
||||
print_dir(win, &mid_file_count, mid_content);
|
||||
@ -86,10 +92,16 @@ void window_rgt(WINDOW *win){
|
||||
unsigned long local_height;
|
||||
getmaxyx(win, local_height, local_width);
|
||||
if (pthread_mutex_trylock(&mutex_rgt)) {
|
||||
/* TODO(2025-06-13T00:49:26) fix race condition and use trylock */
|
||||
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
} else {
|
||||
print_dir(win, &rgt_file_count, rgt_content);
|
||||
if (rgt_content[0].file_type == FILE_TYPE_OPEN_FILE) {
|
||||
mvwprintw(win, 0, 0, "%s", rgt_buffer);
|
||||
} else {
|
||||
print_dir(win, &rgt_file_count, rgt_content);
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user