Compare commits
63 Commits
7f0e65eaf3
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
47357e039d | ||
|
ecce6031a4 | ||
|
e5a2e429f0 | ||
|
1a67c5b4d0 | ||
|
af5a451ec2 | ||
|
a99a519834 | ||
|
6daeaebb5a | ||
|
d9ae5c79af | ||
|
2105bb4fe5 | ||
|
b9c254a0fe | ||
|
4092446825 | ||
|
bd31ffd17d | ||
|
c9c00f4930 | ||
|
d96046ac44 | ||
|
b6f9633677 | ||
|
7fcd148dfe | ||
|
4c958dc10a | ||
|
bc6fb162c5 | ||
|
b77c9a2a29 | ||
|
3f8fdc9e17 | ||
|
b2b100727f | ||
|
bc2989b2d9 | ||
|
47470e4e64 | ||
|
05ba7c82a0 | ||
|
322a1495c0 | ||
|
88beeffafe | ||
|
5185e74441 | ||
|
ab5b466336 | ||
|
36fd160ccb | ||
|
142f75d98a | ||
|
539af5fd65 | ||
|
f320449572 | ||
|
0a6509310d | ||
|
aedfdd1ed5 | ||
|
f2eaeee9ea | ||
|
01fe19866c | ||
|
36ff54038e | ||
|
1a64b83703 | ||
|
c9051b2565 | ||
|
1a68fee59c | ||
|
c29870998e | ||
|
3eb1c0f93e | ||
|
e07ec0b413 | ||
|
f99035629a | ||
|
1485d69cad | ||
|
e7b45579b1 | ||
|
b1eecad13c | ||
|
797f9a7d3b | ||
|
1f3a55df4b | ||
|
c1f2f7602a | ||
|
7c9af0d340 | ||
|
d2bde3a31c | ||
|
188ecb7f57 | ||
|
dc67be11dc | ||
|
f792399d44 | ||
|
f42429de89 | ||
|
bc2bc8fce0 | ||
|
0053c7cb88 | ||
|
f7c1d34e05 | ||
|
3d3052e436 | ||
|
0574732a69 | ||
|
2b52329904 | ||
|
bab921dea2 |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
|
!*.c
|
||||||
|
!*.h
|
||||||
|
!LICENSE
|
||||||
|
!Makefile
|
23
Makefile
23
Makefile
@@ -1,5 +1,24 @@
|
|||||||
|
CC := gcc
|
||||||
|
CFLAGS := -Wall -Wextra -O2 -flto=auto
|
||||||
|
CURSES := -lncursesw -ltinfow #utf8 support
|
||||||
|
#CURSES := -lncurses -tinfo #no utf8
|
||||||
|
CFLAGS_DEBUG := $(CFLAGS) -g
|
||||||
|
GDB := gdb --tui ./th
|
||||||
|
VALGRIND := valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --log-fd=9 9>>valgrind.log ./th
|
||||||
|
HELGRIND := valgrind --tool=helgrind --log-fd=9 9>>helgrind.log ./th
|
||||||
|
|
||||||
|
|
||||||
all:
|
all:
|
||||||
gcc ./main.c -std=c89 -o th -lncurses -ltinfo -Wall
|
$(CC) ./main.c -o th -std=c89 $(CFLAGS) $(CURSES)
|
||||||
|
|
||||||
d:
|
d:
|
||||||
gcc -g -std=c89 ./main.c -o th -lncurses -ltinfo -Wall && gdb --tui ./th
|
$(CC) ./main.c -o th -std=c89 $(CFLAGS_DEBUG) $(CURSES)
|
||||||
|
$(GDB)
|
||||||
|
|
||||||
|
v:
|
||||||
|
$(CC) ./main.c -o th -std=c89 $(CFLAGS_DEBUG) $(CURSES)
|
||||||
|
$(VALGRIND)
|
||||||
|
|
||||||
|
h:
|
||||||
|
$(CC) ./main.c -o th -std=c89 $(CFLAGS_DEBUG) $(CURSES)
|
||||||
|
$(HELGRIND)
|
||||||
|
187
backend.c
187
backend.c
@@ -12,7 +12,20 @@
|
|||||||
extern unsigned int settings;
|
extern unsigned int settings;
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
|
extern unsigned int terminal_height;
|
||||||
|
extern volatile unsigned long selected_file_current;
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
|
int (*order_func)() = sort_natural;
|
||||||
|
|
||||||
|
|
||||||
|
char* concat(const char *s1, const char *s2){
|
||||||
|
const size_t len1 = strlen(s1);
|
||||||
|
const size_t len2 = strlen(s2);
|
||||||
|
char *result = malloc(len1 + len2 + 1);
|
||||||
|
memcpy(result, s1, len1);
|
||||||
|
memcpy(result + len1, s2, len2 + 1);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long get_dir_size(char *path){
|
unsigned long get_dir_size(char *path){
|
||||||
@@ -27,6 +40,10 @@ unsigned long get_dir_size(char *path){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||||
|
/* removes files "." and ".." */
|
||||||
|
entry_count -= 2;
|
||||||
|
}
|
||||||
return entry_count;
|
return entry_count;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -34,39 +51,53 @@ unsigned long get_dir_size(char *path){
|
|||||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
|
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
|
||||||
struct dirent **entry;
|
struct dirent **entry;
|
||||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
||||||
scandir(path, &entry, NULL, alphasort);
|
scandir(path, &entry, skip_dot, alphasort);
|
||||||
} else {
|
} else {
|
||||||
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 = malloc(strlen(entry[i]->d_name)+1);
|
||||||
dir_content[i].file_name = malloc(sizeof(entry[i]->d_name));
|
strcpy(dir_content[i].file_name, entry[i]->d_name);
|
||||||
dir_content[i].file_name = entry[i]->d_name;
|
dir_content[i].file_name[strlen(entry[i]->d_name)] = '\0';
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
dir_content[i].file_size = file->st_size;
|
||||||
|
dir_content[i].permissions = 1;
|
||||||
|
dir_content[i].permissions = file->st_mode;
|
||||||
|
|
||||||
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;
|
||||||
|
dir_content[i].file_size = get_dir_size(full_path);
|
||||||
|
} else if (S_ISLNK(file->st_mode)) {
|
||||||
|
dir_content[i].file_type = FILE_TYPE_SYMLINK;
|
||||||
|
dir_content[i].color_pair = COLOR_SYMLINK;
|
||||||
|
dir_content[i].file_size = get_dir_size(full_path);
|
||||||
} else if (file->st_mode & S_IXUSR) {
|
} else if (file->st_mode & S_IXUSR) {
|
||||||
dir_content[i].file_type = FILE_TYPE_EXEC;
|
dir_content[i].file_type = FILE_TYPE_EXEC;
|
||||||
dir_content[i].color_pair = COLOR_EXEC;
|
dir_content[i].color_pair = COLOR_EXEC;
|
||||||
} else if (S_ISBLK(file->st_mode)) {
|
} else if (S_ISBLK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_BLOCK;
|
dir_content[i].file_type = FILE_TYPE_BLOCK;
|
||||||
dir_content[i].color_pair = COLOR_BLOCK;
|
dir_content[i].color_pair = COLOR_BLOCK;
|
||||||
/*} else if (S_ISCHR(file->st_mode)) {
|
} else if (S_ISCHR(file->st_mode)) {
|
||||||
dir_content[i].file_type = COLOR_CHARDEV; */
|
dir_content[i].file_type = COLOR_CHARDEV;
|
||||||
} else if (S_ISLNK(file->st_mode)) {
|
|
||||||
dir_content[i].file_type = FILE_TYPE_SYMLINK;
|
|
||||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
|
||||||
} else if (S_ISFIFO(file->st_mode)) {
|
} else if (S_ISFIFO(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_FIFO;
|
dir_content[i].file_type = FILE_TYPE_FIFO;
|
||||||
dir_content[i].color_pair = COLOR_FIFO;
|
dir_content[i].color_pair = COLOR_FIFO;
|
||||||
@@ -100,10 +131,12 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(full_path);
|
||||||
free(file);
|
free(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qsort(dir_content, *dir_file_count, sizeof(file), sort_natural);
|
|
||||||
|
qsort(dir_content, *dir_file_count, sizeof(file), order_func);
|
||||||
|
|
||||||
for (i = 0; i < *dir_file_count; i++) {
|
for (i = 0; i < *dir_file_count; i++) {
|
||||||
free(entry[i]);
|
free(entry[i]);
|
||||||
@@ -112,19 +145,135 @@ 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, char print_info, unsigned long *dir_file_count, file *dir_content){
|
||||||
|
/* i am not proud of this function */
|
||||||
|
unsigned long line_width = getmaxx(win);
|
||||||
|
|
||||||
|
char *bg = malloc(line_width+1);
|
||||||
|
memset(bg, ' ', line_width);
|
||||||
|
bg[line_width] = '\0';
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < *dir_file_count; i++) {
|
float file_size;
|
||||||
wattron(win, COLOR_PAIR(dir_content[i].color_pair));
|
float printed_size = 0;
|
||||||
|
char size_char = ' ';
|
||||||
|
char is_selected = 0;
|
||||||
|
static const char sizes[6] = { 'B', 'K', 'M', 'G', 'T', 'P' };
|
||||||
|
|
||||||
|
unsigned long offset_vertical = 0;
|
||||||
|
unsigned long offset_back = 0;
|
||||||
|
unsigned long offset_front = 2;
|
||||||
|
if (print_info) {
|
||||||
|
if (*dir_file_count > 9) {
|
||||||
|
offset_front = (snprintf(NULL, 0, "%ld", *dir_file_count)) + 1;
|
||||||
|
}
|
||||||
|
if (selected_file_current > (terminal_height/3)*2) {
|
||||||
|
if (selected_file_current + (terminal_height/3) >= *dir_file_count) {
|
||||||
|
offset_vertical = *dir_file_count - terminal_height+2;
|
||||||
|
} else {
|
||||||
|
offset_vertical = selected_file_current - (terminal_height/3)*2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) {
|
||||||
|
if (print_info) {
|
||||||
|
file_size = dir_content[i].file_size;
|
||||||
|
char size_index = 0;
|
||||||
|
while (file_size > 1) {
|
||||||
|
printed_size=file_size;
|
||||||
|
file_size /= 1024;
|
||||||
|
size_index++;
|
||||||
|
if (size_index >= 6) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size_char = sizes[size_index-1];
|
||||||
|
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
|
||||||
|
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1);
|
||||||
|
} else if (size_char =='B') {
|
||||||
|
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
||||||
|
} else {
|
||||||
|
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
is_selected = 1;
|
||||||
|
} else {
|
||||||
|
is_selected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
wattron(win, COLOR_PAIR(8));
|
||||||
|
} else {
|
||||||
|
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, "%d", dir_content[i].color_pair);
|
|
||||||
mvwaddstr(win, i, 3,dir_content[i].file_name);
|
/* shortens the printed file name if it is too long
|
||||||
|
* example input: aaaaaaaa.txt
|
||||||
|
* example output: aaa~.txt
|
||||||
|
* if no extension is found, the name will truncate */
|
||||||
|
char *file_name;
|
||||||
|
unsigned long file_name_width = strlen(dir_content[i].file_name);
|
||||||
|
if ((file_name_width + offset_front + is_selected) > offset_back - 1) {
|
||||||
|
char *extension = strrchr(dir_content[i].file_name, '.');
|
||||||
|
if (extension) {
|
||||||
|
int char_offset = (file_name_width + offset_front + is_selected) - (offset_back - 1) ;
|
||||||
|
if ((file_name_width - char_offset - strlen(extension) - 1) > 1) {
|
||||||
|
file_name = malloc(file_name_width - char_offset + 1);
|
||||||
|
memcpy(file_name, dir_content[i].file_name, file_name_width - char_offset);
|
||||||
|
memcpy(file_name + (file_name_width - char_offset - strlen(extension)), extension, strlen(extension));
|
||||||
|
file_name[file_name_width - char_offset - strlen(extension) - 1] = '~';
|
||||||
|
file_name[file_name_width - char_offset] = '\0';
|
||||||
|
} else {
|
||||||
|
file_name = malloc(strlen(extension)+1);
|
||||||
|
file_name[0] = '~';
|
||||||
|
memcpy(file_name+1, extension, strlen(extension));
|
||||||
|
file_name[strlen(extension)] = '\0';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
file_name = malloc(file_name_width+1);
|
||||||
|
memcpy(file_name, dir_content[i].file_name, file_name_width);
|
||||||
|
file_name[file_name_width] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
file_name = malloc(file_name_width+1);
|
||||||
|
memcpy(file_name, dir_content[i].file_name, file_name_width);
|
||||||
|
file_name[file_name_width] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
mvwaddstr(win, i-offset_vertical, 0, bg);
|
||||||
|
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
|
||||||
|
if(print_info) {
|
||||||
|
mvwprintw(win, i-offset_vertical, 0, "%ld", i);
|
||||||
|
free(file_name);
|
||||||
|
|
||||||
|
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
|
||||||
|
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
||||||
|
}else if (size_char =='B') {
|
||||||
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
||||||
|
} else {
|
||||||
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
|
||||||
|
free(file_name);
|
||||||
|
}
|
||||||
|
|
||||||
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
||||||
wattroff(win, A_REVERSE);
|
wattroff(win, A_REVERSE);
|
||||||
}
|
}
|
||||||
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
wattroff(win, COLOR_PAIR(8));
|
||||||
|
} else {
|
||||||
|
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
free(bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
unsigned long get_dir_size(char *path);
|
unsigned long get_dir_size(char *path);
|
||||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
||||||
void print_dir(WINDOW *win, unsigned long *dir_file_count, file *dir_content);
|
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
|
||||||
|
47
colors.c
47
colors.c
@@ -1,6 +1,7 @@
|
|||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#include <bits/types/FILE.h>
|
#include <bits/types/FILE.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
@@ -49,78 +50,64 @@ void colors_init() {
|
|||||||
|
|
||||||
FILE *dircolors = fopen("/etc/DIR_COLORS", "r");
|
FILE *dircolors = fopen("/etc/DIR_COLORS", "r");
|
||||||
if (dircolors) {
|
if (dircolors) {
|
||||||
char *line;
|
char *line = NULL;
|
||||||
char *token;
|
char *token;
|
||||||
char *extension;
|
char *extension;
|
||||||
int tmp = 0;
|
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
short fg;
|
short fg;
|
||||||
short bg;
|
short bg;
|
||||||
|
|
||||||
char supported_filetype_count = 9;
|
while (getline(&line, &size, dircolors) != -1) {
|
||||||
char initial_pass = 0;
|
|
||||||
while ((tmp = getline(&line, &size, dircolors)) != -1 && initial_pass != supported_filetype_count) {
|
|
||||||
fg = 7;
|
fg = 7;
|
||||||
bg = 0;
|
bg = 0;
|
||||||
token = strtok(line, " ");
|
token = strtok(line, " ");
|
||||||
if (token[0] != '#' && token[0] != '\n') {
|
if (token[0] != '#' && token[0] != '\n') {
|
||||||
if (!strcmp(token, "DIR")) {
|
if (line[0] == '.') {
|
||||||
initial_pass++;
|
color_count++;
|
||||||
|
} else if (!strcmp(token, "DIR")) {
|
||||||
parse_colors(line, &fg, &bg);
|
parse_colors(line, &fg, &bg);
|
||||||
init_pair(1, fg, bg); /* directory */
|
init_pair(1, fg, bg); /* directory */
|
||||||
} else if (!strcmp(token, "EXEC")){
|
|
||||||
initial_pass++;
|
|
||||||
parse_colors(line, &fg, &bg);
|
|
||||||
init_pair(2, fg, bg); /* exec */
|
|
||||||
} else if (!strcmp(token, "RESET")){
|
|
||||||
initial_pass++;
|
|
||||||
parse_colors(line, &fg, &bg);
|
|
||||||
init_pair(3, fg, bg); /* regular file */
|
|
||||||
} else if (!strcmp(token, "LINK")){
|
} else if (!strcmp(token, "LINK")){
|
||||||
initial_pass++;
|
|
||||||
parse_colors(line, &fg, &bg);
|
parse_colors(line, &fg, &bg);
|
||||||
init_pair(4, fg, bg); /* symlink */
|
init_pair(2, fg, bg); /* symlink */
|
||||||
|
} else if (!strcmp(token, "EXEC")){
|
||||||
|
parse_colors(line, &fg, &bg);
|
||||||
|
init_pair(3, fg, bg); /* exec */
|
||||||
|
} else if (!strcmp(token, "RESET")){
|
||||||
|
parse_colors(line, &fg, &bg);
|
||||||
|
init_pair(4, fg, bg); /* regular file */
|
||||||
} else if (!strcmp(token, "BLK")){
|
} else if (!strcmp(token, "BLK")){
|
||||||
initial_pass++;
|
|
||||||
parse_colors(line, &fg, &bg);
|
parse_colors(line, &fg, &bg);
|
||||||
init_pair(5, fg, bg); /* block device */
|
init_pair(5, fg, bg); /* block device */
|
||||||
} else if (!strcmp(token, "CHR")){
|
} else if (!strcmp(token, "CHR")){
|
||||||
initial_pass++;
|
|
||||||
parse_colors(line, &fg, &bg);
|
parse_colors(line, &fg, &bg);
|
||||||
init_pair(6, fg, bg); /* character device */
|
init_pair(6, fg, bg); /* character device */
|
||||||
} else if (!strcmp(token, "SOCK")){
|
} else if (!strcmp(token, "SOCK")){
|
||||||
initial_pass++;
|
|
||||||
parse_colors(line, &fg, &bg);
|
parse_colors(line, &fg, &bg);
|
||||||
init_pair(7, fg, bg); /* socket */
|
init_pair(7, fg, bg); /* socket */
|
||||||
} else if (!strcmp(token, "FIFO")){
|
} else if (!strcmp(token, "FIFO")){
|
||||||
initial_pass++;
|
|
||||||
parse_colors(line, &fg, &bg);
|
parse_colors(line, &fg, &bg);
|
||||||
init_pair(8, fg, bg); /* fifo */
|
init_pair(8, fg, bg); /* fifo */
|
||||||
} else if (!strcmp(token, "ORPHAN")){
|
} else if (!strcmp(token, "ORPHAN")){
|
||||||
initial_pass++;
|
|
||||||
parse_colors(line, &fg, &bg);
|
parse_colors(line, &fg, &bg);
|
||||||
init_pair(9, fg, bg); /* orphan */
|
init_pair(9, fg, bg); /* orphan */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* checks for only extensions (*.[extension], includes the '.') as the filetypes are handled seperately */
|
|
||||||
while ((tmp = getline(&line, &size, dircolors)) != -1) {
|
|
||||||
if (line[0] == '.') {
|
|
||||||
color_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rewind(dircolors);
|
rewind(dircolors);
|
||||||
|
|
||||||
|
/*is it a leak when its intentional?*/
|
||||||
colors = malloc(sizeof(color) * color_count);
|
colors = malloc(sizeof(color) * color_count);
|
||||||
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
/* proper pass, reads all defined extensions within /etc/DIR_COLORS */
|
/* proper pass, reads all defined extensions within /etc/DIR_COLORS */
|
||||||
while ((tmp = getline(&line, &size, dircolors)) != -1) {
|
while (getline(&line, &size, dircolors) != -1) {
|
||||||
fg = 7;
|
fg = 7;
|
||||||
bg = 0;
|
bg = 0;
|
||||||
if (line[0] == '.') {
|
if (line[0] == '.') {
|
||||||
extension = strtok(line, " ");
|
extension = strtok(line, " ");
|
||||||
colors[i].file_extension = malloc(sizeof(extension));
|
colors[i].file_extension = malloc(strlen(extension)+1);
|
||||||
strcpy(colors[i].file_extension, extension);
|
strcpy(colors[i].file_extension, extension);
|
||||||
|
|
||||||
colors[i].color_pair = i+11;
|
colors[i].color_pair = i+11;
|
||||||
|
81
config.h
Normal file
81
config.h
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#include "defines.h"
|
||||||
|
#include "interactions.h"
|
||||||
|
#include "sorting.h"
|
||||||
|
|
||||||
|
|
||||||
|
static const mimetype mimetype_default_cmd[] = {
|
||||||
|
/* mimetype shell command
|
||||||
|
* ^ substring of "file --mime-type -b ./hovered"
|
||||||
|
* this does mean that this list is checked for completely linear.
|
||||||
|
* Example:
|
||||||
|
* file --mime-type -b ./image.gif
|
||||||
|
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
|
||||||
|
* we need to define "gif" before "image" */
|
||||||
|
{ "text", "$EDITOR" },
|
||||||
|
{ "gif", "mpv --loop-file=\"inf\"" },
|
||||||
|
{ "image", "feh" },
|
||||||
|
{ "video", "mpv" },
|
||||||
|
{ "audio", "mpv" }
|
||||||
|
};
|
||||||
|
static const extension file_extension_default_cmd[] = {
|
||||||
|
/* extension shell command
|
||||||
|
* similar to mimetype_default_cmd, however it searches for exact string matches
|
||||||
|
* and is checked before mimetype_default_cmd */
|
||||||
|
{ ".exe", "wine"},
|
||||||
|
};
|
||||||
|
static const binding key_binding[] = {
|
||||||
|
/*key action blackmagic comment*/
|
||||||
|
/*you cannot add bindings that include other bindings in its entirety
|
||||||
|
* possible: mk, mf
|
||||||
|
* not possible: gg, ggg
|
||||||
|
* trying to use ggg will always fail as it will execute gg first instead, resetting the input buffer, thus never reaching ggg */
|
||||||
|
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
|
||||||
|
{ "q", quit_program, NULL, "quit" },
|
||||||
|
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
||||||
|
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||||
|
{ "/", not_implemented, NULL, "search" },
|
||||||
|
|
||||||
|
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
|
||||||
|
{ "t", move_down, NULL, "move down" },
|
||||||
|
{ "n", move_up, NULL, "move up" },
|
||||||
|
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||||
|
|
||||||
|
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
|
||||||
|
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||||
|
{ "d", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
||||||
|
* this means that it does not delete the hovered files if files are already selected */
|
||||||
|
|
||||||
|
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
||||||
|
{ "gg", jump_top, NULL, "jump to first file in dir" },
|
||||||
|
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
||||||
|
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
|
||||||
|
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
||||||
|
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
||||||
|
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
|
||||||
|
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
||||||
|
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
||||||
|
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
||||||
|
|
||||||
|
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
||||||
|
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
||||||
|
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
|
||||||
|
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
|
||||||
|
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
|
||||||
|
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
|
||||||
|
|
||||||
|
{ "on", order_by, sort_natural, "order natural" },
|
||||||
|
{ "or", not_implemented, "", "order reverse" },
|
||||||
|
{ "oe", not_implemented, "", "order extension" },
|
||||||
|
{ "os", order_by, sort_size, "order size" },
|
||||||
|
{ "ot", order_by, sort_type, "order type" },
|
||||||
|
{ "oz", order_by, sort_random, "order random" },
|
||||||
|
{ "oa", order_by, sort_alpha, "order alphabetically" },
|
||||||
|
|
||||||
|
{ "mk", makedir, NULL, "create directory" },
|
||||||
|
{ "mf", makefile, NULL, "create file" },
|
||||||
|
|
||||||
|
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
|
||||||
|
};
|
||||||
|
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
||||||
|
static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
|
||||||
|
static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension);
|
49
defines.h
49
defines.h
@@ -1,9 +1,13 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#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_UPDATE_SCREEN_RELOAD_FULL 32
|
||||||
|
#define STATUS_USER_ROOT 64
|
||||||
|
|
||||||
#define SETTINGS_HAS_COLOR 1
|
#define SETTINGS_HAS_COLOR 1
|
||||||
|
|
||||||
@@ -18,14 +22,16 @@
|
|||||||
/*FILE_MODIFIERS_SORT_NATURAL is when bitmask is 0*/
|
/*FILE_MODIFIERS_SORT_NATURAL is when bitmask is 0*/
|
||||||
|
|
||||||
#define FILE_STATUS_HOVER 1
|
#define FILE_STATUS_HOVER 1
|
||||||
#define FILE_STATUS_SELECTED 2;
|
#define FILE_STATUS_SELECTED 2
|
||||||
#define FILE_STATUS_IS_REGULAR_FILE 4
|
#define FILE_STATUS_IS_REGULAR_FILE 4
|
||||||
|
#define FILE_STATUS_DIR_EMPTY 64 /* if a directory is empty */
|
||||||
|
#define FILE_STATUS_FILE_OPEN 128 /* only used for file previews */
|
||||||
|
|
||||||
#define COLOR_UNKNOWN 0
|
#define COLOR_UNKNOWN 0
|
||||||
#define COLOR_DIR 1
|
#define COLOR_DIR 1
|
||||||
#define COLOR_EXEC 2 /* not really a filetype, moreso if it is executable */
|
#define COLOR_SYMLINK 2
|
||||||
#define COLOR_REGULAR 3
|
#define COLOR_EXEC 3 /* not really a filetype, moreso if it is executable */
|
||||||
#define COLOR_SYMLINK 4
|
#define COLOR_REGULAR 4
|
||||||
#define COLOR_BLOCK 5
|
#define COLOR_BLOCK 5
|
||||||
#define COLOR_CHARDEV 6
|
#define COLOR_CHARDEV 6
|
||||||
#define COLOR_SOCK 7
|
#define COLOR_SOCK 7
|
||||||
@@ -43,22 +49,37 @@
|
|||||||
#define FILE_TYPE_SOCK COLOR_SOCK
|
#define FILE_TYPE_SOCK COLOR_SOCK
|
||||||
#define FILE_TYPE_FIFO COLOR_FIFO
|
#define FILE_TYPE_FIFO COLOR_FIFO
|
||||||
#define FILE_TYPE_ORPHAN COLOR_ORPHAN
|
#define FILE_TYPE_ORPHAN COLOR_ORPHAN
|
||||||
|
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
|
||||||
|
|
||||||
#ifndef GUARD
|
#ifndef STRUCT_GUARD
|
||||||
#define GUARD
|
#define STRUCT_GUARD
|
||||||
|
|
||||||
/* complex types are good actually */
|
/* complex types are good actually */
|
||||||
typedef struct File {
|
typedef struct File {
|
||||||
char status;
|
char status;
|
||||||
char *file_name;
|
|
||||||
unsigned char file_type;
|
unsigned char file_type;
|
||||||
unsigned short color_pair;
|
unsigned short color_pair;
|
||||||
unsigned long file_name_width;
|
unsigned short permissions;
|
||||||
unsigned long file_size_bytes;
|
unsigned long file_size; /*if its a file, its in bytes, if its a dir, its the count of files within that dir */
|
||||||
|
char *file_name;
|
||||||
} file;
|
} file;
|
||||||
typedef struct Color {
|
typedef struct Color {
|
||||||
char *file_extension;
|
char *file_extension;
|
||||||
short color_pair;
|
short color_pair;
|
||||||
} color;
|
} color;
|
||||||
|
typedef struct Mimetype {
|
||||||
|
char *mimetype;
|
||||||
|
char *command;
|
||||||
|
} mimetype;
|
||||||
|
typedef struct Extension {
|
||||||
|
char *file_extension;
|
||||||
|
char *command;
|
||||||
|
} extension;
|
||||||
|
typedef struct Binding {
|
||||||
|
char* key;
|
||||||
|
void (*func)();
|
||||||
|
void* black_magic;
|
||||||
|
char* comment;
|
||||||
|
} binding;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
75
file_previews.c
Normal file
75
file_previews.c
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
|
||||||
|
char* text(char *path, unsigned long *file_size);
|
||||||
|
char* generic(char *path);
|
||||||
|
|
||||||
|
char* get_mimetype(char *path){
|
||||||
|
static char *cmd_str = "file --mime-type -b ./\"";
|
||||||
|
unsigned long cmd_len = strlen(cmd_str);
|
||||||
|
unsigned int path_len = strlen(path);
|
||||||
|
|
||||||
|
char *cmd = malloc((cmd_len + path_len) + 2);
|
||||||
|
memset(cmd, ' ', cmd_len + path_len);
|
||||||
|
memcpy(cmd, cmd_str, cmd_len);
|
||||||
|
memcpy(cmd + cmd_len, path, path_len);
|
||||||
|
cmd[cmd_len + path_len] = '\"';
|
||||||
|
cmd[cmd_len + path_len + 1] = '\0';
|
||||||
|
|
||||||
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
|
char *line;
|
||||||
|
size_t size = 0;
|
||||||
|
if (getline(&line, &size, cmd_open) != -1){
|
||||||
|
pclose(cmd_open);
|
||||||
|
return line;
|
||||||
|
} else {
|
||||||
|
pclose(cmd_open);
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char* preview_file(file *file_current){
|
||||||
|
/* this calls "file" on path */
|
||||||
|
|
||||||
|
char *file_buffer;
|
||||||
|
|
||||||
|
|
||||||
|
char *mime = get_mimetype(file_current->file_name);
|
||||||
|
|
||||||
|
if (strstr(mime, "text")) {
|
||||||
|
file_buffer = text(file_current->file_name, &file_current->file_size);
|
||||||
|
} else {
|
||||||
|
file_buffer = generic(file_current->file_name);
|
||||||
|
}
|
||||||
|
free(mime);
|
||||||
|
return file_buffer;
|
||||||
|
|
||||||
|
}
|
||||||
|
char* text(char *path, unsigned long *file_size){
|
||||||
|
|
||||||
|
char *file_buffer = malloc(*file_size + 1);
|
||||||
|
FILE *fp = fopen(path, "r");
|
||||||
|
if (fread(file_buffer, *file_size, 1, fp) != 0) {
|
||||||
|
file_buffer[*file_size] = '\0';
|
||||||
|
return file_buffer;
|
||||||
|
} else {
|
||||||
|
return "failed reading file";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char* generic(char *path){
|
||||||
|
char *cmd = concat("file ./\"", path);
|
||||||
|
cmd = concat(cmd, "\"");
|
||||||
|
|
||||||
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
|
char *line;
|
||||||
|
size_t size = 0;
|
||||||
|
if (getline(&line, &size, cmd_open) != -1) {
|
||||||
|
pclose(cmd_open);
|
||||||
|
return line;
|
||||||
|
} else {
|
||||||
|
pclose(cmd_open);
|
||||||
|
return "failed executing shell command \"file\"";
|
||||||
|
}
|
||||||
|
}
|
5
file_previews.h
Normal file
5
file_previews.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#include "file_previews.c"
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
char* preview_file(file *file_current);
|
||||||
|
char* get_mimetype(char *path);
|
611
interactions.c
611
interactions.c
@@ -1,29 +1,604 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern volatile unsigned long selected_file_current;
|
||||||
|
extern volatile unsigned long selected_file_last;
|
||||||
|
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
|
extern pthread_mutex_t mutex_selection;
|
||||||
|
extern pthread_mutex_t mutex_rgt;
|
||||||
|
extern pthread_mutex_t mutex_mid;
|
||||||
|
extern file *mid_content;
|
||||||
|
extern file *lft_content;
|
||||||
|
extern file *rgt_content;
|
||||||
|
extern volatile file *file_current;
|
||||||
|
|
||||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
|
extern unsigned int terminal_height;
|
||||||
if (*input == 'q') {
|
extern unsigned int terminal_width;
|
||||||
*status ^= STATUS_QUIT_PROGRAM;
|
|
||||||
} else if (*input == *"KEY_BACKSPACE") {
|
|
||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
|
||||||
} else if (*input == 'a') {
|
|
||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
|
||||||
} else if (*input == 'o') {
|
|
||||||
file_modifiers ^= FILE_MODIFIERS_SORT_BITMASK;
|
|
||||||
} else if (*input == 'e') {
|
|
||||||
file_modifiers ^= FILE_MODIFIERS_SORT_ALPHABETIC;
|
|
||||||
} else if (*input == 'u') {
|
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
|
||||||
} else if (*input == 'h') {
|
|
||||||
chdir("..");
|
|
||||||
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
|
||||||
|
|
||||||
} else {
|
extern WINDOW *win_b;
|
||||||
|
|
||||||
|
extern char *rgt_buffer;
|
||||||
|
extern char *btm_buffer;
|
||||||
|
extern unsigned long mid_file_count;
|
||||||
|
|
||||||
|
extern unsigned int status;
|
||||||
|
|
||||||
|
unsigned int timeout_time = 0;
|
||||||
|
extern char *input;
|
||||||
|
unsigned int input_pass;
|
||||||
|
int parsed_input_number;
|
||||||
|
extern char *start_path;
|
||||||
|
|
||||||
|
int read_string(WINDOW *win, int y, int x, char *str);
|
||||||
|
int strcmp_offset(char *in0, char *in1, char offset);
|
||||||
|
extern void render_pass();
|
||||||
|
extern int (*order_func)();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FAIL(char *function, char *str){
|
||||||
|
noraw();
|
||||||
|
endwin();
|
||||||
|
curs_set(1);
|
||||||
|
echo();
|
||||||
|
printf("ERROR in function %s: %s", function, str);
|
||||||
|
kill(getpid(),9);
|
||||||
|
}
|
||||||
|
void user_interactions() {
|
||||||
|
|
||||||
|
|
||||||
|
char ch;
|
||||||
|
unsigned long i;
|
||||||
|
unsigned long binding_matches = 0;
|
||||||
|
static char binding_pass = 0;
|
||||||
|
|
||||||
|
|
||||||
|
ch = getch();
|
||||||
|
if(ch != ERR) {
|
||||||
|
timeout(1); /* blocking timeout of getch() */
|
||||||
|
input[input_pass] = ch;
|
||||||
|
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
||||||
|
input_pass++;
|
||||||
|
if (ch == 27) { /* esc key */
|
||||||
|
memset(input, 0, 255);
|
||||||
|
input_pass = 0;
|
||||||
|
timeout(100); /* blocking timeout of getch() */
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
}
|
||||||
|
binding_pass = 0;
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void (*func_ptr)(int, int);
|
||||||
|
int number_length = 0;
|
||||||
|
if (!binding_pass) {
|
||||||
|
parsed_input_number = 0;
|
||||||
|
while((*input >= '0') && (*input <= '9')) {
|
||||||
|
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
||||||
|
input++;
|
||||||
|
number_length++;
|
||||||
|
mvaddch(terminal_height-5, 5, number_length+48);
|
||||||
|
}
|
||||||
|
input -= number_length;
|
||||||
|
binding_pass = 1;
|
||||||
|
|
||||||
|
char cmp_len = strlen(input);
|
||||||
|
if(strlen(input) < 1) {
|
||||||
|
cmp_len++;
|
||||||
|
}
|
||||||
|
for (i = 0; i < binding_count; i++) {
|
||||||
|
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
||||||
|
|
||||||
|
func_ptr = key_binding[i].func;
|
||||||
|
func_ptr(parsed_input_number, i);
|
||||||
|
|
||||||
|
memset(input, 0, 255);
|
||||||
|
input_pass = 0;
|
||||||
|
binding_pass = 0;
|
||||||
|
number_length = 0;
|
||||||
|
timeout(100); /* blocking timeout of getch() */
|
||||||
|
} else if (strncmp(input+number_length, key_binding[i].key, cmp_len) == 0) {
|
||||||
|
binding_matches++;
|
||||||
|
attron(A_UNDERLINE);
|
||||||
|
mvaddstr(terminal_height-binding_matches-2, 0, "input");
|
||||||
|
mvaddstr(terminal_height-binding_matches-2, sizeof("input"), "\t\t\t");
|
||||||
|
mvaddstr(terminal_height-binding_matches-2, sizeof("input") + sizeof("\t\t\t"), "command");
|
||||||
|
attroff(A_UNDERLINE);
|
||||||
|
mvaddstr(terminal_height-binding_matches-1, 0, key_binding[i].key);
|
||||||
|
mvaddstr(terminal_height-binding_matches-1, 0, key_binding[i].key);
|
||||||
|
mvaddstr(terminal_height-binding_matches-1, sizeof(key_binding[i].key), "\t");
|
||||||
|
mvaddstr(terminal_height-binding_matches-1, sizeof(key_binding[i].key) + sizeof("\t"), key_binding[i].comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int read_string(WINDOW *win, int y, int x, char *str){
|
||||||
|
curs_set(1);
|
||||||
|
|
||||||
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
|
|
||||||
|
unsigned int pass = 0;
|
||||||
|
char ch;
|
||||||
|
char err = 0;
|
||||||
|
|
||||||
|
wmove(win, y, x);
|
||||||
|
while(1) {
|
||||||
|
/*ch = mvwgetch(win, y, x + pass);*/
|
||||||
|
ch = wgetch(win);
|
||||||
|
if (ch == '\n') {
|
||||||
|
err = 0;
|
||||||
|
break;
|
||||||
|
} else if (ch == 27) { /* esc key */
|
||||||
|
err = 1;
|
||||||
|
break;
|
||||||
|
} else if (ch == 127) { /* backspace */
|
||||||
|
if (pass > 0) {
|
||||||
|
pass--;
|
||||||
|
mvwdelch(win, y, pass);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mvwaddch(win, y, x +pass, ch);
|
||||||
|
str[pass] = ch;
|
||||||
|
pass++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str[pass] = '\0';
|
||||||
|
|
||||||
|
timeout(10);
|
||||||
|
curs_set(0);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
int strcmp_offset(char *in0, char *in1, char offset){
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (in0[i] != '\0' && in1[i] != '\0') {
|
||||||
|
if (in0[i+offset] != in1[i]) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
in1++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
void quit_program(){
|
||||||
|
status = STATUS_QUIT_PROGRAM;
|
||||||
|
}
|
||||||
|
void toggle_selection(){
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
pthread_mutex_lock(&mutex_mid);
|
||||||
|
mid_content[selected_file_current].status ^= FILE_STATUS_SELECTED;
|
||||||
|
file_current->status ^= FILE_STATUS_SELECTED;
|
||||||
|
status |= (STATUS_UPDATE_SCREEN_MASK);
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
}
|
||||||
|
void move_down(int passes){
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
if (passes == 0) {
|
||||||
|
passes++;
|
||||||
|
}
|
||||||
|
/*capping the maximum file is done inside thread_mid */
|
||||||
|
selected_file_current += passes;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
}
|
||||||
|
void move_up(int passes){
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
if (passes == 0) {
|
||||||
|
passes++;
|
||||||
|
}
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < passes; i++) {
|
||||||
|
if (selected_file_current != 0) {
|
||||||
|
selected_file_current--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
}
|
||||||
|
void move_left(int passes){
|
||||||
|
if (passes == 0) {
|
||||||
|
passes++;
|
||||||
|
}
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < passes; i++) {
|
||||||
|
if (chdir("..") != 0) {
|
||||||
|
/* TODO(2025-07-09T00:30:05) fix */
|
||||||
|
FAIL("move_left", "unhandled error of chdir");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
|
}
|
||||||
|
void move_right(){
|
||||||
|
if (file_current->file_type == FILE_TYPE_DIR || file_current->file_type == FILE_TYPE_SYMLINK) {
|
||||||
|
if (chdir(file_current->file_name) != 0) {
|
||||||
|
FAIL("move_right", "unhandled error of chdir");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unsigned long i = 0;
|
||||||
|
char match = 0;
|
||||||
|
char *mime = get_mimetype(file_current->file_name);
|
||||||
|
char *extension = strrchr(file_current->file_name, '.');
|
||||||
|
for (i = 0; i < file_extension_default_count; i++) {
|
||||||
|
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
||||||
|
char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
|
||||||
|
cmd = concat(cmd, file_current->file_name);
|
||||||
|
cmd = concat(cmd, "\"");
|
||||||
|
|
||||||
|
|
||||||
|
if (system(cmd) == -1) {
|
||||||
|
/*do nothing*/
|
||||||
|
}
|
||||||
|
match = 1;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (match == 0) {
|
||||||
|
for (i = 0; i < mimetype_default_count; i++) {
|
||||||
|
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||||
|
|
||||||
|
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
|
||||||
|
cmd = concat(cmd, file_current->file_name);
|
||||||
|
cmd = concat(cmd, "\"");
|
||||||
|
btm_buffer = malloc(strlen(cmd));
|
||||||
|
|
||||||
|
strcpy(btm_buffer, cmd-1);
|
||||||
|
|
||||||
|
|
||||||
|
if (system(cmd) == -1) {
|
||||||
|
/*do nothing*/
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(mime);
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
|
}
|
||||||
|
void toggle_hidden_files(){
|
||||||
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
|
}
|
||||||
|
void jump_bottom(){
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
selected_file_current = 0 - 1;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
}
|
||||||
|
void jump_top(){
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
selected_file_current = 0;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void open_with(){
|
||||||
|
btm_buffer = concat("open \"", file_current->file_name);
|
||||||
|
btm_buffer = concat(btm_buffer, "\" with:");
|
||||||
|
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
werase(win_b);
|
||||||
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
|
render_pass();
|
||||||
|
unsigned long local_height;
|
||||||
|
local_height = getmaxy(win_b);
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO(2025-06-22T01:24:36) fix fixed buffer size */
|
||||||
|
char *str = malloc(255);
|
||||||
|
memset(str, ' ', 255);
|
||||||
|
int err = read_string(win_b, local_height - 1, 0 , str);
|
||||||
|
|
||||||
|
|
||||||
|
if (!err) {
|
||||||
|
char *cmd = concat(str, " ./\"");
|
||||||
|
cmd = concat(cmd, file_current->file_name);
|
||||||
|
cmd = concat(cmd, "\"");
|
||||||
|
|
||||||
|
if (system(cmd) == -1) {
|
||||||
|
FAIL("open_with", "creating subcommand failed unhandled");
|
||||||
|
}
|
||||||
|
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = cmd;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rename_hovered(){
|
||||||
|
|
||||||
|
btm_buffer = concat("rename \"", file_current->file_name);
|
||||||
|
btm_buffer = concat(btm_buffer, "\" to:");
|
||||||
|
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
werase(win_b);
|
||||||
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
|
render_pass();
|
||||||
|
|
||||||
|
unsigned long local_height;
|
||||||
|
local_height = getmaxy(win_b);
|
||||||
|
|
||||||
|
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
||||||
|
char *str = malloc(255);
|
||||||
|
memset(str, ' ', 255);
|
||||||
|
int err = read_string(win_b, local_height - 1, 0, str);
|
||||||
|
|
||||||
|
|
||||||
|
if (!err) {
|
||||||
|
char *cmd = concat("mv ./\"", file_current->file_name);
|
||||||
|
cmd = concat(cmd, "\" ./\"");
|
||||||
|
cmd = concat(cmd, str);
|
||||||
|
cmd = concat(cmd, "\"");
|
||||||
|
|
||||||
|
if (system(cmd) == -1) {
|
||||||
|
FAIL("rename_hovered", "mv or creating subcommand failed");
|
||||||
|
};
|
||||||
|
btm_buffer = cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
|
||||||
|
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete(){
|
||||||
|
|
||||||
|
unsigned int i = 0;
|
||||||
|
unsigned int hits = 0;
|
||||||
|
char *file_str = " ";
|
||||||
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
file_str = concat(file_str, "\"");
|
||||||
|
file_str = concat(file_str, mid_content[i].file_name);
|
||||||
|
file_str = concat(file_str, "\" ");
|
||||||
|
hits++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hits) {
|
||||||
|
btm_buffer = concat("delete:", file_str);
|
||||||
|
} else {
|
||||||
|
btm_buffer = concat("delete: \"", file_current->file_name);
|
||||||
|
btm_buffer = concat(btm_buffer, "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
btm_buffer = concat(btm_buffer, "?");
|
||||||
|
btm_buffer = concat(btm_buffer, "\n\n");
|
||||||
|
btm_buffer = concat(btm_buffer, "(y/N)");
|
||||||
|
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
werase(win_b);
|
||||||
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
|
render_pass();
|
||||||
|
|
||||||
|
|
||||||
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
|
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
||||||
|
char ch = wgetch(win_b);
|
||||||
|
|
||||||
|
if (ch == 'y' || ch == 'Y') {
|
||||||
|
/* TODO(2025-06-30T02:27:06) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
||||||
|
int error;
|
||||||
|
if (hits) {
|
||||||
|
int j = 2;
|
||||||
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
error = remove(mid_content[i].file_name);
|
||||||
|
if (error != 0) {
|
||||||
|
mvaddstr(terminal_height-j, 0, "could not delete: " );
|
||||||
|
mvaddstr(terminal_height-j, strlen("could not delete: "), mid_content[i].file_name);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = concat("deleted: ", file_str);
|
||||||
|
} else {
|
||||||
|
free(btm_buffer);
|
||||||
|
error = remove(file_current->file_name);
|
||||||
|
if (error != 0) {
|
||||||
|
mvaddstr(terminal_height-2, 0, "could not delete: " );
|
||||||
|
mvaddstr(terminal_height-2, strlen("could not delete: "), mid_content[i].file_name);
|
||||||
|
btm_buffer = " ";
|
||||||
|
} else {
|
||||||
|
btm_buffer = concat("deleted: \"", file_current->file_name);
|
||||||
|
btm_buffer = concat(btm_buffer, "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/*system(cmd);*/
|
||||||
|
|
||||||
|
} else {
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = "cancled deletion";
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout(10);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
|
||||||
|
if (hits) {
|
||||||
|
free(file_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void makedir(){
|
||||||
|
btm_buffer = "create dir: ";
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
werase(win_b);
|
||||||
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
render_pass();
|
||||||
|
|
||||||
|
unsigned long local_height;
|
||||||
|
local_height = getmaxy(win_b);
|
||||||
|
|
||||||
|
/* TODO(2025-07-03T01:19:55) fix fixed buffer size */
|
||||||
|
char *str = malloc(255);
|
||||||
|
memset(str, ' ', 255);
|
||||||
|
int err = read_string(win_b, local_height - 1, 0, str);
|
||||||
|
if (!err) {
|
||||||
|
btm_buffer = concat(btm_buffer, str);
|
||||||
|
mkdir(str, 755); /*magic number from default permissions as created by mkdir*/
|
||||||
|
}
|
||||||
|
free(str);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
}
|
||||||
|
void makefile(){
|
||||||
|
btm_buffer = "create file: ";
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
werase(win_b);
|
||||||
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
render_pass();
|
||||||
|
|
||||||
|
unsigned long local_height;
|
||||||
|
local_height = getmaxy(win_b);
|
||||||
|
|
||||||
|
/* TODO(2025-07-03T01:19:49) fix fixed buffer size */
|
||||||
|
char *str = malloc(255);
|
||||||
|
memset(str, ' ', 255);
|
||||||
|
int err = read_string(win_b, local_height - 1, 0, str);
|
||||||
|
if (!err) {
|
||||||
|
btm_buffer = concat(btm_buffer, str);
|
||||||
|
FILE *fp;
|
||||||
|
fp = fopen(str, "w");
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
free(str);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(){
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
}
|
||||||
|
void not_implemented(int passes, int index){
|
||||||
|
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
|
||||||
|
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
|
||||||
|
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
||||||
|
}
|
||||||
|
void jump_to_dir(int passes, int index){
|
||||||
|
if ((char*)key_binding[index].black_magic) {
|
||||||
|
if (chdir(getenv((char*)key_binding[index].black_magic+1)) != 0) {
|
||||||
|
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
|
}
|
||||||
|
void order_by(int passes, int index){
|
||||||
|
|
||||||
|
order_func = key_binding[index].black_magic;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
|
}
|
||||||
|
void cmd_on_selected(int passes, int index){
|
||||||
|
unsigned int i = 0;
|
||||||
|
unsigned int hits = 0;
|
||||||
|
char *file_str = " ";
|
||||||
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
file_str = concat(file_str, "\"");
|
||||||
|
file_str = concat(file_str, mid_content[i].file_name);
|
||||||
|
file_str = concat(file_str, "\" ");
|
||||||
|
hits++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hits) {
|
||||||
|
btm_buffer = concat(key_binding[index].black_magic, file_str);
|
||||||
|
} else {
|
||||||
|
btm_buffer = concat(key_binding[index].black_magic, "\"");
|
||||||
|
btm_buffer = concat(btm_buffer, file_current->file_name);
|
||||||
|
btm_buffer = concat(btm_buffer, "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
btm_buffer = concat(btm_buffer, "?");
|
||||||
|
btm_buffer = concat(btm_buffer, "\n\n");
|
||||||
|
btm_buffer = concat(btm_buffer, "(y/N)");
|
||||||
|
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
werase(win_b);
|
||||||
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
|
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
|
render_pass();
|
||||||
|
|
||||||
|
|
||||||
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
|
/* TODO(2025-07-06T07:22:49) fix fixed buffer size */
|
||||||
|
char ch = wgetch(win_b);
|
||||||
|
|
||||||
|
if (ch == 'y' || ch == 'Y') {
|
||||||
|
/* the second loop is used to add "./", wich is not being printed" */
|
||||||
|
char *cmd = malloc(sizeof(char));
|
||||||
|
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
||||||
|
if (hits) {
|
||||||
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
free(cmd);
|
||||||
|
cmd = concat((char*)key_binding[index].black_magic, " \"");
|
||||||
|
cmd = concat(cmd, mid_content[i].file_name);
|
||||||
|
cmd = concat(cmd, "\"");
|
||||||
|
if (system(cmd) != 0) {
|
||||||
|
/*do nothing*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = concat("completed: ", key_binding[index].black_magic);
|
||||||
|
} else {
|
||||||
|
free(btm_buffer);
|
||||||
|
free(cmd);
|
||||||
|
cmd = concat((char*)key_binding[index].black_magic, " \"");
|
||||||
|
cmd = concat(cmd, file_current->file_name);
|
||||||
|
cmd = concat(cmd, "\"");
|
||||||
|
if (system(cmd) != 0) {
|
||||||
|
/*do nothing*/
|
||||||
|
}
|
||||||
|
mvaddstr(10,10, cmd);
|
||||||
|
|
||||||
|
}
|
||||||
|
/*system(cmd);*/
|
||||||
|
free(cmd);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = "cancled deletion";
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout(10);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
|
||||||
|
if (hits) {
|
||||||
|
free(file_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,28 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#ifndef INTERACTIONS_GUARD
|
||||||
|
#define INTERACTIONS_GUARD
|
||||||
#include "interactions.c"
|
#include "interactions.c"
|
||||||
|
#endif
|
||||||
|
|
||||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings);
|
|
||||||
|
void user_interactions();
|
||||||
|
void quit_program();
|
||||||
|
void toggle_selection();
|
||||||
|
void move_right();
|
||||||
|
void move_up(int passes);
|
||||||
|
void move_down(int passes);
|
||||||
|
void move_left(int passes);
|
||||||
|
void jump_bottom();
|
||||||
|
void jump_top();
|
||||||
|
void toggle_hidden_files();
|
||||||
|
void open_with();
|
||||||
|
void rename_hovered();
|
||||||
|
void delete();
|
||||||
|
void makedir();
|
||||||
|
void makefile();
|
||||||
|
void update();
|
||||||
|
void not_implemented(int passes, int index);
|
||||||
|
void jump_to_dir(int passes, int index);
|
||||||
|
void order_by(int passes, int index);
|
||||||
|
void cmd_on_selected(int passes, int index);
|
||||||
|
167
main.c
167
main.c
@@ -4,11 +4,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
|
#include <locale.h>
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "interactions.h"
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
|
#include "interactions.h"
|
||||||
|
|
||||||
unsigned int terminal_height;
|
unsigned int terminal_height;
|
||||||
unsigned int terminal_width;
|
unsigned int terminal_width;
|
||||||
@@ -16,23 +17,37 @@ unsigned int temp_heigth = 0; /*used for screen refresh*/
|
|||||||
unsigned int temp_width = 0;
|
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 = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
char input = 0;
|
char *start_path;
|
||||||
|
|
||||||
void render_pass(WINDOW *wint, WINDOW *winb, WINDOW *winl, WINDOW *winm, WINDOW *winr);
|
WINDOW *win_t;
|
||||||
|
WINDOW *win_b;
|
||||||
|
WINDOW *win_l;
|
||||||
|
WINDOW *win_m;
|
||||||
|
WINDOW *win_r;
|
||||||
|
|
||||||
|
char *input; /*used in user_interactions*/
|
||||||
|
char *terminal_width_empty_line; /* used in user_interactions */
|
||||||
|
|
||||||
|
void render_pass();
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main(){
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||||
WINDOW *win_t = newwin(1, terminal_width, 0, 0);
|
WINDOW *wint = newwin(1, terminal_width, 0, 0);
|
||||||
WINDOW *win_b = newwin(1, terminal_width, terminal_height-1, 0);
|
WINDOW *winb = newwin(1, terminal_width, terminal_height-1, 0);
|
||||||
WINDOW *win_l = newwin(terminal_height-2, terminal_width/3, 1, 0);
|
WINDOW *winl = newwin(terminal_height-2, terminal_width/8, 1, 0);
|
||||||
WINDOW *win_m = newwin(terminal_height-2, terminal_width/3, 1, (terminal_width/3));
|
WINDOW *winm = 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 *winr = newwin(terminal_height-2, terminal_width/3, 1, ((terminal_width/2)));
|
||||||
|
win_t = wint;
|
||||||
|
win_b = winb;
|
||||||
|
win_r = winr;
|
||||||
|
win_m = winm;
|
||||||
|
win_l = winl;
|
||||||
|
|
||||||
pthread_t thread_b;
|
pthread_t thread_b;
|
||||||
pthread_t thread_t;
|
pthread_t thread_t;
|
||||||
@@ -41,6 +56,7 @@ int main() {
|
|||||||
pthread_t thread_r;
|
pthread_t thread_r;
|
||||||
|
|
||||||
char threading = 0;
|
char threading = 0;
|
||||||
|
terminal_width_empty_line = malloc(terminal_width);
|
||||||
|
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
@@ -51,72 +67,90 @@ int main() {
|
|||||||
temp_width = terminal_width;
|
temp_width = terminal_width;
|
||||||
temp_heigth = terminal_height;
|
temp_heigth = terminal_height;
|
||||||
}
|
}
|
||||||
if (status & STATUS_RUN_BACKEND || threading) {
|
if (status & STATUS_RUN_BACKEND && threading) {
|
||||||
if (threading) {
|
pthread_cancel(thread_b);
|
||||||
pthread_cancel(thread_t);
|
pthread_cancel(thread_r);
|
||||||
pthread_cancel(thread_b);
|
pthread_cancel(thread_m);
|
||||||
pthread_cancel(thread_l);
|
pthread_cancel(thread_l);
|
||||||
pthread_cancel(thread_m);
|
pthread_cancel(thread_t);
|
||||||
pthread_cancel(thread_r);
|
}
|
||||||
threading = 0;
|
if (threading) {
|
||||||
status &= ~STATUS_RUN_BACKEND;
|
status &= ~(STATUS_RELOAD_DIRECTORY);
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
pthread_join(thread_t, NULL);
|
||||||
} else {
|
pthread_join(thread_l, NULL);
|
||||||
pthread_create(&thread_t, NULL, thread_top, win_t); /*top bar*/
|
pthread_join(thread_m, NULL);
|
||||||
pthread_create(&thread_b, NULL, thread_btm, win_b); /*bottom bar*/
|
pthread_join(thread_b, NULL);
|
||||||
pthread_create(&thread_m, NULL, thread_mid, win_m); /*parent_content slash win_l*/
|
pthread_join(thread_r, NULL);
|
||||||
pthread_create(&thread_l, NULL, thread_lft, win_l); /*current_content slash win_m*/
|
threading = 0;
|
||||||
pthread_create(&thread_r, NULL, thread_rgt, win_r); /*child_content slash win_r*/
|
}
|
||||||
threading = 1;
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
}
|
pthread_create(&thread_t, NULL, thread_top, &status); /*top bar*/
|
||||||
}
|
pthread_create(&thread_l, NULL, thread_lft, &status); /*parent_content slash win_l*/
|
||||||
if ((input = getch())) {
|
pthread_create(&thread_m, NULL, thread_mid, &status); /*current_content slash win_m*/
|
||||||
user_interactions(&input, &status, &settings);
|
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
||||||
|
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
||||||
|
status &= ~(STATUS_RUN_BACKEND);
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
threading = 1;
|
||||||
}
|
}
|
||||||
|
user_interactions();
|
||||||
|
|
||||||
render_pass(win_t, win_b, win_l, win_m, win_r);
|
|
||||||
|
render_pass();
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
threading_free();
|
threading_free();
|
||||||
|
free(start_path);
|
||||||
|
|
||||||
pthread_join(thread_l, NULL);
|
if (threading) {
|
||||||
pthread_join(thread_r, NULL);
|
pthread_join(thread_l, NULL);
|
||||||
pthread_join(thread_m, NULL);
|
pthread_join(thread_r, NULL);
|
||||||
pthread_join(thread_t, NULL);
|
pthread_join(thread_m, NULL);
|
||||||
pthread_join(thread_b, NULL);
|
pthread_join(thread_t, NULL);
|
||||||
*/
|
pthread_join(thread_b, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
curs_set(1);
|
delwin(win_l);
|
||||||
|
delwin(win_m);
|
||||||
|
delwin(win_r);
|
||||||
|
delwin(win_t);
|
||||||
|
delwin(win_b);
|
||||||
|
noraw();
|
||||||
endwin();
|
endwin();
|
||||||
refresh();
|
curs_set(1);
|
||||||
|
echo();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WINDOW *win_r){
|
void render_pass(){
|
||||||
|
|
||||||
if ((status & STATUS_UPDATE_SCREEN_MASK) & STATUS_UPDATE_SCREEN_RESIZE) {
|
if (status & STATUS_UPDATE_SCREEN_RESIZE) {
|
||||||
|
if (status & STATUS_UPDATE_SCREEN_RELOAD_FULL) {
|
||||||
|
clear();
|
||||||
|
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*TODO: check if deallocation of window and reallocation is faster than this or not */
|
/*TODO: check if deallocation of window and reallocation is faster than this or not */
|
||||||
|
|
||||||
werase(win_t);
|
wclear(win_t);
|
||||||
werase(win_b);
|
wclear(win_b);
|
||||||
werase(win_l);
|
wclear(win_l);
|
||||||
werase(win_m);
|
wclear(win_m);
|
||||||
werase(win_r);
|
wclear(win_r);
|
||||||
|
|
||||||
wresize(win_t, 1, terminal_width);
|
wresize(win_t, 1, terminal_width);
|
||||||
wresize(win_b, terminal_height, terminal_width/3);
|
wresize(win_l, terminal_height-2, terminal_width/8);
|
||||||
wresize(win_m, terminal_height-2, terminal_width/3);
|
wresize(win_m, terminal_height-2, (terminal_width/2)-(terminal_width/8));
|
||||||
wresize(win_l, terminal_height-2, terminal_width/3);
|
wresize(win_r, terminal_height-2, terminal_width/2);
|
||||||
wresize(win_r, terminal_height-2, terminal_width/3);
|
wresize(win_b, 1, terminal_width);
|
||||||
|
|
||||||
|
|
||||||
mvwin(win_t, 0, 0);
|
mvwin(win_t, 0, 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)));
|
||||||
|
mvwin(win_b, terminal_height-1, 0);
|
||||||
|
|
||||||
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
@@ -125,34 +159,39 @@ void render_pass(WINDOW *win_t, WINDOW *win_b, WINDOW *win_l, WINDOW *win_m, WIN
|
|||||||
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
||||||
status &= ~(STATUS_UPDATE_SCREEN_MASK);
|
status &= ~(STATUS_UPDATE_SCREEN_MASK);
|
||||||
window_top(win_t);
|
window_top(win_t);
|
||||||
window_btm(win_b);
|
|
||||||
window_lft(win_l);
|
window_lft(win_l);
|
||||||
window_mid(win_m);
|
window_mid(win_m);
|
||||||
window_rgt(win_r);
|
window_rgt(win_r);
|
||||||
|
window_btm(win_b);
|
||||||
wrefresh(win_t);
|
wrefresh(win_t);
|
||||||
wrefresh(win_b);
|
|
||||||
wrefresh(win_l);
|
wrefresh(win_l);
|
||||||
wrefresh(win_m);
|
wrefresh(win_m);
|
||||||
wrefresh(win_r);
|
wrefresh(win_r);
|
||||||
|
wrefresh(win_b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
initscr(); /*start ncurses*/
|
setlocale(LC_ALL, "");
|
||||||
noecho(); /*hide keyboard input*/
|
initscr(); /* start ncurses */
|
||||||
timeout(50); /*blocking timeout of getch()*/
|
noecho(); /* hide keyboard input */
|
||||||
keypad(stdscr, TRUE);
|
timeout(0); /* blocking timeout of getch() */
|
||||||
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);
|
input = malloc(sizeof(char)*255); /* size of input buffer, out of bounds access will not be accounted for */
|
||||||
|
memset(input, 0, 255);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
threading_init(); /* found in threading.c */
|
threading_init(); /* found in threading.c */
|
||||||
colors_init();
|
colors_init();
|
||||||
|
ESCDELAY = 10;
|
||||||
|
char *start_path = getcwd(NULL, 0);
|
||||||
|
setenv("START_PATH", start_path, 0);
|
||||||
|
free(start_path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
140
sorting.c
140
sorting.c
@@ -1,6 +1,8 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
extern unsigned int settings;
|
extern unsigned int settings;
|
||||||
@@ -12,18 +14,144 @@ int skip_hidden_files(const struct dirent *entry){
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
int skip_dot(const struct dirent *entry){
|
||||||
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int sort_natural(const void *file0, const void *file1){
|
int sort_natural(const void *file0, const void *file1){
|
||||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||||
unsigned char file_type1 = ((file*)file1)->file_type;
|
unsigned char file_type1 = ((file*)file1)->file_type;
|
||||||
if (file_type0 > file_type1) {
|
|
||||||
return 1;
|
char weight = 0;
|
||||||
} else if (file_type0 < file_type1) {
|
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
||||||
return -1;
|
weight |= 1;
|
||||||
} else {
|
}
|
||||||
|
if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
||||||
|
weight |= 2;
|
||||||
|
}
|
||||||
|
if (weight == 0 || weight == 3) {
|
||||||
char *file_name0 = ((file*)file0)->file_name;
|
char *file_name0 = ((file*)file0)->file_name;
|
||||||
char *file_name1 = ((file*)file1)->file_name;
|
char *file_name1 = ((file*)file1)->file_name;
|
||||||
return strcasecmp(file_name0, file_name1);
|
return strcasecmp(file_name0, file_name1);
|
||||||
|
} else {
|
||||||
|
if (file_type0 > file_type1) {
|
||||||
|
return 1;
|
||||||
|
} else if (file_type0 < file_type1) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
char *file_name0 = ((file*)file0)->file_name;
|
||||||
|
char *file_name1 = ((file*)file1)->file_name;
|
||||||
|
return strcasecmp(file_name0, file_name1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int sort_alpha(const void *file0, const void *file1){
|
||||||
|
char *file_name0 = ((file*)file0)->file_name;
|
||||||
|
char *file_name1 = ((file*)file1)->file_name;
|
||||||
|
return strcmp(file_name0, file_name1);
|
||||||
|
}
|
||||||
|
int sort_random(const void *file0, const void *file1){
|
||||||
|
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||||
|
unsigned char file_type1 = ((file*)file1)->file_type;
|
||||||
|
static int seed = 0;
|
||||||
|
static int random = 0;
|
||||||
|
|
||||||
|
if (seed == 0) {
|
||||||
|
seed = rand();
|
||||||
|
}
|
||||||
|
if (random == 0) {
|
||||||
|
random = seed;
|
||||||
|
}
|
||||||
|
char weight = 0;
|
||||||
|
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
||||||
|
weight |= 1;
|
||||||
|
}
|
||||||
|
if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
||||||
|
weight |= 2;
|
||||||
|
}
|
||||||
|
if (weight == 0 || weight == 3) {
|
||||||
|
random = random > 1;
|
||||||
|
if ((random & 2) == 2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
if (random & 1){
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (file_type0 > file_type1) {
|
||||||
|
return 1;
|
||||||
|
} else if (file_type0 < file_type1) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
random = random > 1;
|
||||||
|
if ((random & 2) == 2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
if (random & 1){
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int sort_type(const void *file0, const void *file1){
|
||||||
|
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||||
|
unsigned char file_type1 = ((file*)file1)->file_type;
|
||||||
|
char *file_name0 = ((file*)file0)->file_name;
|
||||||
|
char *file_name1 = ((file*)file1)->file_name;
|
||||||
|
if (file_type0 == file_type1) {
|
||||||
|
return strcasecmp(file_name0, file_name1);
|
||||||
|
} else if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
||||||
|
return -1;
|
||||||
|
} else if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
if (file_type0 > file_type1) {
|
||||||
|
return -1;
|
||||||
|
} else if (file_type0 < file_type1) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return strcasecmp(file_name0, file_name1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int sort_size(const void *file0, const void *file1){
|
||||||
|
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||||
|
unsigned char file_type1 = ((file*)file1)->file_type;
|
||||||
|
unsigned long file_size0 = ((file*)file0)->file_size;
|
||||||
|
unsigned long file_size1 = ((file*)file1)->file_size;
|
||||||
|
char *file_name0 = ((file*)file0)->file_name;
|
||||||
|
char *file_name1 = ((file*)file1)->file_name;
|
||||||
|
if (file_type0 == file_type1) {
|
||||||
|
if (file_size0 > file_size1) {
|
||||||
|
return -1;
|
||||||
|
} else if (file_size0 < file_size1) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return strcasecmp(file_name0, file_name1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
||||||
|
return -1;
|
||||||
|
} else if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
if (file_size0 > file_size1) {
|
||||||
|
return -1;
|
||||||
|
} else if (file_size0 < file_size1) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return strcasecmp(file_name0, file_name1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
12
sorting.h
12
sorting.h
@@ -1,8 +1,18 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#ifndef SORTING_GUARD
|
||||||
|
#define SORTING_GUARD
|
||||||
#include "sorting.c"
|
#include "sorting.c"
|
||||||
|
#endif
|
||||||
|
|
||||||
void sort_dir(unsigned long *dir_length_width, char *dir_content);
|
|
||||||
int skip_hidden_files(const struct dirent *entry);
|
int skip_hidden_files(const struct dirent *entry);
|
||||||
|
int skip_dot(const struct dirent *entry);
|
||||||
|
void sort_dir(unsigned long *dir_length_width, char *dir_content);
|
||||||
|
void sort_dir(unsigned long *dir_length_width, char *dir_content);
|
||||||
|
int sort_natural(const void *file0, const void *file1);
|
||||||
|
int sort_alpha(const void *file0, const void *file1);
|
||||||
|
int sort_random(const void *file0, const void *file1);
|
||||||
|
int sort_type(const void *file0, const void *file1);
|
||||||
|
int sort_size(const void *file0, const void *file1);
|
||||||
|
|
||||||
|
257
threading.c
257
threading.c
@@ -1,10 +1,13 @@
|
|||||||
#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>
|
||||||
|
#include <time.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
|
#include "file_previews.h"
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_t mutex_top;
|
pthread_mutex_t mutex_top;
|
||||||
@@ -12,126 +15,292 @@ 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;
|
||||||
|
pthread_mutex_t mutex_wait;
|
||||||
|
pthread_cond_t cond_wait;
|
||||||
|
volatile char wait_count; /* this is used to determine how many threads are waiting for cont_wait */
|
||||||
|
|
||||||
/* 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 *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */
|
||||||
|
char *btm_buffer;
|
||||||
|
char *top_buffer; /* current path */
|
||||||
|
|
||||||
|
volatile file *file_current;
|
||||||
|
|
||||||
|
|
||||||
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;
|
volatile unsigned long selected_file_current = 0;
|
||||||
|
volatile unsigned long selected_file_last = 0;
|
||||||
|
extern unsigned int terminal_width;
|
||||||
|
|
||||||
|
|
||||||
void *thread_mid(void *data){
|
void *thread_mid(void *data){
|
||||||
|
unsigned int status = *(unsigned int*)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) {
|
||||||
mid_content = malloc(sizeof(file));
|
mid_content = malloc(sizeof(file));
|
||||||
mid_content[1].file_name_width = sizeof("cannot open directory");
|
mid_content->file_name = "cannot open directory";
|
||||||
mid_content[1].file_name = "cannot open directory";
|
|
||||||
mid_file_count = 1;
|
mid_file_count = 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
mid_file_count = (unsigned long)get_dir_size(path);
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
mid_content = malloc(mid_file_count * sizeof(file));
|
free(mid_content);
|
||||||
memset(mid_content, ' ', mid_file_count * sizeof(file));
|
mid_file_count = get_dir_size(path);
|
||||||
get_dir_content(path, &mid_file_count, mid_content);
|
if (mid_file_count > 0) {
|
||||||
|
mid_content = malloc(mid_file_count * sizeof(file));
|
||||||
|
memset(mid_content, '\0', mid_file_count * sizeof(file));
|
||||||
|
get_dir_content(path, &mid_file_count, mid_content);
|
||||||
|
} else {
|
||||||
|
selected_file_current = 0;
|
||||||
|
mid_content = malloc(sizeof(file));
|
||||||
|
mid_content->status = FILE_STATUS_DIR_EMPTY;
|
||||||
|
mid_content->file_type = 0;
|
||||||
|
mid_content->file_size = 0;
|
||||||
|
mid_content->permissions = 0;
|
||||||
|
mid_content->color_pair = 0;
|
||||||
|
mid_content->file_name = "empty dir";
|
||||||
|
|
||||||
|
file_current->file_name = mid_content->file_name;
|
||||||
|
file_current->file_size = mid_content->file_size;
|
||||||
|
file_current->file_type = mid_content->file_type;
|
||||||
|
file_current->color_pair = mid_content->color_pair;
|
||||||
|
file_current->permissions = mid_content->permissions;
|
||||||
|
file_current->status = mid_content->status;
|
||||||
|
mid_file_count = 0;
|
||||||
|
|
||||||
|
while(wait_count < 2){
|
||||||
|
/*wait for thread_rgt and thread_btm to lock*/
|
||||||
|
}
|
||||||
|
pthread_mutex_lock(&mutex_wait);
|
||||||
|
pthread_cond_broadcast(&cond_wait);
|
||||||
|
pthread_mutex_unlock(&mutex_wait);
|
||||||
|
|
||||||
|
free(path);
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
if (selected_file_current >= mid_file_count) {
|
||||||
|
selected_file_current = mid_file_count-1;
|
||||||
|
selected_file_current = mid_file_count-1;
|
||||||
|
}
|
||||||
|
if (selected_file_current != selected_file_last) {
|
||||||
|
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
||||||
|
}
|
||||||
|
selected_file_last = selected_file_current;
|
||||||
|
|
||||||
|
free(file_current->file_name);
|
||||||
|
file_current->file_name = malloc(strlen(mid_content[selected_file_current].file_name));
|
||||||
|
strcpy(file_current->file_name, mid_content[selected_file_current].file_name);
|
||||||
|
file_current->file_size = mid_content[selected_file_current].file_size;
|
||||||
|
file_current->file_type = mid_content[selected_file_current].file_type;
|
||||||
|
file_current->color_pair = mid_content[selected_file_current].color_pair;
|
||||||
|
file_current->permissions = mid_content[selected_file_current].permissions;
|
||||||
|
|
||||||
|
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
||||||
|
file_current->status = mid_content[selected_file_current].status;
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
|
||||||
|
while(wait_count < 2){
|
||||||
|
/*wait for thread_rgt and thread_btm to lock*/
|
||||||
|
}
|
||||||
|
pthread_mutex_lock(&mutex_wait);
|
||||||
|
pthread_cond_broadcast(&cond_wait);
|
||||||
|
pthread_mutex_unlock(&mutex_wait);
|
||||||
|
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
pthread_exit(NULL);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
void *thread_lft(void *data){
|
void *thread_lft(void *data){
|
||||||
|
unsigned int status = *(unsigned int*)data;
|
||||||
pthread_mutex_lock(&mutex_lft);
|
pthread_mutex_lock(&mutex_lft);
|
||||||
|
|
||||||
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));
|
||||||
lft_content[1].file_name_width = sizeof("cannot open directory");
|
lft_content[0].file_name = "cannot open directory";
|
||||||
lft_content[1].file_name = "cannot open directory";
|
|
||||||
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);
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
lft_content = malloc(lft_file_count * sizeof(file));
|
lft_file_count = get_dir_size(path);
|
||||||
memset(lft_content, ' ', lft_file_count * sizeof(file));
|
free(lft_content);
|
||||||
get_dir_content(parent, &lft_file_count, lft_content);
|
lft_content = malloc(lft_file_count * sizeof(file));
|
||||||
free(parent);
|
memset(lft_content, '\0', lft_file_count * sizeof(file));
|
||||||
|
get_dir_content(path, &lft_file_count, lft_content);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
pthread_exit(NULL);
|
pthread_exit(0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void *thread_rgt(void *data){
|
void *thread_rgt(void *data){
|
||||||
|
unsigned int status = *(unsigned int*)data;
|
||||||
|
pthread_mutex_lock(&mutex_rgt);
|
||||||
|
pthread_mutex_lock(&mutex_wait);
|
||||||
|
wait_count++;
|
||||||
|
pthread_cond_wait(&cond_wait, &mutex_wait);
|
||||||
|
wait_count--;
|
||||||
|
pthread_mutex_unlock(&mutex_wait);
|
||||||
|
|
||||||
|
|
||||||
pthread_exit(NULL);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
free(rgt_content);
|
||||||
|
rgt_content = malloc(sizeof(file));
|
||||||
|
rgt_content->file_name = malloc(strlen(file_current->file_name));
|
||||||
|
strcpy(rgt_content->file_name, file_current->file_name);
|
||||||
|
rgt_content->file_size = file_current->file_size;
|
||||||
|
rgt_content->file_type = file_current->file_type;
|
||||||
|
rgt_content->status = file_current->status;
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
|
||||||
|
if (rgt_content->file_type == FILE_TYPE_DIR || rgt_content->file_type == FILE_TYPE_SYMLINK) {
|
||||||
|
char *path = malloc(strlen(rgt_content[0].file_name) + 1);
|
||||||
|
strcpy(path, rgt_content[0].file_name);
|
||||||
|
free(rgt_content);
|
||||||
|
rgt_file_count = 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);
|
||||||
|
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
|
||||||
|
free(path);
|
||||||
|
|
||||||
|
free(rgt_buffer);
|
||||||
|
rgt_buffer = malloc(sizeof(char));
|
||||||
|
rgt_buffer[0] = '\0';
|
||||||
|
} else {
|
||||||
|
|
||||||
|
rgt_file_count = 0;
|
||||||
|
|
||||||
|
free(rgt_buffer);
|
||||||
|
if (rgt_content->status & FILE_STATUS_DIR_EMPTY) {
|
||||||
|
rgt_buffer = "empty dir";
|
||||||
|
} else {
|
||||||
|
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
|
||||||
|
rgt_content->status = FILE_STATUS_HOVER;
|
||||||
|
rgt_buffer = preview_file(rgt_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
void *thread_top(void *data){
|
void *thread_top(void *data){
|
||||||
|
unsigned int status = *(unsigned int*)data;
|
||||||
pthread_mutex_lock(&mutex_top);
|
pthread_mutex_lock(&mutex_top);
|
||||||
free(top_content);
|
free(top_buffer);
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
if((path=getcwd(NULL, 0)) == NULL) {
|
||||||
top_content = malloc(sizeof("cannot open directory"));
|
top_buffer = malloc(sizeof("cannot open directory"));
|
||||||
top_width = sizeof("cannot open directory");
|
top_width = sizeof("cannot open directory");
|
||||||
top_content = "cannot open directory";
|
top_buffer = "cannot open directory";
|
||||||
} else {
|
} else {
|
||||||
top_content = getcwd(NULL, 0);
|
top_buffer = getcwd(NULL, 0);
|
||||||
top_width = strlen(top_content);
|
top_width = strlen(top_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
pthread_exit(NULL);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
void *thread_btm(void *data){
|
void *thread_btm(void *data){
|
||||||
|
unsigned int status = *(unsigned int*)data;
|
||||||
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
pthread_mutex_lock(&mutex_wait);
|
||||||
|
wait_count++;
|
||||||
|
pthread_cond_wait(&cond_wait, &mutex_wait);
|
||||||
|
wait_count--;
|
||||||
|
pthread_mutex_unlock(&mutex_wait);
|
||||||
|
|
||||||
pthread_exit(NULL);
|
free(btm_buffer);
|
||||||
|
int buffer_width = terminal_width;
|
||||||
|
btm_buffer = malloc(buffer_width);
|
||||||
|
memset(btm_buffer, 0, buffer_width);
|
||||||
|
btm_buffer[0] = (S_ISDIR(file_current->permissions)) ? 'd' : '-';
|
||||||
|
btm_buffer[1] = (file_current->permissions & S_IRUSR) ? 'r' : '-';
|
||||||
|
btm_buffer[2] = (file_current->permissions & S_IWUSR) ? 'w' : '-';
|
||||||
|
btm_buffer[3] = (file_current->permissions & S_IXUSR) ? 'x' : '-';
|
||||||
|
btm_buffer[4] = (file_current->permissions & S_IRGRP) ? 'r' : '-';
|
||||||
|
btm_buffer[5] = (file_current->permissions & S_IWGRP) ? 'w' : '-';
|
||||||
|
btm_buffer[6] = (file_current->permissions & S_IXGRP) ? 'x' : '-';
|
||||||
|
btm_buffer[7] = (file_current->permissions & S_IROTH) ? 'r' : '-';
|
||||||
|
btm_buffer[8] = (file_current->permissions & S_IWOTH) ? 'w' : '-';
|
||||||
|
btm_buffer[9] = (file_current->permissions & S_IXOTH) ? 'x' : '-';
|
||||||
|
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void threading_init(){
|
void threading_init(){
|
||||||
rgt_content = malloc(sizeof(char));
|
rgt_content = malloc(sizeof(file));
|
||||||
mid_content = malloc(sizeof(file));
|
mid_content = malloc(sizeof(file));
|
||||||
lft_content = malloc(sizeof(file));
|
lft_content = malloc(sizeof(file));
|
||||||
|
|
||||||
top_content = malloc(sizeof(char));
|
top_buffer = malloc(sizeof(char));
|
||||||
|
rgt_buffer = malloc(sizeof(char));
|
||||||
|
btm_buffer = malloc(sizeof(char));
|
||||||
|
memset(top_buffer, '\0', sizeof(char));
|
||||||
|
memset(rgt_buffer, '\0', sizeof(char));
|
||||||
|
memset(btm_buffer, '\0', sizeof(char));
|
||||||
|
|
||||||
|
mid_content->file_type = 0;
|
||||||
|
mid_content->file_size = 0;
|
||||||
|
mid_content->file_name = malloc(sizeof(char));
|
||||||
|
mid_content->file_name[0] = '\0';
|
||||||
|
|
||||||
|
rgt_content->file_type = 0;
|
||||||
|
rgt_content->file_size = 0;
|
||||||
|
rgt_content->file_name = malloc(sizeof(char));
|
||||||
|
rgt_content->file_name[0] = '\0';
|
||||||
|
|
||||||
pthread_mutex_init(&mutex_top, NULL);
|
file_current = malloc(sizeof(file));
|
||||||
pthread_mutex_init(&mutex_mid, NULL);
|
file_current->file_type = 0;
|
||||||
pthread_mutex_init(&mutex_lft, NULL);
|
file_current->file_size = 0;
|
||||||
|
file_current->file_name = malloc(sizeof(char));
|
||||||
|
file_current->file_name[0] = '\0';
|
||||||
|
|
||||||
|
volatile char vol; /* needed to make sure higher optimization steps dont move these around */
|
||||||
|
vol = pthread_mutex_init(&mutex_top, NULL);
|
||||||
|
vol = pthread_mutex_init(&mutex_mid, NULL);
|
||||||
|
vol = pthread_mutex_init(&mutex_lft, NULL);
|
||||||
|
vol = pthread_mutex_init(&mutex_btm, NULL);
|
||||||
|
vol = pthread_mutex_init(&mutex_rgt, NULL);
|
||||||
|
vol = pthread_mutex_init(&mutex_selection, NULL);
|
||||||
|
vol = pthread_mutex_init(&mutex_wait, NULL);
|
||||||
|
vol = pthread_cond_init(&cond_wait, NULL);
|
||||||
|
vol;
|
||||||
|
selected_file_current = 0;
|
||||||
|
selected_file_last = 0;
|
||||||
}
|
}
|
||||||
void threading_free(){
|
void threading_free(){
|
||||||
free(rgt_content);
|
free(rgt_content);
|
||||||
free(mid_content);
|
free(mid_content);
|
||||||
free(lft_content);
|
free(lft_content);
|
||||||
free(top_content);
|
free(top_buffer);
|
||||||
|
|
||||||
pthread_mutex_destroy(&mutex_top);
|
pthread_mutex_destroy(&mutex_top);
|
||||||
pthread_mutex_destroy(&mutex_mid);
|
pthread_mutex_destroy(&mutex_mid);
|
||||||
|
83
window.c
83
window.c
@@ -1,16 +1,22 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
|
extern char *input;
|
||||||
|
|
||||||
|
extern unsigned int timeout_time;
|
||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
|
|
||||||
extern file *mid_content;
|
extern file *mid_content;
|
||||||
extern file *lft_content;
|
extern file *lft_content;
|
||||||
extern file *rgt_content;
|
extern file *rgt_content;
|
||||||
extern char *top_content;
|
extern char *top_buffer;
|
||||||
|
extern char *rgt_buffer;
|
||||||
|
extern char *btm_buffer;
|
||||||
|
|
||||||
|
|
||||||
extern unsigned long lft_file_count;
|
extern unsigned long lft_file_count;
|
||||||
extern unsigned long mid_file_count;
|
extern unsigned long mid_file_count;
|
||||||
@@ -24,25 +30,35 @@ extern pthread_mutex_t mutex_mid;
|
|||||||
extern pthread_mutex_t mutex_rgt;
|
extern pthread_mutex_t mutex_rgt;
|
||||||
|
|
||||||
void window_top(WINDOW *win){
|
void window_top(WINDOW *win){
|
||||||
unsigned long i = 0;
|
|
||||||
werase(win);
|
werase(win);
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_top)) {
|
if (pthread_mutex_trylock(&mutex_top) == 0) {
|
||||||
wprintw(win,"loading");
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
wattron(win, COLOR_PAIR(COLOR_PATH));
|
wattron(win, COLOR_PAIR(COLOR_PATH));
|
||||||
mvwprintw(win, i, 0, "%s", top_content);
|
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||||
|
mvwaddstr(win, 0, 0, top_buffer);
|
||||||
|
}
|
||||||
wattroff(win, COLOR_PAIR(COLOR_PATH));
|
wattroff(win, COLOR_PAIR(COLOR_PATH));
|
||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
|
} else {
|
||||||
|
wprintw(win,"loading");
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_btm(WINDOW *win){
|
void window_btm(WINDOW *win){
|
||||||
werase(win);
|
werase(win);
|
||||||
if (pthread_mutex_trylock(&mutex_btm)) {
|
unsigned long local_width;
|
||||||
} else {
|
unsigned long local_height;
|
||||||
|
getmaxyx(win, local_height, local_width);
|
||||||
|
if (pthread_mutex_trylock(&mutex_btm) == 0) {
|
||||||
|
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||||
|
mvwprintw(win, 0, 0, "%s", btm_buffer);
|
||||||
|
}
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
|
/*the printing of the input char is done in user_interactions*/
|
||||||
|
/*the printing of all possible inputs are done in user_interactions */
|
||||||
|
} else {
|
||||||
|
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_lft(WINDOW *win){
|
void window_lft(WINDOW *win){
|
||||||
@@ -52,13 +68,13 @@ void window_lft(WINDOW *win){
|
|||||||
unsigned long local_width;
|
unsigned long local_width;
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
getmaxyx(win, local_height, local_width);
|
getmaxyx(win, local_height, local_width);
|
||||||
if (pthread_mutex_trylock(&mutex_lft)) {
|
if (pthread_mutex_trylock(&mutex_lft) == 0) {
|
||||||
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
print_dir(win, 0, &lft_file_count, lft_content);
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print_dir(win, &lft_file_count, lft_content);
|
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_mid(WINDOW *win){
|
void window_mid(WINDOW *win){
|
||||||
@@ -68,13 +84,16 @@ void window_mid(WINDOW *win){
|
|||||||
unsigned long local_width;
|
unsigned long local_width;
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
getmaxyx(win, local_height, local_width);
|
getmaxyx(win, local_height, local_width);
|
||||||
if (pthread_mutex_trylock(&mutex_mid)) {
|
if (pthread_mutex_trylock(&mutex_mid) == 0) {
|
||||||
|
if (mid_file_count == 0) {
|
||||||
|
mvwprintw(win, 0, 0, "empty");
|
||||||
|
} else {
|
||||||
|
print_dir(win, 1, &mid_file_count, mid_content);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
} else {
|
||||||
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 {
|
|
||||||
print_dir(win, &mid_file_count, mid_content);
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_rgt(WINDOW *win){
|
void window_rgt(WINDOW *win){
|
||||||
@@ -84,17 +103,21 @@ void window_rgt(WINDOW *win){
|
|||||||
unsigned long local_width;
|
unsigned long local_width;
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
getmaxyx(win, local_height, local_width);
|
getmaxyx(win, local_height, local_width);
|
||||||
if (pthread_mutex_trylock(&mutex_rgt)) {
|
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
|
||||||
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
if (rgt_file_count == 0) {
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
if (rgt_content[0].file_type == FILE_TYPE_OPEN_FILE) {
|
||||||
} else {
|
mvwprintw(win, 0, 0, "%s", rgt_buffer);
|
||||||
int i = 0;
|
} else {
|
||||||
for (i = 0; i < color_count; i++) {
|
mvwprintw(win, 0, 0, "empty");
|
||||||
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));
|
} else {
|
||||||
|
print_dir(win, 0, &rgt_file_count, rgt_content);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
|
} else {
|
||||||
|
mvwprintw(win, local_height/2, local_width/2, "LOADING");
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user