Compare commits
15 Commits
87bfdd1b86
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 60127a6b9b | |||
| 7091c47a2c | |||
| e6318f8d1e | |||
| f6c39ce039 | |||
| ef4e49e022 | |||
| eafb13d3e2 | |||
| f88b86c1f5 | |||
| d8b3706f64 | |||
| c0299aef8c | |||
| 4def2c7cf0 | |||
| 50f7e7c67d | |||
| 9bdf677a56 | |||
| 5a31f452ea | |||
| daf43daa00 | |||
| cf03a230b6 |
@@ -82,10 +82,15 @@ char* smartstrcasestr(const char *haystack, const char *needle){
|
|||||||
|
|
||||||
|
|
||||||
char* parse_cmd(const char *cmd, file *f){
|
char* parse_cmd(const char *cmd, file *f){
|
||||||
|
char *out;
|
||||||
|
if (f == NULL) {
|
||||||
|
out = malloc(strlen(cmd)+1);
|
||||||
|
memcpy(out, cmd, strlen(cmd)+1);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char *out;
|
|
||||||
char *pos;
|
char *pos;
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
while(f->file_name[i]) {
|
while(f->file_name[i]) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
unsigned int color_count;
|
unsigned int color_count;
|
||||||
color *colors;
|
color *colors;
|
||||||
|
|
||||||
extern unsigned int settings;
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
|
|
||||||
void parse_colors(char *line, short *fg, short *bg){
|
void parse_colors(char *line, short *fg, short *bg){
|
||||||
@@ -31,7 +30,6 @@ void parse_colors(char *line, short *fg, short *bg){
|
|||||||
|
|
||||||
void colors_init() {
|
void colors_init() {
|
||||||
if (has_colors()) {
|
if (has_colors()) {
|
||||||
settings |= SETTINGS_HAS_COLOR;
|
|
||||||
start_color();
|
start_color();
|
||||||
color_count = 0;
|
color_count = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ static const char clipboard_cmd[] = "echo ^ | xsel -ib --trim"; /*used in yank_t
|
|||||||
static const char rename_cmd[] = "mv"; /* as used in rename_hovered, makedir and makefile */
|
static const char rename_cmd[] = "mv"; /* as used in rename_hovered, makedir and makefile */
|
||||||
static const char makefile_cmd[] = "touch"; /*as of now both only do ``rename_cmd new_name``*/
|
static const char makefile_cmd[] = "touch"; /*as of now both only do ``rename_cmd new_name``*/
|
||||||
static const char makedir_cmd[] = "mkdir";
|
static const char makedir_cmd[] = "mkdir";
|
||||||
|
static const char copy_cmd[] = "cp -r";
|
||||||
|
static const char cut_cmd[] = "mv";
|
||||||
|
static const char del_cmd[] = "rm -r";
|
||||||
|
|
||||||
static const mimetype mimetype_default_cmd[] = {
|
static const mimetype mimetype_default_cmd[] = {
|
||||||
/* mimetype shell command
|
/* mimetype shell command
|
||||||
@@ -68,14 +71,14 @@ static const binding key_binding[] = {
|
|||||||
{ "n", move_up, NULL, "move up" },
|
{ "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 */
|
{ "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 */
|
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* execute shell cmd on file, accounts for SETTINGS_COMMAND_FORK */
|
||||||
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||||
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
{ "dD", 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 */
|
* this means that it does not delete the hovered files if files are already selected */
|
||||||
{ "yn", yank_file_name, NULL, "yank filename of hovered file" },
|
{ "yn", yank_file_name, NULL, "yank filename of hovered file" },
|
||||||
{ "yp", yank_file_path, NULL, "yank path of hovered file" },
|
{ "yp", yank_file_path, NULL, "yank path of hovered file" },
|
||||||
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
{ "yy", copy_file, COPY_FILE, "copy/yank file/directory" },
|
||||||
{ "dd", yank_file, "cut", "cut file/directory" },
|
{ "dd", copy_file, CUT_FILE, "cut file/directory" },
|
||||||
{ "pp", paste, NULL, "paste" },
|
{ "pp", paste, NULL, "paste" },
|
||||||
|
|
||||||
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
||||||
@@ -150,5 +153,9 @@ static const char ui_makedir_text[];
|
|||||||
static const char ui_makefile_text[];
|
static const char ui_makefile_text[];
|
||||||
static const char ui_rename_text[];
|
static const char ui_rename_text[];
|
||||||
static const char ui_delete_text[];
|
static const char ui_delete_text[];
|
||||||
|
static const char copy_cmd[];
|
||||||
|
static const char cut_cmd[];
|
||||||
|
static const char del_cmd[];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
#define STATUS_QUIT_PROGRAM 1
|
#define STATUS_QUIT_PROGRAM 1
|
||||||
#define STATUS_RUN_BACKEND 2
|
#define STATUS_RUN_BACKEND 2
|
||||||
#define STATUS_RELOAD_DIRECTORY 4
|
#define STATUS_RELOAD_DIRECTORY 4
|
||||||
#define STATUS_UPDATE_ASYNC_REFRESH 8
|
#define STATUS_UPDATE_SCREEN_RESIZE 8
|
||||||
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
#define STATUS_UPDATE_SCREEN_CLEAR 16
|
||||||
#define STATUS_UPDATE_SCREEN_CLEAR 32
|
|
||||||
#define STATUS_UPDATE_SCREEN_MASK (STATUS_UPDATE_ASYNC_REFRESH | STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)
|
|
||||||
#define STATUS_USER_ROOT 128
|
#define STATUS_USER_ROOT 128
|
||||||
#define STATUS_INPUT_MATCH 256
|
#define STATUS_INPUT_MATCH 256
|
||||||
#define STATUS_DELTA_TIME 512
|
#define STATUS_DELTA_TIME 512
|
||||||
@@ -59,9 +57,8 @@
|
|||||||
#define FILE_TYPE_SYMLINK 64
|
#define FILE_TYPE_SYMLINK 64
|
||||||
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
|
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
|
||||||
|
|
||||||
#define YANK_IS_USED 1
|
#define COPY_FILE (int*)0x0001
|
||||||
#define YANK_CUT 2
|
#define CUT_FILE (int*)0x0002
|
||||||
#define YANK_COPY 4
|
|
||||||
|
|
||||||
#define BTM_WINDOW_HEIGHT_ON_STR_INTERACTION 5
|
#define BTM_WINDOW_HEIGHT_ON_STR_INTERACTION 5
|
||||||
#define INPUT_BUFFER_SIZE 255
|
#define INPUT_BUFFER_SIZE 255
|
||||||
@@ -101,8 +98,7 @@ typedef struct Binding {
|
|||||||
char* comment;
|
char* comment;
|
||||||
} binding;
|
} binding;
|
||||||
typedef struct Yank {
|
typedef struct Yank {
|
||||||
char status;
|
int *status; /*pointer to make blackmagic easier, should probably not deref lol*/
|
||||||
char *path;
|
|
||||||
char **list;
|
char **list;
|
||||||
unsigned long count;
|
unsigned long count;
|
||||||
} yank;
|
} yank;
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ unsigned long get_dir_size(char *path){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void get_dir_content(char *path, dir *dir){
|
void get_dir_content(char *path, dir *dir){
|
||||||
|
|
||||||
struct dirent **entry = NULL;
|
struct dirent **entry = NULL;
|
||||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
||||||
scandir(path, &entry, skip_dot, NULL);
|
scandir(path, &entry, skip_dot, NULL);
|
||||||
@@ -169,16 +170,16 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
|||||||
|
|
||||||
long offset_index = 2; /* only used for the index of the file itself */
|
long offset_index = 2; /* only used for the index of the file itself */
|
||||||
if (print_info) {
|
if (print_info) {
|
||||||
if (dir->file_count > 9) {
|
|
||||||
|
|
||||||
#if SETTINGS_LINE_NUMBERS != 0
|
#if SETTINGS_LINE_NUMBERS != 0
|
||||||
|
if (dir->file_count > 9) {
|
||||||
unsigned long dir_file_count_ = dir->file_count;
|
unsigned long dir_file_count_ = dir->file_count;
|
||||||
while(dir_file_count_ > 9) {
|
while(dir_file_count_ > 9) {
|
||||||
offset_front++;
|
offset_front++;
|
||||||
dir_file_count_ /= 10;
|
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)*2 && dir->file_count > terminal_height - 2) {
|
||||||
if (selected_file_current + (terminal_height/3) >= dir->file_count) {
|
if (selected_file_current + (terminal_height/3) >= dir->file_count) {
|
||||||
offset_vertical = dir->file_count - terminal_height+2;
|
offset_vertical = dir->file_count - terminal_height+2;
|
||||||
@@ -191,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++) {
|
for (i = offset_vertical; i < dir->file_count && i < (terminal_height + offset_vertical); i++) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (print_info) {
|
if (print_info) {
|
||||||
file_size = dir->file_list[i].file_size;
|
file_size = dir->file_list[i].file_size;
|
||||||
char size_index = -1;
|
char size_index = -1;
|
||||||
@@ -206,7 +205,7 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
|||||||
|
|
||||||
if (dir->file_list[i].file_type & FILE_TYPE_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);
|
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);
|
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
||||||
} else {
|
} else {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
|
||||||
@@ -216,14 +215,11 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
|
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
wattron(win, COLOR_PAIR(8)); /* FIFO, as seen in colors.c */
|
||||||
is_selected = 1;
|
is_selected = 1;
|
||||||
} else {
|
|
||||||
is_selected = 0;
|
|
||||||
}
|
|
||||||
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
wattron(win, COLOR_PAIR(8));
|
|
||||||
} else {
|
} else {
|
||||||
wattron(win, COLOR_PAIR(dir->file_list[i].color_pair));
|
wattron(win, COLOR_PAIR(dir->file_list[i].color_pair));
|
||||||
|
is_selected = 0;
|
||||||
}
|
}
|
||||||
if (&dir->file_list[i] == dir->current_file) {
|
if (&dir->file_list[i] == dir->current_file) {
|
||||||
wattron(win, A_REVERSE);
|
wattron(win, A_REVERSE);
|
||||||
@@ -231,13 +227,8 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
|||||||
for (bg = 0; bg < line_width; bg++) {
|
for (bg = 0; bg < line_width; bg++) {
|
||||||
mvwaddch(win, i-offset_vertical, bg, ' ');
|
mvwaddch(win, i-offset_vertical, bg, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
wattroff(win, A_REVERSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(print_info) {
|
if(print_info) {
|
||||||
#if SETTINGS_LINE_NUMBERS == 2
|
#if SETTINGS_LINE_NUMBERS == 2
|
||||||
long i_ = (selected_file_current) - i;
|
long i_ = (selected_file_current) - i;
|
||||||
@@ -272,7 +263,7 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
|||||||
|
|
||||||
if (dir->file_list[i].file_type & FILE_TYPE_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);
|
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);
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
||||||
} else {
|
} else {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char);
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char);
|
||||||
@@ -289,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) {
|
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
|
||||||
wattroff(win, COLOR_PAIR(8));
|
wattroff(win, COLOR_PAIR(8));
|
||||||
} else {
|
} else {
|
||||||
wattroff(win, COLOR_PAIR(dir->file_list[i].color_pair));
|
wattroff(win, COLOR_PAIR(dir->file_list[i].color_pair));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,7 +319,7 @@ void dir_changed(){
|
|||||||
}
|
}
|
||||||
void change_dir(char *new_path){
|
void change_dir(char *new_path){
|
||||||
|
|
||||||
char *old_path = getcwd(NULL, 0);
|
const char *old_path = global_path;
|
||||||
current_linked_dir = list_beginning;
|
current_linked_dir = list_beginning;
|
||||||
while (current_linked_dir->next != NULL) {
|
while (current_linked_dir->next != NULL) {
|
||||||
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||||
@@ -338,7 +332,12 @@ void change_dir(char *new_path){
|
|||||||
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
chdir(new_path);
|
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;
|
||||||
|
}
|
||||||
char *new_path_real = getcwd(NULL, 0);
|
char *new_path_real = getcwd(NULL, 0);
|
||||||
|
|
||||||
current_linked_dir = list_beginning;
|
current_linked_dir = list_beginning;
|
||||||
@@ -361,7 +360,6 @@ void change_dir(char *new_path){
|
|||||||
}
|
}
|
||||||
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||||
|
|
||||||
free(old_path);
|
|
||||||
free(new_path_real);
|
free(new_path_real);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -374,37 +372,3 @@ void dir_init(){
|
|||||||
current_linked_dir = list_beginning;
|
current_linked_dir = list_beginning;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void recursive_delete(file current_file){
|
|
||||||
/*
|
|
||||||
if (S_ISLNK(current_file.permissions)) {
|
|
||||||
remove(current_file.file_name);
|
|
||||||
} else if (current_file.file_type & FILE_TYPE_DIR ) {
|
|
||||||
unsigned int file_modifiers_tmp = file_modifiers;
|
|
||||||
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
|
|
||||||
unsigned long current_file_count = get_dir_size(current_file.file_name);
|
|
||||||
if (current_file_count != 0) {
|
|
||||||
file *current_dir = malloc(current_file_count * sizeof(file));
|
|
||||||
memset(current_dir, '\0', current_file_count * sizeof(file));
|
|
||||||
get_dir_content(current_file.file_name, ¤t_file_count, current_dir);
|
|
||||||
if (chdir(current_file.file_name) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
unsigned long i;
|
|
||||||
for (i = 0; i < current_file_count; i++) {
|
|
||||||
recursive_delete(current_dir[i]);
|
|
||||||
free(current_dir[i].file_name);
|
|
||||||
}
|
|
||||||
free(current_dir);
|
|
||||||
if (chdir("..") != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
remove(current_file.file_name);
|
|
||||||
file_modifiers = file_modifiers_tmp;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
remove(current_file.file_name);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,4 +10,3 @@ char update_selected_file();
|
|||||||
void dir_set_selected_file_current(unsigned long selected_file_current);
|
void dir_set_selected_file_current(unsigned long selected_file_current);
|
||||||
unsigned long dir_get_selected_file_current();
|
unsigned long dir_get_selected_file_current();
|
||||||
void dir_init();
|
void dir_init();
|
||||||
void recursive_delete(file current_file);
|
|
||||||
|
|||||||
+274
-43
@@ -1,7 +1,6 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -22,14 +21,12 @@ extern unsigned int terminal_height;
|
|||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
extern char *start_path;
|
|
||||||
extern char *global_path;
|
extern char *global_path;
|
||||||
extern char *input;
|
extern char *input;
|
||||||
|
|
||||||
extern time_t seed;
|
extern time_t seed;
|
||||||
|
|
||||||
char search_buffer[INPUT_BUFFER_SIZE];
|
char search_buffer[INPUT_BUFFER_SIZE];
|
||||||
unsigned int input_pass;
|
|
||||||
unsigned long parsed_input_number;
|
unsigned long parsed_input_number;
|
||||||
yank yank_files = { 0 };
|
yank yank_files = { 0 };
|
||||||
|
|
||||||
@@ -41,15 +38,18 @@ yank yank_files = { 0 };
|
|||||||
printf("TODO: %s at %d in %s \n", __func__, __LINE__, __FILE__);\
|
printf("TODO: %s at %d in %s \n", __func__, __LINE__, __FILE__);\
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
void FAIL(char *function, char *str){
|
#define skip_if_empty_dir \
|
||||||
printf("ERROR in function %s: %s", function, str);
|
if (mid_dir.current_file == NULL) { \
|
||||||
}
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
void user_interactions() {
|
void user_interactions() {
|
||||||
|
|
||||||
|
|
||||||
char ch;
|
char ch;
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
unsigned long binding_matches = 0;
|
unsigned long binding_matches = 0;
|
||||||
|
static unsigned int input_pass;
|
||||||
|
|
||||||
|
|
||||||
ch = getch();
|
ch = getch();
|
||||||
@@ -79,6 +79,9 @@ void user_interactions() {
|
|||||||
|
|
||||||
char cmp_len = strlen(input);
|
char cmp_len = strlen(input);
|
||||||
if(strlen(input) < 1) {
|
if(strlen(input) < 1) {
|
||||||
|
/* strlen is 0 every iteration nothing is pressed
|
||||||
|
* should this be input in the strncmp, it always succeeds.
|
||||||
|
* this results in all possible bindings being printed at all times */
|
||||||
cmp_len = 1;
|
cmp_len = 1;
|
||||||
}
|
}
|
||||||
for (i = 0; i < binding_count; i++) {
|
for (i = 0; i < binding_count; i++) {
|
||||||
@@ -121,10 +124,11 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
|||||||
|
|
||||||
wmove(win, y, x);
|
wmove(win, y, x);
|
||||||
while(1) {
|
while(1) {
|
||||||
/*ch = mvwgetch(win, y, x + pass);*/
|
|
||||||
ch = wgetch(win);
|
ch = wgetch(win);
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
err = 0;
|
break;
|
||||||
|
} else if (ch == 27) { /* esc key */
|
||||||
|
err = 1;
|
||||||
break;
|
break;
|
||||||
} else if (ch == '\t') { /* tab */
|
} else if (ch == '\t') { /* tab */
|
||||||
memcpy(str + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
memcpy(str + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
||||||
@@ -135,9 +139,6 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
|||||||
pass--;
|
pass--;
|
||||||
mvwdelch(win, y, x + pass);
|
mvwdelch(win, y, x + pass);
|
||||||
}
|
}
|
||||||
} else if (ch == 27) { /* esc key */
|
|
||||||
err = 1;
|
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
mvwaddch(win, y, x + pass, ch);
|
mvwaddch(win, y, x + pass, ch);
|
||||||
str[pass] = ch;
|
str[pass] = ch;
|
||||||
@@ -154,7 +155,7 @@ void quit_program(){
|
|||||||
status = STATUS_QUIT_PROGRAM;
|
status = STATUS_QUIT_PROGRAM;
|
||||||
}
|
}
|
||||||
void update(){
|
void update(){
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_RELOAD_DIRECTORY );
|
||||||
}
|
}
|
||||||
void select_all(){
|
void select_all(){
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
@@ -165,6 +166,8 @@ void select_all(){
|
|||||||
}
|
}
|
||||||
void move_down(unsigned long passes){
|
void move_down(unsigned long passes){
|
||||||
|
|
||||||
|
skip_if_empty_dir;
|
||||||
|
|
||||||
mid_dir.current_file += passes;
|
mid_dir.current_file += passes;
|
||||||
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
|
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
|
||||||
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||||
@@ -174,6 +177,8 @@ void move_down(unsigned long passes){
|
|||||||
}
|
}
|
||||||
void move_up(unsigned long passes){
|
void move_up(unsigned long passes){
|
||||||
|
|
||||||
|
skip_if_empty_dir;
|
||||||
|
|
||||||
mid_dir.current_file -= passes;
|
mid_dir.current_file -= passes;
|
||||||
if (mid_dir.current_file < mid_dir.file_list) {
|
if (mid_dir.current_file < mid_dir.file_list) {
|
||||||
mid_dir.current_file = mid_dir.file_list;
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
@@ -186,11 +191,13 @@ void move_left(unsigned long passes){
|
|||||||
for (i = 0; i < passes; i++) {
|
for (i = 0; i < passes; i++) {
|
||||||
change_dir("..");
|
change_dir("..");
|
||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void move_right(){
|
void move_right(){
|
||||||
|
|
||||||
|
skip_if_empty_dir
|
||||||
|
|
||||||
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||||
change_dir(mid_dir.current_file->file_name);
|
change_dir(mid_dir.current_file->file_name);
|
||||||
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
||||||
@@ -257,8 +264,8 @@ void move_right(){
|
|||||||
free(cmd);
|
free(cmd);
|
||||||
free(mime);
|
free(mime);
|
||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void toggle_hidden_files(){
|
void toggle_hidden_files(){
|
||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
@@ -270,6 +277,7 @@ void toggle_selection(unsigned long passes){
|
|||||||
mid_dir.current_file->status ^= FILE_STATUS_SELECTED;
|
mid_dir.current_file->status ^= FILE_STATUS_SELECTED;
|
||||||
move_down(1);
|
move_down(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void jump_bottom(){
|
void jump_bottom(){
|
||||||
@@ -281,7 +289,32 @@ void jump_top(){
|
|||||||
status |= (STATUS_RUN_BACKEND);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void open_with(){
|
void open_with(){
|
||||||
TODO;
|
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);
|
||||||
|
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||||
|
|
||||||
|
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) {
|
||||||
|
if (str[0] == SETTINGS_COMMAND_FORK) {
|
||||||
|
cmd = parse_cmd(str+1, mid_dir.current_file);
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid == 0 && setsid()) {
|
||||||
|
system(cmd);
|
||||||
|
status = STATUS_QUIT_PROGRAM;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd = parse_cmd(str, mid_dir.current_file);
|
||||||
|
if (system(cmd)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(cmd);
|
||||||
|
}
|
||||||
|
free(parsed_ui_text);
|
||||||
|
free(str);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||||
}
|
}
|
||||||
void rename_hovered(){
|
void rename_hovered(){
|
||||||
wclear(win_b);
|
wclear(win_b);
|
||||||
@@ -289,6 +322,7 @@ void rename_hovered(){
|
|||||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
|
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
|
||||||
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||||
|
|
||||||
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, tmp.file_name) == 0) {
|
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 *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file);
|
||||||
char *cmd1 = parse_cmd(cmd0, &tmp);
|
char *cmd1 = parse_cmd(cmd0, &tmp);
|
||||||
@@ -298,11 +332,36 @@ void rename_hovered(){
|
|||||||
}
|
}
|
||||||
free(parsed_ui_text);
|
free(parsed_ui_text);
|
||||||
free(tmp.file_name);
|
free(tmp.file_name);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void delete(){
|
void delete(unsigned long passes){
|
||||||
TODO;
|
|
||||||
|
unsigned long i;
|
||||||
|
unsigned long del_count = 0;
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
|
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);
|
||||||
|
free(cmd);
|
||||||
|
del_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (del_count == 0) {
|
||||||
|
for (i = 0; i < passes; i++) {
|
||||||
|
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);
|
||||||
|
free(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void makedir(){
|
void makedir(){
|
||||||
wclear(win_b);
|
wclear(win_b);
|
||||||
@@ -315,6 +374,7 @@ void makedir(){
|
|||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
free(tmp.file_name);
|
free(tmp.file_name);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void makefile(){
|
void makefile(){
|
||||||
@@ -328,6 +388,7 @@ void makefile(){
|
|||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
free(tmp.file_name);
|
free(tmp.file_name);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void enter_shell(unsigned long passes, int index){
|
void enter_shell(unsigned long passes, int index){
|
||||||
@@ -343,34 +404,58 @@ void enter_shell(unsigned long passes, int index){
|
|||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
|
|
||||||
}
|
|
||||||
void not_implemented(unsigned long passes, int index){
|
|
||||||
(void)passes;
|
|
||||||
|
|
||||||
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");
|
|
||||||
TODO;
|
|
||||||
}
|
}
|
||||||
void jump_to_dir(unsigned long passes, int index){
|
void jump_to_dir(unsigned long passes, int index){
|
||||||
TODO;
|
(void)passes;
|
||||||
|
|
||||||
|
unsigned long len;
|
||||||
|
char *c = strchr(key_binding[index].black_magic, '/');
|
||||||
|
if (c) {
|
||||||
|
len = c - (char*)key_binding[index].black_magic;
|
||||||
|
} else {
|
||||||
|
len = strlen(key_binding[index].black_magic);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *to_env = malloc(len + 1);
|
||||||
|
memcpy(to_env, key_binding[index].black_magic, len);
|
||||||
|
to_env[len] = '\0';
|
||||||
|
char *env = getenv(to_env + 1); /*+1 to remove the '$' prefix, freeing env always segfaults*/
|
||||||
|
|
||||||
|
if (env) {
|
||||||
|
char *path = malloc(strlen(key_binding[index].black_magic) + strlen(env) + 1);
|
||||||
|
memcpy(path, env, strlen(env));
|
||||||
|
memcpy(path + strlen(env), key_binding[index].black_magic + len, strlen(key_binding[index].black_magic)+1);
|
||||||
|
change_dir(path);
|
||||||
|
free(path);
|
||||||
|
} else {
|
||||||
|
change_dir(key_binding[index].black_magic);
|
||||||
|
}
|
||||||
|
free(to_env);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_RELOAD_DIRECTORY );
|
||||||
}
|
}
|
||||||
void order_by(unsigned long passes, int index){
|
void order_by(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
|
|
||||||
seed = time(NULL);
|
seed = time(NULL);
|
||||||
|
|
||||||
order_func = key_binding[index].black_magic;
|
order_func = key_binding[index].black_magic;
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void cmd_on_selected(unsigned long passes, int index){
|
void cmd_on_selected(unsigned long passes, int index){
|
||||||
TODO;
|
(void)passes;
|
||||||
|
|
||||||
|
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||||
}
|
}
|
||||||
void yank_file_name(){
|
void yank_file_name(){
|
||||||
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);
|
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void yank_file_path(){
|
void yank_file_path(){
|
||||||
@@ -384,15 +469,111 @@ void yank_file_path(){
|
|||||||
free(cmd);
|
free(cmd);
|
||||||
free(tmp->file_name);
|
free(tmp->file_name);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
|
}
|
||||||
|
void copy_file(unsigned long passes, int index){
|
||||||
|
(void)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++) {
|
||||||
|
free(yank_files.list[i]);
|
||||||
|
}
|
||||||
|
free(yank_files.list);
|
||||||
|
yank_files.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < mid_dir.file_count; i++) {
|
||||||
|
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
yank_files.count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (yank_files.count != 0) {
|
||||||
|
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
||||||
|
|
||||||
|
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)] = '/';
|
||||||
|
|
||||||
|
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*/
|
||||||
|
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)] = '/';
|
||||||
|
|
||||||
|
*yank_files.list = str;
|
||||||
|
yank_files.count = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*free(path);*/
|
||||||
|
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void yank_file(unsigned long passes, int index){
|
void paste(unsigned long passes){
|
||||||
TODO;
|
|
||||||
}
|
unsigned long i;
|
||||||
void paste(){
|
unsigned long j;
|
||||||
TODO;
|
file tmp;
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
|
for (j = 0; j < passes; j++) {
|
||||||
|
for (i = 0; i < yank_files.count; i++) {
|
||||||
|
|
||||||
|
char *file_name = strrchr(yank_files.list[i], '/')+1;
|
||||||
|
char *dest_file_name = malloc(strlen(file_name)+1);
|
||||||
|
memcpy(dest_file_name, file_name, strlen(file_name)+1);
|
||||||
|
|
||||||
|
|
||||||
|
tmp.file_name = yank_files.list[i];
|
||||||
|
while(access(dest_file_name, F_OK) == 0) {
|
||||||
|
unsigned long len = strlen(dest_file_name);
|
||||||
|
dest_file_name = realloc(dest_file_name, len+2);
|
||||||
|
|
||||||
|
dest_file_name[len] = '_';
|
||||||
|
dest_file_name[len+1] = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (yank_files.status == COPY_FILE) {
|
||||||
|
cmd = parse_cmd(copy_cmd, &tmp);
|
||||||
|
} else if (yank_files.status == CUT_FILE) {
|
||||||
|
cmd = parse_cmd(cut_cmd, &tmp);
|
||||||
|
} else {
|
||||||
|
free(dest_file_name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tmp.file_name = dest_file_name;
|
||||||
|
cmd = parse_cmd(cmd, &tmp);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
free(tmp.file_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void search(){
|
void search(){
|
||||||
echo();
|
echo();
|
||||||
@@ -410,13 +591,14 @@ void search(){
|
|||||||
|
|
||||||
unsigned int pass = 0;
|
unsigned int pass = 0;
|
||||||
char ch;
|
char ch;
|
||||||
char err = 0;
|
|
||||||
|
|
||||||
wmove(win_b, 0, 1);
|
wmove(win_b, 0, 1);
|
||||||
while(1) {
|
while(1) {
|
||||||
ch = wgetch(win_b);
|
ch = wgetch(win_b);
|
||||||
if (ch == '\n') {
|
if (ch == '\n' || ch == 27 /* esc key */) {
|
||||||
err = 0;
|
/* unlike the other uses of a read string reimplementation,
|
||||||
|
* here we do not differentiate between accepting and cancle.
|
||||||
|
* this is intentional */
|
||||||
break;
|
break;
|
||||||
} else if (ch == '\t') { /* tab */
|
} else if (ch == '\t') { /* tab */
|
||||||
memcpy(search_buffer + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
memcpy(search_buffer + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
||||||
@@ -427,9 +609,6 @@ void search(){
|
|||||||
pass--;
|
pass--;
|
||||||
mvwdelch(win_b, 0, pass+1);
|
mvwdelch(win_b, 0, pass+1);
|
||||||
}
|
}
|
||||||
} else if (ch == 27) { /* esc key */
|
|
||||||
err = 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (ch) {
|
if (ch) {
|
||||||
mvwaddch(win_b, 0, pass+1, ch);
|
mvwaddch(win_b, 0, pass+1, ch);
|
||||||
@@ -437,7 +616,6 @@ void search(){
|
|||||||
pass++;
|
pass++;
|
||||||
|
|
||||||
unsigned long index = (mid_dir.current_file - mid_dir.file_list);
|
unsigned long index = (mid_dir.current_file - mid_dir.file_list);
|
||||||
unsigned long x = getmaxx(win_b);
|
|
||||||
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
|
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)) {
|
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||||
mid_dir.current_file = &mid_dir.file_list[index];
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
@@ -485,5 +663,58 @@ void search_previous(){
|
|||||||
status |= (STATUS_RUN_BACKEND);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void jmp_file_index(){
|
void jmp_file_index(){
|
||||||
TODO;
|
|
||||||
|
|
||||||
|
char ch;
|
||||||
|
char err = 0;
|
||||||
|
char number_buffer[INPUT_BUFFER_SIZE];
|
||||||
|
char *num = number_buffer;
|
||||||
|
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < terminal_width -1; i++) {
|
||||||
|
mvwaddch(win_b, 0, i, ' ');
|
||||||
|
}
|
||||||
|
mvwaddch(win_b, 0, 0, ':');
|
||||||
|
memset(search_buffer, 0, INPUT_BUFFER_SIZE);
|
||||||
|
|
||||||
|
curs_set(1);
|
||||||
|
echo();
|
||||||
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
|
|
||||||
|
|
||||||
|
wmove(win_b, 0, 1);
|
||||||
|
while(1) {
|
||||||
|
ch = wgetch(win_b);
|
||||||
|
|
||||||
|
if (ch >= '0' && ch <= '9') {
|
||||||
|
*num = ch;
|
||||||
|
num++;
|
||||||
|
} else if (ch == '\n') {
|
||||||
|
break;
|
||||||
|
} else if (ch == 27) { /* esc key */
|
||||||
|
err = 1;
|
||||||
|
break;
|
||||||
|
} else if (ch == 127) { /* backspace */
|
||||||
|
num--;
|
||||||
|
if (num < number_buffer) {
|
||||||
|
num = number_buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*num = 0;
|
||||||
|
num = number_buffer;
|
||||||
|
|
||||||
|
if (err == 0) {
|
||||||
|
unsigned long parsed_number = 0;
|
||||||
|
while(*num) {
|
||||||
|
parsed_number = (parsed_number * 10) + (*num - '0');
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[parsed_number];
|
||||||
|
}
|
||||||
|
|
||||||
|
noecho();
|
||||||
|
curs_set(0);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ void order_by(unsigned long passes, int index);
|
|||||||
void cmd_on_selected(unsigned long passes, int index);
|
void cmd_on_selected(unsigned long passes, int index);
|
||||||
void yank_file_name();
|
void yank_file_name();
|
||||||
void yank_file_path();
|
void yank_file_path();
|
||||||
void yank_file(unsigned long passes, int index);
|
void copy_file();
|
||||||
void paste();
|
void paste();
|
||||||
void search();
|
void search();
|
||||||
void search_next();
|
void search_next();
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "window.c"
|
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
#include "interactions.h"
|
#include "interactions.h"
|
||||||
|
|
||||||
@@ -18,9 +17,8 @@ unsigned int terminal_height;
|
|||||||
unsigned int terminal_width;
|
unsigned int terminal_width;
|
||||||
unsigned int temp_heigth = 0; /*used for screen refresh*/
|
unsigned int temp_heigth = 0; /*used for screen refresh*/
|
||||||
unsigned int temp_width = 0;
|
unsigned int temp_width = 0;
|
||||||
unsigned int settings;
|
|
||||||
unsigned int file_modifiers = 0;
|
unsigned int file_modifiers = 0;
|
||||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY) & ~STATUS_UPDATE_SCREEN_RESIZE;
|
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_UPDATE_SCREEN_RESIZE | STATUS_RELOAD_DIRECTORY) & ~STATUS_UPDATE_SCREEN_RESIZE;
|
||||||
char *global_path;
|
char *global_path;
|
||||||
time_t seed;
|
time_t seed;
|
||||||
|
|
||||||
@@ -149,9 +147,8 @@ void render_pass(){
|
|||||||
mvwin(win_b, terminal_height-1, 0);
|
mvwin(win_b, terminal_height-1, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (pthread_mutex_lock(&mutex_render) == 0 || status & STATUS_UPDATE_SCREEN_MASK) {
|
if (pthread_mutex_lock(&mutex_render) == 0) {
|
||||||
doupdate();
|
doupdate();
|
||||||
status &= ~STATUS_UPDATE_SCREEN_MASK;
|
|
||||||
pthread_mutex_unlock(&mutex_render);
|
pthread_mutex_unlock(&mutex_render);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-2
@@ -85,6 +85,7 @@ void *thread_mid(){
|
|||||||
|
|
||||||
} else { /* the hovered dir is empty */
|
} else { /* the hovered dir is empty */
|
||||||
mid_dir.current_file = NULL;
|
mid_dir.current_file = NULL;
|
||||||
|
mid_dir.file_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
@@ -95,12 +96,14 @@ void *thread_mid(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mid_dir.current_file != NULL) {
|
||||||
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
|
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
|
||||||
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||||
}
|
}
|
||||||
if (mid_dir.current_file < mid_dir.file_list) {
|
if (mid_dir.current_file < mid_dir.file_list) {
|
||||||
mid_dir.current_file = mid_dir.file_list;
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
@@ -204,6 +207,7 @@ void *thread_rgt(){
|
|||||||
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
|
|
||||||
|
if (mid_dir.current_file != NULL) {
|
||||||
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
|
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
|
||||||
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
|
||||||
@@ -212,12 +216,17 @@ void *thread_rgt(){
|
|||||||
rgt_dir.file_list->file_name = file_name;
|
rgt_dir.file_list->file_name = file_name;
|
||||||
rgt_dir.current_file = rgt_dir.file_list;
|
rgt_dir.current_file = rgt_dir.file_list;
|
||||||
rgt_dir.file_count = 1;
|
rgt_dir.file_count = 1;
|
||||||
|
} else {
|
||||||
|
rgt_dir.current_file = NULL;
|
||||||
|
rgt_dir.file_list = NULL;
|
||||||
|
rgt_dir.file_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (rgt_dir.current_file->permissions & S_IRUSR) {
|
if (rgt_dir.current_file != NULL && rgt_dir.current_file->permissions & S_IRUSR) {
|
||||||
if (rgt_dir.current_file->file_type & FILE_TYPE_DIR) {
|
if (rgt_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
@@ -288,13 +297,18 @@ void *thread_top(){
|
|||||||
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
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);
|
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, 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);
|
memcpy(top_buffer + strlen(global_path) + 1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
|
||||||
top_buffer[strlen(global_path)] = '/';
|
top_buffer[strlen(global_path)] = '/';
|
||||||
top_width = strlen(top_buffer);
|
top_width = strlen(top_buffer);
|
||||||
|
} else {
|
||||||
|
top_buffer = malloc(strlen(global_path)+1);
|
||||||
|
memcpy(top_buffer, global_path, strlen(global_path)+1);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
|
|
||||||
/* rendering */
|
/* rendering */
|
||||||
@@ -404,6 +418,7 @@ void *thread_btm(){
|
|||||||
|
|
||||||
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
|
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':
|
btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
|
||||||
(S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
|
(S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
|
||||||
btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
|
btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
|
||||||
@@ -415,6 +430,7 @@ void *thread_btm(){
|
|||||||
btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
|
btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
|
||||||
btm_buffer[8] = (mid_dir.current_file->permissions & S_IWOTH) ? 'w' : '-';
|
btm_buffer[8] = (mid_dir.current_file->permissions & S_IWOTH) ? 'w' : '-';
|
||||||
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
|
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
#include <curses.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "defines.h"
|
|
||||||
#include "dir.h"
|
|
||||||
|
|
||||||
extern unsigned int terminal_height;
|
|
||||||
extern unsigned int terminal_width;
|
|
||||||
extern unsigned int status;
|
|
||||||
extern char *input;
|
|
||||||
|
|
||||||
extern unsigned int timeout_time;
|
|
||||||
extern unsigned int color_count;
|
|
||||||
extern color *colors;
|
|
||||||
|
|
||||||
extern dir rgt_dir;
|
|
||||||
extern dir mid_dir;
|
|
||||||
extern dir lft_dir;
|
|
||||||
extern char *top_buffer;
|
|
||||||
extern char *rgt_buffer;
|
|
||||||
extern char *btm_buffer;
|
|
||||||
|
|
||||||
|
|
||||||
extern unsigned long top_width;
|
|
||||||
|
|
||||||
extern pthread_mutex_t mutex_top;
|
|
||||||
extern pthread_mutex_t mutex_btm;
|
|
||||||
extern pthread_mutex_t mutex_lft;
|
|
||||||
extern pthread_mutex_t mutex_mid;
|
|
||||||
extern pthread_mutex_t mutex_rgt;
|
|
||||||
|
|
||||||
void window_top(WINDOW *win){
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_top) == 0) {
|
|
||||||
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
|
||||||
wattron(win, COLOR_PAIR(COLOR_PATH));
|
|
||||||
mvwaddstr(win, 0, 0, top_buffer);
|
|
||||||
mvwaddch(win, 0, strlen(top_buffer), '/');
|
|
||||||
wattroff(win, COLOR_PAIR(COLOR_PATH));
|
|
||||||
if (mid_dir.file_count != 0) {
|
|
||||||
mvwaddstr(win, 0, strlen(top_buffer)+1, mid_dir.current_file->file_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&mutex_top);
|
|
||||||
} else {
|
|
||||||
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
|
||||||
/*
|
|
||||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void window_btm(WINDOW *win){
|
|
||||||
|
|
||||||
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);
|
|
||||||
/*the printing of the input char is done in user_interactions*/
|
|
||||||
/*the printing of all possible inputs are done in user_interactions */
|
|
||||||
} else {
|
|
||||||
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
|
||||||
/*
|
|
||||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void window_lft(WINDOW *win){
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_lft) == 0) {
|
|
||||||
print_dir(win, 0, &lft_dir);
|
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
mvwaddstr(win, terminal_height/2, terminal_width/8, "LOADING");
|
|
||||||
/*
|
|
||||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void window_mid(WINDOW *win){
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_mid) == 0) {
|
|
||||||
if (mid_dir.file_count == 0) {
|
|
||||||
mvwaddstr(win, 0, 0, "empty");
|
|
||||||
} else {
|
|
||||||
print_dir(win, 1, &mid_dir);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
|
||||||
} else {
|
|
||||||
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
|
|
||||||
/*
|
|
||||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void window_rgt(WINDOW *win){
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
|
|
||||||
if (!rgt_dir.current_file) {
|
|
||||||
mvwaddstr(win, 0, 0, "not accessible");
|
|
||||||
}else if (rgt_dir.current_file->file_type == FILE_TYPE_OPEN_FILE) {
|
|
||||||
mvwaddnstr(win, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
|
||||||
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
|
|
||||||
mvwaddstr(win, 0, 0, "not accessible");
|
|
||||||
} else {
|
|
||||||
print_dir(win, 0, &rgt_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
|
||||||
} else {
|
|
||||||
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
|
|
||||||
/*
|
|
||||||
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user