implemented settings functionallity
This commit is contained in:
parent
965351968f
commit
26d3dc9bc8
@ -67,7 +67,8 @@ void *populate_dir(void *which){ // 0=left, 1=main, 2=right
|
||||
unsigned long longest_name = 0;
|
||||
|
||||
if (wh) {
|
||||
if (wh==1) {
|
||||
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++) {
|
||||
@ -76,6 +77,7 @@ void *populate_dir(void *which){ // 0=left, 1=main, 2=right
|
||||
*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++) {
|
||||
@ -85,6 +87,7 @@ void *populate_dir(void *which){ // 0=left, 1=main, 2=right
|
||||
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++) {
|
||||
|
@ -3,11 +3,15 @@
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void user_interactions(char *input, unsigned int *status) {
|
||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
|
||||
if (*input == 'q') {
|
||||
*status ^= 1;
|
||||
} else if (*input == *"KEY_BACKSPACE") {
|
||||
*settings ^= 1;
|
||||
} else if (*input == 'a') {
|
||||
*settings ^= 1;
|
||||
}
|
||||
else {
|
||||
*status ^= 2;
|
||||
}
|
||||
*status ^= 2;
|
||||
}
|
||||
|
@ -2,4 +2,4 @@
|
||||
#include <pthread.h>
|
||||
#include "interactions.c"
|
||||
|
||||
void user_interactions(char *input, unsigned int *status);
|
||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings);
|
||||
|
12
main.c
12
main.c
@ -9,7 +9,7 @@ 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 settings = 1;
|
||||
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
|
||||
@ -20,15 +20,19 @@ 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 ^= 1; //bit 0 = show_hidden_files
|
||||
status = 2; //update ui bit
|
||||
status ^= 2; //update ui bit
|
||||
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 & 1)){
|
||||
getmaxyx(stdscr, temp_heigth, temp_width);
|
||||
@ -51,7 +55,7 @@ int main() {
|
||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||
temp_heigth -= terminal_height;
|
||||
temp_width -= terminal_width;
|
||||
if (!temp_heigth || !temp_width || (status & 2)) {
|
||||
if (!temp_heigth || !temp_width || (status & 2)) { //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);
|
||||
@ -62,7 +66,7 @@ int main() {
|
||||
|
||||
|
||||
if ((input = getch())) {
|
||||
user_interactions(&input, &status);
|
||||
user_interactions(&input, &status, &settings);
|
||||
}
|
||||
}
|
||||
free(content_l);
|
||||
|
Loading…
x
Reference in New Issue
Block a user