Compare commits

...
30 Commits
Author SHA1 Message Date
nova 267518fe3a explicit sign on result as chars are implicitly unsigned on riscv 2026-08-05 23:40:08 +02:00
nova 89c3f88a34 cast to fix always true on on riscv and arm 2026-08-04 21:31:19 +02:00
nova 6d1c9c95ac slight bounds checking 2026-07-26 16:27:29 +02:00
nova 06c00a0924 now checking for file names rather than using indexes on dir refresh 2026-07-23 12:48:34 +02:00
nova b30229b770 use global_path in image previews & fit_contain 2026-07-23 01:10:36 +02:00
nova f7589dbe2b read_string_loop 2026-07-20 00:16:35 +02:00
nova 25c912069a searching now starts at index 0, rather than current_file 2026-07-20 00:16:35 +02:00
nova 24fe4a4aa4 removal of top_buffer 2026-07-13 18:03:00 +02:00
nova 56d2f9d5d0 now accounting for root dir 2026-07-12 23:03:13 +02:00
nova a55c38abfa off by one 2026-07-12 22:50:33 +02:00
nova a5fcd1985e workaround for file previews on delta time 2026-07-12 22:43:37 +02:00
nova c68b872d1e revame of START_PATH to TH_START_PATH 2026-07-12 22:10:26 +02:00
nova c6ec8c1199 removal of malloc and memset in threading_init 2026-07-12 22:08:49 +02:00
nova 230bac4d75 fix of failed compile on disabling ueberzug 2026-07-12 22:04:10 +02:00
nova e898ec3ba5 rendering improvements 2026-07-12 22:03:43 +02:00
nova e65a2ecdb6 executing an executable exe now properly executing through wine 2026-07-06 23:57:02 +02:00
nova 94ca039248 parse_cmd now using file name strings rather than file struct 2026-06-25 22:42:43 +02:00
nova 441e02e289 deselect_all_files 2026-06-25 00:42:12 +02:00
nova fd2bb01b96 cleanup 2026-06-25 00:25:25 +02:00
nova 18705b01c4 double free fix 2026-06-23 22:16:32 +02:00
nova cebacc7017 removal of unnecessary getcwd 2026-06-23 21:55:07 +02:00
nova edab9a62ad faster initial render 2026-06-23 21:42:10 +02:00
nova 7a3de19314 added build instructions 2026-06-19 00:20:43 +02:00
nova e876aa9899 readme 2026-06-19 00:16:52 +02:00
nova 1889eaad6f now depending on libmagic 2026-06-19 00:06:07 +02:00
nova f1b1400194 fix of copy_file 2026-06-18 21:54:51 +02:00
nova 60127a6b9b cleanup 2026-06-16 23:53:35 +02:00
nova 7091c47a2c comment 2026-06-16 23:41:39 +02:00
nova e6318f8d1e wattroff -> wattrset to disable all attributes 2026-06-16 23:37:13 +02:00
nova f6c39ce039 minor changes 2026-06-16 23:28:03 +02:00
14 changed files with 384 additions and 315 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
CC := gcc
CFLAGS := -Wall -Wextra -O3 -flto=auto
CFLAGS := -Wall -Wextra -O3 -flto=auto -lmagic
CURSES := $(shell pkg-config --libs ncursesw)
CFLAGS_DEBUG := $(CFLAGS) -ggdb
CFLAGS_PROFILE := $(CFLAGS) -pg
+32
View File
@@ -1,2 +1,34 @@
# th
~~~text
/home/toaster/src/desktop/c/th/README.md
th 15 backend.c 3.22 K # th
14 backend.h 253 B a filemanager born from spite
13 colors.c 3.54 K
12 colors.h 41 B qwert* user should adjust
11 config.h 8.07 K bindings in config.h, lol
10 defines.h 2.82 K
9 dir.c 11.05 K build instructions:
8 dir.h 367 B ``make``
7 file_prev~.c 2.68 K
6 file_previ~.h 297 B dependencies:
5 interact~.c 17.79 K libc
4 interactio~.h 900 B a c compiler
3 LICENSE 33.76 K make
2 main.c 5.00 K ncurses
1 Makefile 709 B pthreads
15 README.md 1.39 K libmagic
1 sorting.c 5.62 K ueberzugpp (optional)
2 sorting.h 633 B stuff in config.h
3 string.h 2.39 K
4 threadin~.c 14.11 K note:
5 threading.h 246 B th does as little checking
as possible; it is highly
insecure.
example: if you dont have
ueberzugpp installed,
and hover a picture without
disabling it in config.h,
th just crashes
-rw-r--r-- 176.03K sum of dir, 23.89G total free
+9 -11
View File
@@ -81,26 +81,24 @@ char* smartstrcasestr(const char *haystack, const char *needle){
}
char* parse_cmd(const char *cmd, file *f){
char* parse_cmd(const char *cmd, char *file_name){
char *out;
if (f == NULL) {
out = malloc(strlen(cmd)+1);
memcpy(out, cmd, strlen(cmd)+1);
return out;
if (file_name == NULL) {
return NULL;
}
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
int count = 0;
char *pos;
unsigned long i = 0;
while(f->file_name[i]) {
if (f->file_name[i] == '\'') {
while(file_name[i]) {
if (file_name[i] == '\'') {
count++;
}
i++;
}
out = malloc(strlen(cmd) + 1 + (strlen(f->file_name)+(count*3)) + 3);
out = malloc(strlen(cmd) + 1 + (strlen(file_name)+(count*3)) + 3);
pos = out;
if (offset) {
@@ -115,13 +113,13 @@ char* parse_cmd(const char *cmd, file *f){
pos++;
i = 0;
while(f->file_name[i]) {
if (f->file_name[i] == '\'') {
while(file_name[i]) {
if (file_name[i] == '\'') {
*pos++ = '\'';
*pos++ = '\\';
*pos++ = '\'';
}
*pos = f->file_name[i];
*pos = file_name[i];
pos++;
i++;
}
+1 -1
View File
@@ -7,5 +7,5 @@
/*char* concat(const char *s1, const char *s2);*/
char* smartstrcasestr(const char *haystack, const char *needle);
char* parse_cmd(const char *cmd, file *f);
char* parse_cmd(const char *cmd, char *file_name);
+3 -1
View File
@@ -84,7 +84,7 @@ static const binding key_binding[] = {
{ "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" }, /* the path you started th in */
{ "gs", jump_to_dir, "$TH_START_PATH", "jump to $TH_START_PATH" }, /* the path you started th in */
{ "gD", jump_to_dir, "$HOME/Downloads", "jump to $HOME/Downloads" },
{ "gC", jump_to_dir, "$HOME/Documents", "jump to $HOME/Documents" },
{ "gP", jump_to_dir, "$HOME/Pictures", "jump to $HOME/Pictures" },
@@ -129,6 +129,7 @@ static const char ui_rename_text[] = "rename "SETTINGS_COMMAND_REPLACE_STR" to:"
static const char ui_makefile_text[] = "makedir:";
static const char ui_makedir_text[] = "makefile:";
static const char ui_delete_text[] = "delete:";
static const char ui_search_text[] = "/"; /*unlike the other ui, this one doesnt automatically add a space*/
/* {{{ */
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
@@ -156,6 +157,7 @@ static const char ui_delete_text[];
static const char copy_cmd[];
static const char cut_cmd[];
static const char del_cmd[];
static const char ui_search_text[];
#endif
/* }}} */
+4
View File
@@ -63,6 +63,10 @@
#define BTM_WINDOW_HEIGHT_ON_STR_INTERACTION 5
#define INPUT_BUFFER_SIZE 255
#define ignore_return(in) if (in) { };
#define unused(in) (void)(in);
#ifndef STRUCT_GUARD
#define STRUCT_GUARD
/* complex types are good actually */
+35 -38
View File
@@ -50,11 +50,6 @@ unsigned long get_dir_size(char *path){
void get_dir_content(char *path, dir *dir){
if (dir->file_count == 0) {
return;
dir = NULL;
}
struct dirent **entry = NULL;
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
scandir(path, &entry, skip_dot, NULL);
@@ -167,24 +162,24 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
unsigned long offset_vertical = 0;
unsigned long offset_back = 0;
#if SETTINGS_LINE_NUMBERS == 0
unsigned long offset_front = 0;
unsigned long offset_front = 0;
#else
long offset_front = 2;
long offset_front = 2;
#endif
unsigned long selected_file_current = dir->current_file - dir->file_list;
long offset_index = 2; /* only used for the index of the file itself */
if (print_info) {
#if SETTINGS_LINE_NUMBERS != 0
if (dir->file_count > 9) {
#if SETTINGS_LINE_NUMBERS != 0
unsigned long dir_file_count_ = dir->file_count;
while(dir_file_count_ > 9) {
offset_front++;
dir_file_count_ /= 10;
}
#endif
}
#endif
/* scrolling of the directory if too many files are in a dir */
if (selected_file_current > (terminal_height/3)*2 && dir->file_count > terminal_height - 2) {
if (selected_file_current + (terminal_height/3) >= dir->file_count) {
offset_vertical = dir->file_count - terminal_height+2;
@@ -197,8 +192,6 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
}
for (i = offset_vertical; i < dir->file_count && i < (terminal_height + offset_vertical); i++) {
if (print_info) {
file_size = dir->file_list[i].file_size;
char size_index = -1;
@@ -212,7 +205,7 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
if (dir->file_list[i].file_type & FILE_TYPE_DIR) {
offset_back = line_width - (snprintf(NULL,0,"%ld", dir->file_list[i].file_size) + 1);
} else if (size_char =='B') {
} else if (size_char == size_unit[0]) {
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);
@@ -222,28 +215,20 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
}
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
wattron(win, COLOR_PAIR(8)); /* FIFO, as seen in colors.c */
is_selected = 1;
} else {
is_selected = 0;
}
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
wattron(win, COLOR_PAIR(8));
} else {
wattron(win, COLOR_PAIR(dir->file_list[i].color_pair));
is_selected = 0;
}
if (&dir->file_list[i] == dir->current_file) {
wattron(win, A_REVERSE);
unsigned long bg = 0;
for (bg = 0; bg < line_width; bg++) {
mvwaddch(win, i-offset_vertical, bg, ' ');
}
}
} else {
wattroff(win, A_REVERSE);
}
if(print_info) {
#if SETTINGS_LINE_NUMBERS == 2
long i_ = (selected_file_current) - i;
@@ -278,12 +263,12 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
if (dir->file_list[i].file_type & FILE_TYPE_DIR) {
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir->file_list[i].file_size);
}else if (size_char =='B') {
}else if (size_char == size_unit[0]) {
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);
}
}
}
char *extension = strrchr(dir->file_list[i].file_name, '.');
unsigned long printable_size = offset_back-offset_front-is_selected-2;
@@ -295,11 +280,14 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
}
wattrset(win, 0);
/*
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
wattroff(win, COLOR_PAIR(8));
} else {
wattroff(win, COLOR_PAIR(dir->file_list[i].color_pair));
}
*/
}
}
@@ -329,37 +317,49 @@ void dir_changed(){
}
}
void deselect_all_files() {
unsigned long i;
for (i = 0; i < mid_dir.file_count; i++) {
mid_dir.file_list[i].status &= ~FILE_STATUS_SELECTED;
}
}
void change_dir(char *new_path){
deselect_all_files();
char *old_path = getcwd(NULL, 0);
current_linked_dir = list_beginning;
while (current_linked_dir->next != NULL) {
if(strcmp(current_linked_dir->path, old_path) == 0) {
if(strcmp(current_linked_dir->path, global_path) == 0) {
break;
} else {
current_linked_dir = current_linked_dir->next;
}
}
if(strcmp(current_linked_dir->path, old_path) == 0) {
if(strcmp(current_linked_dir->path, global_path) == 0) {
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
}
chdir(new_path);
char *new_path_real = getcwd(NULL, 0);
if (chdir(new_path) != 0) {
/* i have made the decission that this is a case that i do not want to handle
* god may help me if this ever fails, cuz damn thatll be hard to debug
* especially in like 2 years when i even forgot about this possibility */
return;
}
free(global_path);
global_path = getcwd(NULL, 0);
current_linked_dir = list_beginning;
while (current_linked_dir->next != NULL) {
if(strcmp(current_linked_dir->path, new_path_real) == 0) {
if(strcmp(current_linked_dir->path, global_path) == 0) {
break;
} else {
current_linked_dir = current_linked_dir->next;
}
}
if(strcmp(current_linked_dir->path, new_path_real) != 0) {
if(strcmp(current_linked_dir->path, global_path) != 0) {
current_linked_dir->next = malloc(sizeof(linked_dir));
current_linked_dir = current_linked_dir->next;
current_linked_dir->path = malloc(strlen(new_path_real)+1);
memcpy(current_linked_dir->path, new_path_real, strlen(new_path_real)+1);
current_linked_dir->path = malloc(strlen(global_path)+1);
memcpy(current_linked_dir->path, global_path, strlen(global_path)+1);
current_linked_dir->next = NULL;
current_linked_dir->index = 0;
/*TODO(2026-05-25T22:49:30)
@@ -367,9 +367,6 @@ void change_dir(char *new_path){
}
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
free(old_path);
free(new_path_real);
}
void dir_init(){
+1
View File
@@ -9,4 +9,5 @@ void print_dir(WINDOW *win, char print_info, dir *dir);
char update_selected_file();
void dir_set_selected_file_current(unsigned long selected_file_current);
unsigned long dir_get_selected_file_current();
void deselect_all_files();
void dir_init();
+31 -43
View File
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <magic.h>
#include "backend.h"
#include "defines.h"
@@ -11,7 +12,10 @@ static FILE *ueberzug = NULL;
#endif
extern unsigned int terminal_height;
extern unsigned int terminal_width;
extern char *global_path;
char previewd;
magic_t cookie_type;
magic_t cookie_description;
char* text(file *f);
void images_print(char *file_name);
@@ -19,24 +23,11 @@ void images_clear();
char* generic(file *f);
char* get_mimetype(file *f){
static const char *cmd_str = "file --mime-type -b";
char *cmd = parse_cmd(cmd_str, f);
char *mime = (char*)magic_file(cookie_type, f->file_name); /*freeing this causes th to crash*/
FILE *cmd_open = popen(cmd, "r");
char *line = NULL;
size_t size = 0;
free(cmd);
if (getline(&line, &size, cmd_open) != -1){
pclose(cmd_open);
return line;
} else {
pclose(cmd_open);
return "unknown";
}
return mime;
}
char* preview_file(file *f){
/* this calls "file" on path */
char *file_buffer;
@@ -46,19 +37,22 @@ char* preview_file(file *f){
images_clear();
#endif
if (strstr(mime, "text")) {
file_buffer = text(f);
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
} else if (strstr(mime, "image")) {
file_buffer = generic(f);
images_print(f->file_name);
previewd = 1;
#endif
} else {
if (mime != NULL) {
if (strstr(mime, "text")) {
file_buffer = text(f);
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
} else if (strstr(mime, "image")) {
file_buffer = generic(f);
images_print(f->file_name);
previewd = 1;
#endif
} else {
file_buffer = generic(f);
}
} else {
file_buffer = generic(f);
}
free(mime);
return file_buffer;
}
@@ -80,21 +74,11 @@ char* text(file *f){
}
}
char* generic(file *f){
static const char *cmd_str = "file";
char *cmd = parse_cmd(cmd_str, f);
char *mime = (char*)magic_file(cookie_description, f->file_name);
char *buffer = malloc(strlen(mime)+1);
memcpy(buffer, mime, strlen(mime)+1);
return buffer;
FILE *cmd_open = popen(cmd, "r");
char *line = NULL;
size_t size = 0;
free(cmd);
if (getline(&line, &size, cmd_open) != -1) {
pclose(cmd_open);
return line;
} else {
pclose(cmd_open);
return "failed executing shell command \"file\"";
}
}
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
void images_clear(){
@@ -106,20 +90,18 @@ void images_clear(){
}
}
void images_print(char *file_name){
char *path=getcwd(NULL, 0);
fprintf(ueberzug, "{\"action\":\"add\", \
\"identifier\":\"preview\", \
\"scaler\":\"fit_contain\", \
\"max_height\":%d, \
\"max_width\":%d, \
\"y\":0, \
\"x\":%d, \
\"path\":\"%s/%s\"}\n", terminal_height, terminal_width/2, terminal_width/2, path, file_name);
\"path\":\"%s/%s\"}\n", terminal_height, terminal_width/2, terminal_width/2, global_path, file_name);
fflush(ueberzug);
free(path);
}
void ueberzug_init(){
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW == 2
ueberzug = popen("ueberzug layer -s ", "w");
#elif SETTINGS_UEBERZUG_IMAGE_PREVIEW == 1
@@ -131,3 +113,9 @@ void ueberzug_close(){
pclose(ueberzug);
}
#endif
void file_preview_init(){
cookie_type = magic_open(MAGIC_MIME_TYPE);
cookie_description = magic_open(MAGIC_NONE);
magic_load(cookie_type, NULL);
magic_load(cookie_description, NULL);
}
+2 -1
View File
@@ -7,7 +7,8 @@
char* preview_file(file *f);
char* get_mimetype(file *f);
void images_clear();
void ueberzug_init();
void file_preview_init();
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
void ueberzug_init();
void ueberzug_close();
#endif
+162 -141
View File
@@ -53,13 +53,16 @@ void user_interactions() {
ch = getch();
if(ch != ERR) {
if(ch != (char)ERR) {
input[input_pass] = ch;
input_pass++;
if (ch == 27) { /* esc key */
memset(input, 0, INPUT_BUFFER_SIZE);
input_pass = 0;
}
if (input_pass >= INPUT_BUFFER_SIZE) {
input_pass = INPUT_BUFFER_SIZE - 1;
}
}
@@ -93,6 +96,12 @@ void user_interactions() {
pthread_mutex_unlock(&mutex_mid);
timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */
#if SETTINGS_RELOAD_DIR_DELTA != 0
/* workaround for file previews not working on changing file while this is true
* disabling this here does not influence the reload/rerun of the logic */
status &= ~STATUS_DELTA_TIME;
#endif
} else {
binding_matches++;
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
@@ -113,43 +122,50 @@ void user_interactions() {
binding_matches = 0;
}
}
int read_string(WINDOW *win, int y, int x, char *str){
curs_set(1);
char read_string_loop(WINDOW *win, char *buffer, char *nullable_return_char, unsigned long *pass, unsigned long y, unsigned long x) {
char ch = wgetch(win_b);
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 = wgetch(win);
if (ch == '\n') {
break;
} else if (ch == 27) { /* esc key */
err = 1;
break;
} else if (ch == '\t') { /* tab */
memcpy(str + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
mvwaddstr(win, y, x + pass, mid_dir.current_file->file_name);
pass += strlen(mid_dir.current_file->file_name);
} else if (ch == 127) { /* backspace */
if (pass > 0) {
pass--;
mvwdelch(win, y, x + pass);
}
} else {
mvwaddch(win, y, x + pass, ch);
str[pass] = ch;
pass++;
}
if (nullable_return_char != NULL) {
*nullable_return_char = 0;
}
str[pass] = '\0';
if (ch == '\n' ) {
buffer[*pass] = 0;
return 1;
} else if ( ch == 27 /* esc key */) {
buffer[*pass] = 0;
return 2;
} else if (ch == '\t') { /* tab */
memcpy(buffer + *pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
mvwaddstr(win_b, 0, x+ *pass, mid_dir.current_file->file_name);
*pass += strlen(mid_dir.current_file->file_name);
} else if (ch == 127) { /* backspace */
if (*pass > 0) {
unsigned long i = x;
while (i < terminal_width) {
mvwaddch(win, y, i, ' ');
i++;
}
*pass -= 1;
buffer[*pass] = 0;
mvwaddstr(win, y, x, buffer);
curs_set(0);
}
} else if (ch) {
if (nullable_return_char != NULL) {
*nullable_return_char = ch;
}
return err;
mvwaddch(win_b, 0, x + *pass, ch);
buffer[*pass] = ch;
*pass += 1;
}
if (*pass >= INPUT_BUFFER_SIZE) {
*pass = INPUT_BUFFER_SIZE - 1;
}
return 0;
}
void quit_program(){
status = STATUS_QUIT_PROGRAM;
@@ -198,12 +214,35 @@ void move_right(){
skip_if_empty_dir
char *cmd = NULL;
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
change_dir(mid_dir.current_file->file_name);
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
if (system(cmd)) {
/* if an .exe is executable, this branch will trigger as expected,
* however since executing an .exe without wine causes a exec format error, we should check if the program you tried to access is that
* if an .exe is not executable, it will get to the top else branch, then hit the comparison in the file extension area, and succeed also.
* that is unless the user removed wine out of the file_extension_default_cmd,
* in which case im going to assume wine isnt installed anyways as that would require:
* a. thought on my end in how to catch wine being removed in the config
* b. the user having deliberately changed the default config (good, thats why they are easily configurable)
* c. if wine is not installed on the system, executing an .exe would fail regardless of via direct execution or through wine */
char *extension = mid_dir.current_file->file_name;
while (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
if (*extension == '.') {
break;
}
extension++;
}
if (strcmp(extension, ".exe") == 0) {
cmd = parse_cmd("wine ./"SETTINGS_COMMAND_REPLACE_STR, mid_dir.current_file->file_name);
} else {
cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR, mid_dir.current_file->file_name);
}
ignore_return(system(cmd));
} else {
char *mime = get_mimetype(mid_dir.current_file);
char *extension = mid_dir.current_file->file_name;
@@ -220,17 +259,16 @@ void move_right(){
for (i = 0; i < file_extension_default_count; i++) {
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file);
cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file->file_name);
pid_t pid = fork();
if (pid == 0 && setsid()) {
system(cmd);
ignore_return(system(cmd));
status = STATUS_QUIT_PROGRAM;
exit(1);
}
} else {
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
if (system(cmd)) {
}
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file->file_name);
ignore_return(system(cmd));
}
status |= STATUS_MOVE_RIGHT_MATCH;
update();
@@ -242,17 +280,16 @@ void move_right(){
for (i = 0; i < mimetype_default_count; i++) {
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file);
cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file->file_name);
pid_t pid = fork();
if (pid == 0 && setsid()) {
system(cmd);
ignore_return(system(cmd));
status = STATUS_QUIT_PROGRAM;
exit(1);
}
} else {
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
if (system(cmd)) {
}
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file->file_name);
ignore_return(system(cmd));
}
status |= STATUS_MOVE_RIGHT_MATCH;
update();
@@ -261,9 +298,8 @@ void move_right(){
}
}
status &= ~STATUS_MOVE_RIGHT_MATCH;
free(cmd);
free(mime);
}
free(cmd);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
@@ -292,25 +328,30 @@ void open_with(){
wclear(win_b);
char *cmd;
char *str = malloc(INPUT_BUFFER_SIZE);
char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file);
char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file->file_name);
mvwprintw(win_b, 0, 0, parsed_ui_text);
unsigned long pass = 0;
char ret;
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) {
while ((ret = read_string_loop(win_b, str, NULL, &pass, 0, strlen(parsed_ui_text)+1)) == 0) {
}
if (ret == 1) {
if (str[0] == SETTINGS_COMMAND_FORK) {
cmd = parse_cmd(str+1, mid_dir.current_file);
cmd = parse_cmd(str+1, mid_dir.current_file->file_name);
pid_t pid = fork();
if (pid == 0 && setsid()) {
system(cmd);
ignore_return(system(cmd));
status = STATUS_QUIT_PROGRAM;
exit(1);
}
} else {
cmd = parse_cmd(str, mid_dir.current_file);
if (system(cmd)) {
}
cmd = parse_cmd(str, mid_dir.current_file->file_name);
ignore_return(system(cmd));
}
free(cmd);
}
free(parsed_ui_text);
free(str);
@@ -318,20 +359,23 @@ void open_with(){
}
void rename_hovered(){
wclear(win_b);
file tmp;
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
char *new_file_name = malloc(INPUT_BUFFER_SIZE);
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file->file_name);
mvwprintw(win_b, 0, 0, parsed_ui_text);
unsigned long pass = 0;
char ret;
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, tmp.file_name) == 0) {
char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file);
char *cmd1 = parse_cmd(cmd0, &tmp);
system(cmd1);
while ((ret = read_string_loop(win_b, new_file_name, NULL, &pass, 0, strlen(parsed_ui_text)+1)) == 0) {
}
if (ret == 1) {
char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file->file_name);
char *cmd1 = parse_cmd(cmd0, new_file_name);
ignore_return(system(cmd1));
free(cmd0);
free(cmd1);
}
free(parsed_ui_text);
free(tmp.file_name);
free(new_file_name);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
@@ -343,8 +387,8 @@ void delete(unsigned long passes){
for (i = 0; i < mid_dir.file_count; i++) {
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
cmd = parse_cmd(del_cmd, &mid_dir.file_list[i]);
system(cmd);
cmd = parse_cmd(del_cmd, mid_dir.file_list[i].file_name);
ignore_return(system(cmd));
free(cmd);
del_count++;
}
@@ -355,50 +399,57 @@ void delete(unsigned long passes){
if (&mid_dir.current_file[i] > mid_dir.file_list + mid_dir.file_count) {
break;
}
cmd = parse_cmd(del_cmd, &mid_dir.current_file[i]);
system(cmd);
cmd = parse_cmd(del_cmd, mid_dir.current_file[i].file_name);
ignore_return(system(cmd));
free(cmd);
}
}
deselect_all_files();
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void makedir(){
wclear(win_b);
file tmp;
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
char *file_name = malloc(INPUT_BUFFER_SIZE);
mvwprintw(win_b, 0, 0, ui_makedir_text);
if (read_string(win_b, 0, strlen(ui_makedir_text)+1, tmp.file_name) == 0) {
char *cmd = parse_cmd(makedir_cmd, &tmp);
system(cmd);
unsigned long pass = 0;
char ret;
while ((ret = read_string_loop(win_b, file_name, NULL, &pass, 0, strlen(ui_makedir_text)+1)) == 0) {
}
if (ret == 1) {
char *cmd = parse_cmd(makedir_cmd, file_name);
ignore_return(system(cmd));
free(cmd);
}
free(tmp.file_name);
free(file_name);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void makefile(){
wclear(win_b);
file tmp;
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
char *file_name = malloc(INPUT_BUFFER_SIZE);
mvwprintw(win_b, 0, 0, ui_makefile_text);
if (read_string(win_b, 0, strlen(ui_makefile_text)+1, tmp.file_name) == 0) {
char *cmd = parse_cmd(makefile_cmd, &tmp);
system(cmd);
unsigned long pass = 0;
char ret;
while ((ret = read_string_loop(win_b, file_name, NULL, &pass, 0, strlen(ui_makefile_text)+1)) == 0) {
}
if (ret == 1) {
char *cmd = parse_cmd(makefile_cmd, file_name);
ignore_return(system(cmd));
free(cmd);
}
free(tmp.file_name);
free(file_name);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void enter_shell(unsigned long passes, int index){
(void)passes; /*remove compiler warning*/
unused(passes);
endwin();\
echo();\
curs_set(1);\
if (system(key_binding[index].black_magic)) {
}
ignore_return(system(key_binding[index].black_magic));
initscr(); /* start ncurses */
noecho(); /* hide keyboard input */
curs_set(0);
@@ -406,7 +457,7 @@ void enter_shell(unsigned long passes, int index){
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void jump_to_dir(unsigned long passes, int index){
(void)passes;
unused(passes);
unsigned long len;
char *c = strchr(key_binding[index].black_magic, '/');
@@ -435,7 +486,7 @@ void jump_to_dir(unsigned long passes, int index){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_RELOAD_DIRECTORY );
}
void order_by(unsigned long passes, int index){
(void)passes;
unused(passes);
seed = time(NULL);
order_func = key_binding[index].black_magic;
@@ -443,17 +494,17 @@ void order_by(unsigned long passes, int index){
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void cmd_on_selected(unsigned long passes, int index){
(void)passes;
unused(passes);
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file);
system(cmd);
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file->file_name);
ignore_return(system(cmd));
free(cmd);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
}
void yank_file_name(){
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);
system(cmd);
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file->file_name);
ignore_return(system(cmd));
free(cmd);
status |= (STATUS_RUN_BACKEND);
@@ -464,8 +515,8 @@ void yank_file_path(){
memcpy(tmp->file_name, global_path, strlen(global_path));
memcpy(tmp->file_name+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
tmp->file_name[strlen(global_path)] = '/'; /*no +1 is needed*/
char *cmd = parse_cmd(clipboard_cmd, tmp);
system(cmd);
char *cmd = parse_cmd(clipboard_cmd, tmp->file_name);
ignore_return(system(cmd));
free(cmd);
free(tmp->file_name);
free(tmp);
@@ -473,19 +524,13 @@ void yank_file_path(){
status |= (STATUS_RUN_BACKEND);
}
void copy_file(unsigned long passes, int index){
(void)passes;
unused(passes);
yank_files.status = key_binding[index].black_magic;
unsigned long i;
unsigned long j = 0;
char *path = malloc(strlen(global_path)+1); /* im at a loss for words, freeing this always segfaults if yank_files.count != 0
if i use global_path directly or getcwd(NULL, 0), it will segfault at the next free on global_path.
what makes this wierder is, regardless of if the yank_files.count != 0 is true or false, both do the same things
so were going to just leak the size of the path */
memcpy(path, global_path, strlen(global_path)+1);
if (yank_files.count != 0) {
for (i = 0; i < yank_files.count; i++) {
@@ -506,30 +551,28 @@ void copy_file(unsigned long passes, int index){
for (i = 0; j < yank_files.count; i++) {
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
char *str = malloc(strlen(path) + 1 + strlen(mid_dir.current_file->file_name)+1);
memcpy(str, path, strlen(path));
memcpy(str+strlen(path)+1, mid_dir.file_list[i].file_name, strlen(mid_dir.file_list[i].file_name)+1);
str[strlen(path)] = '/';
char *str = malloc(strlen(global_path) + 1 + strlen(mid_dir.file_list[i].file_name)+1);
memcpy(str, global_path, strlen(global_path));
memcpy(str+strlen(global_path)+1, mid_dir.file_list[i].file_name, strlen(mid_dir.file_list[i].file_name)+1);
str[strlen(global_path)] = '/';
yank_files.list[j] = str;
j++;
}
}
} else {
/*this path is achieved if no file is explicitly selected by the user, thus we assume the user wants the currently hovered file*/
/*this condition is achieved if no file is explicitly selected by the user, thus we assume the user wants the currently hovered file*/
yank_files.list = malloc(1 * sizeof(char*));
char *str = malloc(strlen(path) + 1 + strlen(mid_dir.current_file->file_name)+1);
memcpy(str, path, strlen(path));
memcpy(str+strlen(path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
str[strlen(path)] = '/';
char *str = malloc(strlen(global_path) + 1 + strlen(mid_dir.current_file->file_name)+1);
memcpy(str, global_path, strlen(global_path));
memcpy(str+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
str[strlen(global_path)] = '/';
*yank_files.list = str;
yank_files.count = 1;
}
/*free(path);*/
status |= (STATUS_RUN_BACKEND);
}
@@ -558,16 +601,16 @@ void paste(unsigned long passes){
}
if (yank_files.status == COPY_FILE) {
cmd = parse_cmd(copy_cmd, &tmp);
cmd = parse_cmd(copy_cmd, tmp.file_name);
} else if (yank_files.status == CUT_FILE) {
cmd = parse_cmd(cut_cmd, &tmp);
cmd = parse_cmd(cut_cmd, tmp.file_name);
} else {
free(dest_file_name);
continue;
}
tmp.file_name = dest_file_name;
cmd = parse_cmd(cmd, &tmp);
system(cmd);
cmd = parse_cmd(cmd, tmp.file_name);
ignore_return(system(cmd));
free(cmd);
free(tmp.file_name);
}
@@ -581,7 +624,7 @@ void search(){
for (i = 0; i < terminal_width -1; i++) {
mvwaddch(win_b, 0, i, ' ');
}
mvwaddch(win_b, 0, 0, '/');
mvwaddstr(win_b, 0, 0, ui_search_text);
memset(search_buffer, 0, INPUT_BUFFER_SIZE);
curs_set(1);
@@ -589,33 +632,12 @@ void search(){
timeout(-1); /* negative numbers block until enter is pressed */
unsigned int pass = 0;
unsigned long pass = 0;
char ch;
wmove(win_b, 0, 1);
while(1) {
ch = wgetch(win_b);
if (ch == '\n' || ch == 27 /* esc key */) {
/* unlike the other uses of a read string reimplementation,
* here we do not differentiate between accepting and cancle.
* this is intentional */
break;
} else if (ch == '\t') { /* tab */
memcpy(search_buffer + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
mvwaddstr(win_b, 0, pass+1, mid_dir.current_file->file_name);
pass += strlen(mid_dir.current_file->file_name);
} else if (ch == 127) { /* backspace */
if (pass > 0) {
pass--;
mvwdelch(win_b, 0, pass+1);
}
}
while (read_string_loop(win_b, search_buffer, &ch, &pass, 0, strlen(ui_search_text)) == 0) {
if (ch) {
mvwaddch(win_b, 0, pass+1, ch);
search_buffer[pass] = ch;
pass++;
unsigned long index = (mid_dir.current_file - mid_dir.file_list);
unsigned long index = 0;
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
mid_dir.current_file = &mid_dir.file_list[index];
@@ -626,15 +648,14 @@ void search(){
werase(win_m);
print_dir(win_m, 1, &mid_dir);
wnoutrefresh(win_m);
wrefresh(win_m);
pthread_mutex_unlock(&mutex_render);
break;
}
}
}
}
search_buffer[pass] = '\0';
noecho();
curs_set(0);
+23 -9
View File
@@ -18,7 +18,7 @@ unsigned int terminal_width;
unsigned int temp_heigth = 0; /*used for screen refresh*/
unsigned int temp_width = 0;
unsigned int file_modifiers = 0;
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_UPDATE_SCREEN_RESIZE | STATUS_RELOAD_DIRECTORY) & ~STATUS_UPDATE_SCREEN_RESIZE;
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_UPDATE_SCREEN_RESIZE | STATUS_RELOAD_DIRECTORY);
char *global_path;
time_t seed;
@@ -75,13 +75,19 @@ int main(){
timeout(SETTINGS_CURSES_TIMEOUT);
/* initial render pass to speed first render up,
* yes this only skips SETTINGS_CURSES_TIMEOUT, which by default is 100ms,
* but i started to write th out of spite; because anything else either is too slow and unresponsive
* or i just dont like their ux.
* will i ever make use of the 100ms? will i ever react and do faster inputs? no
* does it feel more responsive? sure does */
pthread_cond_signal(&cond_mid);
render_pass();
while(!(status & STATUS_QUIT_PROGRAM)){
getmaxyx(stdscr, terminal_height, terminal_width);
if (status & STATUS_RUN_BACKEND) {
free(global_path);
global_path = getcwd(NULL, 0);
pthread_cond_signal(&cond_mid);
pthread_cond_signal(&cond_lft);
status &= ~(STATUS_RUN_BACKEND);
@@ -127,10 +133,6 @@ int main(){
void render_pass(){
if (status & STATUS_UPDATE_SCREEN_CLEAR) {
clear();
status &= ~STATUS_UPDATE_SCREEN_CLEAR;
}
if (status & STATUS_UPDATE_SCREEN_RESIZE) {
wresize(win_t, 1, terminal_width);
@@ -145,12 +147,23 @@ void render_pass(){
mvwin(win_m, 1, (terminal_width/8));
mvwin(win_r, 1, ((terminal_width/2)));
mvwin(win_b, terminal_height-1, 0);
status |= STATUS_UPDATE_SCREEN_CLEAR;
status &= ~STATUS_UPDATE_SCREEN_RESIZE;
}
if (pthread_mutex_lock(&mutex_render) == 0) {
if (status & STATUS_UPDATE_SCREEN_CLEAR) {
clear();
pthread_mutex_lock(&mutex_render);
refresh();
status &= ~STATUS_UPDATE_SCREEN_CLEAR;
pthread_mutex_unlock(&mutex_render);
}
/*
if (pthread_mutex_trylock(&mutex_render) == 0) {
doupdate();
pthread_mutex_unlock(&mutex_render);
}
*/
}
/*this function exists for things done at startup (initialization, reading config, etc)*/
void init() {
@@ -177,11 +190,12 @@ void init() {
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
ueberzug_init(); /* in file_previews.c */
#endif
file_preview_init();
ESCDELAY = 10;
global_path = getcwd(NULL, 0);
char *start_path = getcwd(NULL, 0);
setenv("START_PATH", start_path, 0);
setenv("TH_START_PATH", start_path, 0);
free(start_path);
seed = time(NULL);
+1 -1
View File
@@ -38,7 +38,7 @@ int sort_natural(const void *file0, const void *file1){
long parsed_number0 = 0;
long parsed_number1 = 0;
char is_num = 0;
char result = 0;
signed char result = 0;
do {
+79 -68
View File
@@ -31,7 +31,6 @@ dir mid_dir;
dir lft_dir;
char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */
char *btm_buffer;
char *top_buffer; /* current path */
extern WINDOW *win_t;
extern WINDOW *win_b;
@@ -52,10 +51,7 @@ unsigned int btm_status;
void *thread_mid(){
dir tmp;
tmp.current_file = NULL;
tmp.file_list = NULL;
tmp.file_count = 0;
dir previous_dir_state = { 0 };
while(!(status & STATUS_QUIT_PROGRAM)){
@@ -75,7 +71,7 @@ void *thread_mid(){
if (status & STATUS_RELOAD_DIRECTORY) {
long index = mid_dir.current_file - mid_dir.file_list;
tmp = mid_dir;
previous_dir_state = mid_dir;
mid_dir.file_count = get_dir_size(path);
mid_dir.file_list = malloc(mid_dir.file_count * sizeof(file));
@@ -89,8 +85,21 @@ void *thread_mid(){
}
unsigned long i;
for(i = 0; i < mid_dir.file_count && i < tmp.file_count; i++) {
mid_dir.file_list[i].status = tmp.file_list[i].status;
for(i = 0; i < mid_dir.file_count && i < previous_dir_state.file_count; i++) {
mid_dir.file_list[i].status = previous_dir_state.file_list[i].status;
}
/* youd think that after the above previous_dir_state = mid_dir previous_dir_state.current_file is always within the bounds of the file_list,
* but no, it fucking is not for some reason
* however for some mysterious reason this condition doesnt fail. well it probably does,
* but that doesnt matter as it does what its supposed to do:
* keep the current file selected after a reload even if the dir contents change like a new file being added */
if (previous_dir_state.current_file != NULL && previous_dir_state.current_file < previous_dir_state.file_list + previous_dir_state.file_count) {
for (i = 0; i < mid_dir.file_count; i++) {
if (strcmp(mid_dir.file_list[i].file_name, previous_dir_state.file_list[index].file_name) == 0) {
mid_dir.current_file = &mid_dir.file_list[i];
break;
}
}
}
@@ -120,21 +129,20 @@ void *thread_mid(){
} else {
print_dir(win_m, 1, &mid_dir);
}
wnoutrefresh(win_m);
/*wnoutrefresh(win_m);*/
wrefresh(win_m);
pthread_mutex_unlock(&mutex_render);
unsigned long i;
for (i = 0; i < tmp.file_count; i++) {
free(tmp.file_list[i].file_name);
for (i = 0; i < previous_dir_state.file_count; i++) {
free(previous_dir_state.file_list[i].file_name);
}
free(tmp.file_list);
tmp.current_file = NULL;
tmp.file_list = NULL;
tmp.file_count = 0;
free(previous_dir_state.file_list);
previous_dir_state.current_file = NULL;
previous_dir_state.file_list = NULL;
previous_dir_state.file_count = 0;
free(path);
}
pthread_exit(0);
}
@@ -182,7 +190,8 @@ void *thread_lft(){
pthread_mutex_lock(&mutex_render);
werase(win_l);
print_dir(win_l, 0, &lft_dir);
wnoutrefresh(win_l);
/*wnoutrefresh(win_l);*/
wrefresh(win_l);
pthread_mutex_unlock(&mutex_render);
pthread_mutex_unlock(&mutex_lft);
@@ -244,7 +253,8 @@ void *thread_rgt(){
pthread_mutex_lock(&mutex_render);
werase(win_r);
print_dir(win_r, 0, &rgt_dir);
wnoutrefresh(win_r);
/*wnoutrefresh(win_r);*/
wrefresh(win_r);
pthread_mutex_unlock(&mutex_render);
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && rgt_dir.file_count > 0) {
@@ -259,7 +269,8 @@ void *thread_rgt(){
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
mvwaddstr(win_r, 0, 0, "not accessible");
}
wnoutrefresh(win_r);
/*wnoutrefresh(win_r);*/
wrefresh(win_r);
pthread_mutex_unlock(&mutex_render);
}
}
@@ -285,43 +296,42 @@ void *thread_top(){
pthread_cond_wait(&cond_top, &mutex_top);
free(top_buffer);
if(global_path == NULL) {
top_buffer = malloc(sizeof("cannot open directory"));
top_width = sizeof("cannot open directory");
top_buffer = "cannot open directory";
pthread_mutex_unlock(&mutex_top);
continue;
}
pthread_mutex_lock(&mutex_mid);
if (mid_dir.current_file != NULL) {
top_buffer = malloc(strlen(global_path)+1 + strlen(mid_dir.current_file->file_name)+1);
memcpy(top_buffer, global_path, strlen(global_path));
memcpy(top_buffer + strlen(global_path) + 1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
top_buffer[strlen(global_path)] = '/';
top_width = strlen(top_buffer);
} else {
top_buffer = malloc(strlen(global_path)+1);
memcpy(top_buffer, global_path, strlen(global_path)+1);
if(global_path == NULL) {
mvwaddstr(win_t, 0, 0, "cannot open directory");
pthread_mutex_unlock(&mutex_top);
pthread_mutex_unlock(&mutex_mid);
continue;
} else if (mid_dir.current_file == NULL) {
mvwaddstr(win_t, 0, 0, "cannot open file");
pthread_mutex_unlock(&mutex_top);
pthread_mutex_unlock(&mutex_mid);
continue;
}
pthread_mutex_unlock(&mutex_mid);
/* rendering */
pthread_mutex_lock(&mutex_render);
werase(win_t);
wattron(win_t, COLOR_PAIR(COLOR_PATH));
mvwaddnstr(win_t, 0, 0, top_buffer, strlen(global_path)+1);
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
mvwaddstr(win_t, 0, strlen(global_path)+1, top_buffer+strlen(global_path)+1);
wnoutrefresh(win_t);
if (strlen(global_path) != 1) {
wattron(win_t, COLOR_PAIR(COLOR_PATH));
mvwaddnstr(win_t, 0, 0, global_path, strlen(global_path)+1);
mvwaddch(win_t, 0, strlen(global_path), '/');
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
mvwaddstr(win_t, 0, strlen(global_path)+1, mid_dir.current_file->file_name);
} else { /* dir '/' */
wattron(win_t, COLOR_PAIR(COLOR_PATH));
mvwaddnstr(win_t, 0, 0, global_path, 1);
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
mvwaddstr(win_t, 0, 1, mid_dir.current_file->file_name);
}
/*wnoutrefresh(win_t);*/
wrefresh(win_t);
pthread_mutex_unlock(&mutex_render);
pthread_mutex_unlock(&mutex_mid);
pthread_mutex_unlock(&mutex_top);
}
pthread_exit(0);
@@ -332,10 +342,19 @@ void *thread_btm(){
unsigned int ui_btm_right_block_size = 0;
unsigned int buffer_width = 0;
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_btm);
pthread_cond_wait(&cond_btm, &mutex_btm);
if (buffer_width != terminal_width) {
buffer_width = (terminal_width > 10) ? terminal_width : 11;
free(btm_buffer);
btm_buffer = malloc(buffer_width+1);
/*in this case STATUS_RUN_BACKEND should be true as defined in the main loop resize check*/
}
if (status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
/*{{{ parse storage info; the fold of shame*/
@@ -408,15 +427,11 @@ void *thread_btm(){
/*}}}*/
}
if (buffer_width != terminal_width) {
buffer_width = terminal_width;
free(btm_buffer);
btm_buffer = malloc(buffer_width+1);
}
memset(btm_buffer, ' ', buffer_width);
btm_buffer[buffer_width] = '\0';
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
if (ui_btm_right_block_size + 9 < buffer_width) {
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
}
if (mid_dir.current_file != NULL) {
btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
@@ -432,15 +447,17 @@ void *thread_btm(){
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
}
btm_buffer[buffer_width] = '\0';
/* rendering */
pthread_mutex_lock(&mutex_render);
werase(win_b);
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
mvwprintw(win_b, 0, 0, "%s", btm_buffer);
}
wnoutrefresh(win_b);
mvwprintw(win_b, 0, 0, "%s", btm_buffer);
/*wnoutrefresh(win_b);*/
wrefresh(win_b);
pthread_mutex_unlock(&mutex_render);
pthread_mutex_unlock(&mutex_btm);
/*the printing of all possible inputs are done in user_interactions */
@@ -453,13 +470,8 @@ void *thread_btm(){
void threading_init(){
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));
rgt_buffer = NULL;
btm_buffer = NULL;
pthread_mutex_init(&mutex_top, NULL);
pthread_mutex_init(&mutex_mid, NULL);
@@ -475,7 +487,6 @@ void threading_init(){
}
void threading_free(){
free(top_buffer);
pthread_mutex_destroy(&mutex_top);
pthread_mutex_destroy(&mutex_mid);