Compare commits
15
Commits
e65a2ecdb6
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
267518fe3a | ||
|
|
89c3f88a34 | ||
|
|
6d1c9c95ac | ||
|
|
06c00a0924 | ||
|
|
b30229b770 | ||
|
|
f7589dbe2b | ||
|
|
25c912069a | ||
|
|
24fe4a4aa4 | ||
|
|
56d2f9d5d0 | ||
|
|
a55c38abfa | ||
|
|
a5fcd1985e | ||
|
|
c68b872d1e | ||
|
|
c6ec8c1199 | ||
|
|
230bac4d75 | ||
|
|
e898ec3ba5 |
@@ -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
|
||||
/* }}} */
|
||||
|
||||
+8
-8
@@ -12,6 +12,7 @@ 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;
|
||||
@@ -89,17 +90,16 @@ 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
|
||||
@@ -108,14 +108,14 @@ void ueberzug_init(){
|
||||
ueberzug = popen("ueberzug layer -s --no-cache ", "w");
|
||||
#endif
|
||||
}
|
||||
void ueberzug_close(){
|
||||
images_clear();
|
||||
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);
|
||||
}
|
||||
void ueberzug_close(){
|
||||
images_clear();
|
||||
pclose(ueberzug);
|
||||
}
|
||||
#endif
|
||||
|
||||
+78
-66
@@ -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;
|
||||
@@ -314,8 +330,13 @@ void open_with(){
|
||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||
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->file_name);
|
||||
pid_t pid = fork();
|
||||
@@ -330,6 +351,7 @@ void open_with(){
|
||||
}
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
free(parsed_ui_text);
|
||||
free(str);
|
||||
|
||||
@@ -340,8 +362,12 @@ void rename_hovered(){
|
||||
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, new_file_name) == 0) {
|
||||
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));
|
||||
@@ -387,7 +413,11 @@ void makedir(){
|
||||
wclear(win_b);
|
||||
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, file_name) == 0) {
|
||||
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);
|
||||
@@ -400,7 +430,11 @@ void makefile(){
|
||||
wclear(win_b);
|
||||
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, file_name) == 0) {
|
||||
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);
|
||||
@@ -590,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);
|
||||
@@ -598,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];
|
||||
@@ -635,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);
|
||||
|
||||
@@ -133,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);
|
||||
@@ -151,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() {
|
||||
@@ -188,7 +195,7 @@ void 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);
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user