added file previev
This commit is contained in:
parent
f7c1d34e05
commit
0053c7cb88
@ -63,6 +63,8 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
lstat(full_path, file);
|
lstat(full_path, file);
|
||||||
free(full_path);
|
free(full_path);
|
||||||
|
|
||||||
|
dir_content[i].file_size_bytes = file->st_size;
|
||||||
|
|
||||||
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;
|
||||||
dir_content[i].color_pair = COLOR_DIR;
|
dir_content[i].color_pair = COLOR_DIR;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#define STATUS_QUIT_PROGRAM 1
|
#define STATUS_QUIT_PROGRAM 1
|
||||||
#define STATUS_RUN_BACKEND 2
|
#define STATUS_RUN_BACKEND 2
|
||||||
#define STATUS_UPDATE_SCREEN_MASK 12 /* 1100*/
|
#define STATUS_RELOAD_DIRECTORY 4
|
||||||
#define STATUS_UPDATE_SCREEN_0 4
|
#define STATUS_UPDATE_SCREEN_MASK 24 /* 11000 */
|
||||||
#define STATUS_UPDATE_SCREEN_RESIZE 8
|
#define STATUS_UPDATE_SCREEN_0 8
|
||||||
#define STATUS_USER_ROOT 16
|
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
||||||
|
#define STATUS_USER_ROOT 32
|
||||||
|
|
||||||
#define SETTINGS_HAS_COLOR 1
|
#define SETTINGS_HAS_COLOR 1
|
||||||
|
|
||||||
|
@ -9,6 +9,9 @@ extern unsigned int file_modifiers;
|
|||||||
unsigned long selected_file_current;
|
unsigned long selected_file_current;
|
||||||
unsigned long selected_file_last;
|
unsigned long selected_file_last;
|
||||||
extern pthread_mutex_t mutex_selection;
|
extern pthread_mutex_t mutex_selection;
|
||||||
|
extern file *mid_content;
|
||||||
|
extern file *lft_content;
|
||||||
|
extern file *rgt_content;
|
||||||
|
|
||||||
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') {
|
||||||
@ -17,16 +20,16 @@ void user_interactions(char *input, unsigned int *status, unsigned int *settings
|
|||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
} else if (*input == 'a') {
|
} else if (*input == 'a') {
|
||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
} else if (*input == 'o') {
|
} else if (*input == 'o') {
|
||||||
file_modifiers ^= FILE_MODIFIERS_SORT_BITMASK;
|
file_modifiers ^= FILE_MODIFIERS_SORT_BITMASK;
|
||||||
} else if (*input == 'e') {
|
} else if (*input == 'e') {
|
||||||
file_modifiers ^= FILE_MODIFIERS_SORT_ALPHABETIC;
|
file_modifiers ^= FILE_MODIFIERS_SORT_ALPHABETIC;
|
||||||
} else if (*input == 'u') {
|
} else if (*input == 'u') {
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
} 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 | STATUS_RELOAD_DIRECTORY);
|
||||||
} else if (*input == 't') {
|
} else if (*input == 't') {
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
/* capping the maximum file is done inside thread_mid */
|
/* capping the maximum file is done inside thread_mid */
|
||||||
@ -40,6 +43,9 @@ void user_interactions(char *input, unsigned int *status, unsigned int *settings
|
|||||||
}
|
}
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
} else if (*input == 's') {
|
||||||
|
chdir(mid_content[selected_file_current].file_name);
|
||||||
|
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
main.c
11
main.c
@ -17,6 +17,7 @@ unsigned int temp_width = 0;
|
|||||||
unsigned int settings;
|
unsigned int settings;
|
||||||
unsigned int file_modifiers;
|
unsigned int file_modifiers;
|
||||||
unsigned int status;
|
unsigned int status;
|
||||||
|
unsigned int timeout_time = 0;
|
||||||
char input = 0;
|
char input = 0;
|
||||||
|
|
||||||
void render_pass(WINDOW *wint, WINDOW *winb, WINDOW *winl, WINDOW *winm, WINDOW *winr);
|
void render_pass(WINDOW *wint, WINDOW *winb, WINDOW *winl, WINDOW *winm, WINDOW *winr);
|
||||||
@ -60,6 +61,7 @@ int main() {
|
|||||||
pthread_cancel(thread_r);
|
pthread_cancel(thread_r);
|
||||||
threading = 0;
|
threading = 0;
|
||||||
status &= ~STATUS_RUN_BACKEND;
|
status &= ~STATUS_RUN_BACKEND;
|
||||||
|
status &= ~STATUS_RELOAD_DIRECTORY;
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
} else {
|
} else {
|
||||||
pthread_create(&thread_t, NULL, thread_top, win_t); /*top bar*/
|
pthread_create(&thread_t, NULL, thread_top, win_t); /*top bar*/
|
||||||
@ -72,7 +74,12 @@ int main() {
|
|||||||
}
|
}
|
||||||
if ((input = getch())) {
|
if ((input = getch())) {
|
||||||
user_interactions(&input, &status, &settings);
|
user_interactions(&input, &status, &settings);
|
||||||
|
timeout_time = 5;
|
||||||
|
} else {
|
||||||
|
timeout_time += 10;
|
||||||
}
|
}
|
||||||
|
timeout(timeout_time); /* blocking timeout of getch() */
|
||||||
|
|
||||||
|
|
||||||
render_pass(win_t, win_b, win_l, win_m, win_r);
|
render_pass(win_t, win_b, win_l, win_m, win_r);
|
||||||
|
|
||||||
@ -141,12 +148,12 @@ void init() {
|
|||||||
|
|
||||||
initscr(); /* start ncurses */
|
initscr(); /* start ncurses */
|
||||||
noecho(); /* hide keyboard input */
|
noecho(); /* hide keyboard input */
|
||||||
timeout(50); /*blocking timeout of getch()*/
|
timeout(timeout_time); /* blocking timeout of getch() */
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
||||||
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
if (getuid() == 0) {
|
if (getuid() == 0) {
|
||||||
status += STATUS_USER_ROOT;
|
status += STATUS_USER_ROOT;
|
||||||
}
|
}
|
||||||
|
38
threading.c
38
threading.c
@ -1,5 +1,6 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -34,7 +35,6 @@ 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);
|
||||||
|
|
||||||
free(mid_content);
|
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
if((path=getcwd(NULL, 0)) == NULL) {
|
||||||
@ -45,10 +45,13 @@ void *thread_mid(void *data){
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
|
free(mid_content);
|
||||||
mid_file_count = (unsigned long)get_dir_size(path);
|
mid_file_count = (unsigned long)get_dir_size(path);
|
||||||
mid_content = malloc(mid_file_count * sizeof(file));
|
mid_content = malloc(mid_file_count * sizeof(file));
|
||||||
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);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
@ -70,7 +73,6 @@ void *thread_mid(void *data){
|
|||||||
void *thread_lft(void *data){
|
void *thread_lft(void *data){
|
||||||
pthread_mutex_lock(&mutex_lft);
|
pthread_mutex_lock(&mutex_lft);
|
||||||
|
|
||||||
free(lft_content);
|
|
||||||
|
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
@ -84,10 +86,13 @@ void *thread_lft(void *data){
|
|||||||
path[strrchr(path, '/')-path] = '\0';
|
path[strrchr(path, '/')-path] = '\0';
|
||||||
path[0] = '/';
|
path[0] = '/';
|
||||||
|
|
||||||
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
|
free(lft_content);
|
||||||
lft_file_count = (unsigned long)get_dir_size(path);
|
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(path, &lft_file_count, lft_content);
|
get_dir_content(path, &lft_file_count, lft_content);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
@ -97,8 +102,37 @@ void *thread_lft(void *data){
|
|||||||
|
|
||||||
}
|
}
|
||||||
void *thread_rgt(void *data){
|
void *thread_rgt(void *data){
|
||||||
|
pthread_mutex_lock(&mutex_rgt);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mutex_mid);
|
||||||
|
char *path = mid_content[selected_file_current].file_name;
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
|
if (mid_content[selected_file_current].file_type == FILE_TYPE_DIR || mid_content[selected_file_current].file_type == FILE_TYPE_SYMLINK) {
|
||||||
|
free(rgt_content);
|
||||||
|
rgt_file_count = (unsigned long)get_dir_size(path);
|
||||||
|
rgt_content = malloc(rgt_file_count * sizeof(file));
|
||||||
|
memset(rgt_content, ' ', rgt_file_count * sizeof(file));
|
||||||
|
get_dir_content(path, &rgt_file_count, rgt_content);
|
||||||
|
} else if (mid_content[selected_file_current].file_type == FILE_TYPE_REGULAR) {
|
||||||
|
FILE *fp = fopen(mid_content[selected_file_current].file_name, "r");
|
||||||
|
unsigned long file_size = ftell(fp);
|
||||||
|
rewind(fp);
|
||||||
|
free(rgt_content);
|
||||||
|
rgt_content = malloc(sizeof(file));
|
||||||
|
rgt_content[0].file_name = malloc(file_size);
|
||||||
|
fgets(rgt_content[0].file_name, file_size, fp);
|
||||||
|
rgt_content[0].file_size_bytes = file_size;
|
||||||
|
rgt_content[0].file_type = FILE_TYPE_REGULAR;
|
||||||
|
rgt_content[0].file_name_width = file_size;
|
||||||
|
rgt_content[0].color_pair = 0;
|
||||||
|
rgt_content[0].status = 0;
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
void *thread_top(void *data){
|
void *thread_top(void *data){
|
||||||
|
9
window.c
9
window.c
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
|
|
||||||
|
extern unsigned int timeout_time;
|
||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
|
|
||||||
@ -88,13 +89,7 @@ void window_rgt(WINDOW *win){
|
|||||||
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
print_dir(win, &rgt_file_count, rgt_content);
|
||||||
for (i = 0; i < color_count; i++) {
|
|
||||||
wattron(win, COLOR_PAIR(colors[i].color_pair));
|
|
||||||
mvwprintw(win, i, 0, "%d", colors[i].color_pair);
|
|
||||||
mvwaddstr(win, i, 3,colors[i].file_extension);
|
|
||||||
wattroff(win, COLOR_PAIR(colors[i].color_pair));
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user