Compare commits
11
Commits
c68b872d1e
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
267518fe3a | ||
|
|
89c3f88a34 | ||
|
|
6d1c9c95ac | ||
|
|
06c00a0924 | ||
|
|
b30229b770 | ||
|
|
f7589dbe2b | ||
|
|
25c912069a | ||
|
|
24fe4a4aa4 | ||
|
|
56d2f9d5d0 | ||
|
|
a55c38abfa | ||
|
|
a5fcd1985e |
@@ -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
|
||||
/* }}} */
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
+50
-48
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,17 +134,15 @@ void *thread_mid(){
|
||||
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);
|
||||
}
|
||||
@@ -289,44 +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);
|
||||
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);
|
||||
@@ -343,8 +348,7 @@ void *thread_btm(){
|
||||
pthread_cond_wait(&cond_btm, &mutex_btm);
|
||||
|
||||
if (buffer_width != terminal_width) {
|
||||
buffer_width = terminal_width;
|
||||
if (terminal_width < 10) { buffer_width = 10; }
|
||||
buffer_width = (terminal_width > 10) ? terminal_width : 11;
|
||||
|
||||
free(btm_buffer);
|
||||
btm_buffer = malloc(buffer_width+1);
|
||||
@@ -466,7 +470,6 @@ void *thread_btm(){
|
||||
|
||||
void threading_init(){
|
||||
|
||||
top_buffer = NULL;
|
||||
rgt_buffer = NULL;
|
||||
btm_buffer = NULL;
|
||||
|
||||
@@ -484,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