Compare commits
5 Commits
7f0e65eaf3
...
f7c1d34e05
Author | SHA1 | Date | |
---|---|---|---|
|
f7c1d34e05 | ||
|
3d3052e436 | ||
|
0574732a69 | ||
|
2b52329904 | ||
|
bab921dea2 |
31
backend.c
31
backend.c
@ -39,19 +39,29 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
scandir(path, &entry, skip_hidden_files, alphasort);
|
scandir(path, &entry, skip_hidden_files, alphasort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < *dir_file_count; i++ ) {
|
for (i = 0; i < *dir_file_count; i++ ) {
|
||||||
if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
||||||
} else {
|
} else {
|
||||||
dir_content[i].file_name_width = strlen(entry[i]->d_name);
|
dir_content[i].file_name_width = sizeof(entry[i]->d_name) / sizeof(char);;
|
||||||
dir_content[i].file_name = malloc(sizeof(entry[i]->d_name));
|
dir_content[i].file_name = malloc(dir_content[i].file_name_width * sizeof(char));
|
||||||
dir_content[i].file_name = entry[i]->d_name;
|
memcpy(dir_content[i].file_name, entry[i]->d_name, dir_content[i].file_name_width);
|
||||||
|
|
||||||
struct stat *file;
|
struct stat *file;
|
||||||
file = malloc(sizeof(struct stat));
|
file = malloc(sizeof(struct stat));
|
||||||
memset(file, ' ', sizeof(struct stat));
|
memset(file, ' ', sizeof(struct stat));
|
||||||
lstat(dir_content[i].file_name, file);
|
|
||||||
|
/* using the full path allows using the same function for all windows */
|
||||||
|
unsigned long path_len = strlen(path);
|
||||||
|
char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/"));
|
||||||
|
memcpy(full_path, path, strlen(path));
|
||||||
|
memcpy(full_path + path_len, "/", sizeof("/"));
|
||||||
|
memcpy(full_path + path_len + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
||||||
|
|
||||||
|
lstat(full_path, file);
|
||||||
|
free(full_path);
|
||||||
|
|
||||||
if (S_ISDIR(file->st_mode)) {
|
if (S_ISDIR(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_DIR;
|
dir_content[i].file_type = FILE_TYPE_DIR;
|
||||||
@ -115,15 +125,20 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
void print_dir(WINDOW *win, unsigned long *dir_file_count, file *dir_content){
|
void print_dir(WINDOW *win, unsigned long *dir_file_count, file *dir_content){
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
|
unsigned int offset = 2;
|
||||||
|
if (*dir_file_count > 9) {
|
||||||
|
offset = (snprintf(NULL, 0, "%ld", *dir_file_count)) + 1;
|
||||||
|
}
|
||||||
for (i = 0; i < *dir_file_count; i++) {
|
for (i = 0; i < *dir_file_count; i++) {
|
||||||
wattron(win, COLOR_PAIR(dir_content[i].color_pair));
|
wattron(win, COLOR_PAIR(dir_content[i].color_pair));
|
||||||
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
||||||
wattron(win, A_REVERSE);
|
wattron(win, A_REVERSE);
|
||||||
}
|
mvwprintw(win, i, 0, "%ld", i);
|
||||||
mvwprintw(win, i, 0, "%d", dir_content[i].color_pair);
|
mvwprintw(win, i, offset, "%s", dir_content[i].file_name);
|
||||||
mvwaddstr(win, i, 3,dir_content[i].file_name);
|
|
||||||
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
|
||||||
wattroff(win, A_REVERSE);
|
wattroff(win, A_REVERSE);
|
||||||
|
} else {
|
||||||
|
mvwprintw(win, i, 0, "%ld", i);
|
||||||
|
mvwprintw(win, i, offset, "%s", dir_content[i].file_name);
|
||||||
}
|
}
|
||||||
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
|
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
|
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
|
unsigned long selected_file_current;
|
||||||
|
unsigned long selected_file_last;
|
||||||
|
extern pthread_mutex_t mutex_selection;
|
||||||
|
|
||||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
|
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
|
||||||
if (*input == 'q') {
|
if (*input == 'q') {
|
||||||
@ -23,7 +27,19 @@ void user_interactions(char *input, unsigned int *status, unsigned int *settings
|
|||||||
} else if (*input == 'h') {
|
} else if (*input == 'h') {
|
||||||
chdir("..");
|
chdir("..");
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
|
} else if (*input == 't') {
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
/* capping the maximum file is done inside thread_mid */
|
||||||
|
selected_file_current++;
|
||||||
|
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
} else if (*input == 'n') {
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
if (selected_file_current != 0) {
|
||||||
|
selected_file_current--;
|
||||||
|
}
|
||||||
|
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
main.c
16
main.c
@ -30,9 +30,9 @@ int main() {
|
|||||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||||
WINDOW *win_t = newwin(1, terminal_width, 0, 0);
|
WINDOW *win_t = newwin(1, terminal_width, 0, 0);
|
||||||
WINDOW *win_b = newwin(1, terminal_width, terminal_height-1, 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_l = newwin(terminal_height-2, terminal_width/8, 1, 0);
|
||||||
WINDOW *win_m = newwin(terminal_height-2, terminal_width/3, 1, (terminal_width/3));
|
WINDOW *win_m = newwin(terminal_height-2, terminal_width/3, 1, (terminal_width/8));
|
||||||
WINDOW *win_r = newwin(terminal_height-2, terminal_width/3, 1, ((terminal_width/3)*2));
|
WINDOW *win_r = newwin(terminal_height-2, terminal_width/3, 1, ((terminal_width/2)));
|
||||||
|
|
||||||
pthread_t thread_b;
|
pthread_t thread_b;
|
||||||
pthread_t thread_t;
|
pthread_t thread_t;
|
||||||
@ -108,15 +108,15 @@ void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WIN
|
|||||||
|
|
||||||
wresize(win_t, 1, terminal_width);
|
wresize(win_t, 1, terminal_width);
|
||||||
wresize(win_b, terminal_height, terminal_width/3);
|
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/8);
|
||||||
wresize(win_l, terminal_height-2, terminal_width/3);
|
wresize(win_m, terminal_height-2, (terminal_width/2)-(terminal_width/8));
|
||||||
wresize(win_r, terminal_height-2, terminal_width/3);
|
wresize(win_r, terminal_height-2, terminal_width/2);
|
||||||
|
|
||||||
mvwin(win_t, 0, 0);
|
mvwin(win_t, 0, 0);
|
||||||
mvwin(win_b, terminal_height-1, 0);
|
mvwin(win_b, terminal_height-1, 0);
|
||||||
mvwin(win_l, 1, 0);
|
mvwin(win_l, 1, 0);
|
||||||
mvwin(win_m, 1, (terminal_width/3));
|
mvwin(win_m, 1, (terminal_width/8));
|
||||||
mvwin(win_r, 1, ((terminal_width/3)*2));
|
mvwin(win_r, 1, ((terminal_width/2)));
|
||||||
|
|
||||||
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
39
threading.c
39
threading.c
@ -12,22 +12,24 @@ pthread_mutex_t mutex_btm;
|
|||||||
pthread_mutex_t mutex_lft;
|
pthread_mutex_t mutex_lft;
|
||||||
pthread_mutex_t mutex_mid;
|
pthread_mutex_t mutex_mid;
|
||||||
pthread_mutex_t mutex_rgt;
|
pthread_mutex_t mutex_rgt;
|
||||||
|
pthread_mutex_t mutex_selection;
|
||||||
|
|
||||||
/* contains entire directory as 2d array
|
|
||||||
* may be changed in future to only include parts of the dir (currently includes entire dir) */
|
|
||||||
file *rgt_content;
|
file *rgt_content;
|
||||||
file *mid_content;
|
file *mid_content;
|
||||||
file *lft_content;
|
file *lft_content;
|
||||||
|
|
||||||
char *top_content; /* current path */
|
char *top_content; /* current path */
|
||||||
|
|
||||||
unsigned long rgt_file_count;
|
unsigned long rgt_file_count;
|
||||||
unsigned long mid_file_count;
|
unsigned long mid_file_count;
|
||||||
unsigned long lft_file_count;
|
unsigned long lft_file_count;
|
||||||
unsigned long top_width;
|
unsigned long top_width;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
|
extern unsigned long selected_file_current;
|
||||||
|
extern unsigned long selected_file_last;
|
||||||
|
|
||||||
void *thread_mid(void *data){
|
void *thread_mid(void *data){
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
@ -48,6 +50,18 @@ void *thread_mid(void *data){
|
|||||||
memset(mid_content, ' ', mid_file_count * sizeof(file));
|
memset(mid_content, ' ', mid_file_count * sizeof(file));
|
||||||
get_dir_content(path, &mid_file_count, mid_content);
|
get_dir_content(path, &mid_file_count, mid_content);
|
||||||
|
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
if (selected_file_current >= mid_file_count) {
|
||||||
|
selected_file_current = mid_file_count-1;
|
||||||
|
}
|
||||||
|
mid_content[selected_file_current].status = FILE_STATUS_HOVER;
|
||||||
|
if (selected_file_current != selected_file_last) {
|
||||||
|
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
||||||
|
}
|
||||||
|
selected_file_last = selected_file_current;
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
@ -58,6 +72,7 @@ void *thread_lft(void *data){
|
|||||||
|
|
||||||
free(lft_content);
|
free(lft_content);
|
||||||
|
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
if((path=getcwd(NULL, 0)) == NULL) {
|
||||||
lft_content = malloc(sizeof(file));
|
lft_content = malloc(sizeof(file));
|
||||||
@ -66,18 +81,13 @@ void *thread_lft(void *data){
|
|||||||
lft_file_count = 1;
|
lft_file_count = 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
char *parent ;
|
path[strrchr(path, '/')-path] = '\0';
|
||||||
if((parent = malloc(strlen(path)+strlen("/..")+1)) != NULL){
|
path[0] = '/';
|
||||||
parent[0] = '\0'; /* ensures empty string */
|
|
||||||
strcat(parent, path);
|
|
||||||
strcat(parent, "/..");
|
|
||||||
}
|
|
||||||
|
|
||||||
lft_file_count = (unsigned long)get_dir_size(parent);
|
lft_file_count = (unsigned long)get_dir_size(path);
|
||||||
lft_content = malloc(lft_file_count * sizeof(file));
|
lft_content = malloc(lft_file_count * sizeof(file));
|
||||||
memset(lft_content, ' ', lft_file_count * sizeof(file));
|
memset(lft_content, ' ', lft_file_count * sizeof(file));
|
||||||
get_dir_content(parent, &lft_file_count, lft_content);
|
get_dir_content(path, &lft_file_count, lft_content);
|
||||||
free(parent);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
@ -121,11 +131,12 @@ void threading_init(){
|
|||||||
|
|
||||||
top_content = malloc(sizeof(char));
|
top_content = malloc(sizeof(char));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_init(&mutex_top, NULL);
|
pthread_mutex_init(&mutex_top, NULL);
|
||||||
pthread_mutex_init(&mutex_mid, NULL);
|
pthread_mutex_init(&mutex_mid, NULL);
|
||||||
pthread_mutex_init(&mutex_lft, NULL);
|
pthread_mutex_init(&mutex_lft, NULL);
|
||||||
|
pthread_mutex_init(&mutex_selection, NULL);
|
||||||
|
selected_file_current = 0;
|
||||||
|
selected_file_last = 0;
|
||||||
}
|
}
|
||||||
void threading_free(){
|
void threading_free(){
|
||||||
free(rgt_content);
|
free(rgt_content);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user