Compare commits

...

No commits in common. "bcd7acbd080d76fc8ada4a7e8555ad85654285ec" and "72189ba5c7282479ae77c24f45585706dce1fa71" have entirely different histories.

9 changed files with 0 additions and 290 deletions

View File

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

View File

@ -1,96 +0,0 @@
#include <curses.h>
#include <string.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include "defines.h"
extern unsigned int settings;
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){
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) {
struct dirent *entry;
while ( (entry=readdir(dir)) ) {
if (entry->d_name[0] != '.' && !(settings & SETTINGS_HIDDEN_FILES)) {
index++;
} else if (settings & SETTINGS_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] != '.' && !(settings & SETTINGS_HIDDEN_FILES)) {
strcpy(dir_content[index], entry->d_name);
index++;
} else if (settings & SETTINGS_HIDDEN_FILES) {
strcpy(dir_content[index], entry->d_name);
index++;
}
}
}
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);
}
}
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);
} 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);
}
} 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);
}
return NULL;
}

View File

@ -1,8 +0,0 @@
#include <curses.h>
#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 *populate_dir(void *dir);

View File

@ -1,17 +0,0 @@
#include <curses.h>
#include <dirent.h>
#include <unistd.h>
#include "defines.h"
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
if (*input == 'q') {
*status ^= STATUS_QUIT_PROGRAM;
} else if (*input == *"KEY_BACKSPACE") {
*settings ^= SETTINGS_HIDDEN_FILES;
} else if (*input == 'a') {
*settings ^= SETTINGS_HIDDEN_FILES;
}
else {
}
*status ^= STATUS_RUN_BACKEND;
}

View File

@ -1,5 +0,0 @@
#include <curses.h>
#include <pthread.h>
#include "interactions.c"
void user_interactions(char *input, unsigned int *status, unsigned int *settings);

80
main.c
View File

@ -1,80 +0,0 @@
#include <curses.h>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.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 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 = ".";
int main() {
initscr(); //start ncurses
timeout(50); //blocking timeout of getch()
keypad(stdscr, TRUE);
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));
settings ^= SETTINGS_HIDDEN_FILES;
status ^= STATUS_RUN_BACKEND;
char input = 0;
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));
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 ((input = getch())) {
user_interactions(&input, &status, &settings);
}
}
free(content_l);
free(content_m);
free(content_r);
endwin();
return 0;
}

BIN
th

Binary file not shown.

View File

@ -1,72 +0,0 @@
#include <curses.h>
#include <dirent.h>
#include "backend.h"
extern unsigned int terminal_height;
extern unsigned int terminal_width;
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);
}
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_right(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
wmove(win, 0, 0);
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, local_height/2, local_width/2);
wprintw(win, "%d,%d", local_height, local_width);
box(win,0,0);
wrefresh(win);
}

View File

@ -1,7 +0,0 @@
#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);