mirror of
https://gittea.dev/nova/th.git
synced 2026-01-30 16:50:10 -05:00
Compare commits
6 Commits
df726e2f32
...
4229ebe1d5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4229ebe1d5 | ||
|
|
3da05ce27f | ||
|
|
d5a816ae38 | ||
|
|
cbd479ff4f | ||
|
|
7450280c43 | ||
|
|
326d3f7e52 |
@@ -9,7 +9,7 @@ char* concat(const char *s1, const char *s2){
|
|||||||
memcpy(result + len1, s2, len2 + 1);
|
memcpy(result + len1, s2, len2 + 1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
char* smartstrcasestr(char *haystack, const char *needle){
|
char* smartstrcasestr(const char *haystack, const char *needle){
|
||||||
char smart = 0;
|
char smart = 0;
|
||||||
char *ret;
|
char *ret;
|
||||||
char passes = 0;
|
char passes = 0;
|
||||||
@@ -24,7 +24,7 @@ char* smartstrcasestr(char *haystack, const char *needle){
|
|||||||
needle -= passes;
|
needle -= passes;
|
||||||
if (smart == 0) {
|
if (smart == 0) {
|
||||||
char *needle_case = malloc(strlen(needle)+1);
|
char *needle_case = malloc(strlen(needle)+1);
|
||||||
strcpy(needle_case, needle);
|
memcpy(needle_case, needle, strlen(needle)+1);
|
||||||
passes = 0;
|
passes = 0;
|
||||||
while (*needle_case) {
|
while (*needle_case) {
|
||||||
*needle_case = *needle_case | ' ';
|
*needle_case = *needle_case | ' ';
|
||||||
@@ -34,7 +34,7 @@ char* smartstrcasestr(char *haystack, const char *needle){
|
|||||||
needle_case -= passes;
|
needle_case -= passes;
|
||||||
|
|
||||||
char *haystack_case = malloc(strlen(haystack)+1);
|
char *haystack_case = malloc(strlen(haystack)+1);
|
||||||
strcpy(haystack_case, haystack);
|
memcpy(haystack_case, haystack, strlen(haystack)+1);
|
||||||
passes = 0;
|
passes = 0;
|
||||||
while (*haystack_case) {
|
while (*haystack_case) {
|
||||||
*haystack_case = *haystack_case | ' ';
|
*haystack_case = *haystack_case | ' ';
|
||||||
|
|||||||
@@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
|
|
||||||
char* concat(const char *s1, const char *s2);
|
char* concat(const char *s1, const char *s2);
|
||||||
char* smartstrcasestr(char *haystack, const char *needle);
|
char* smartstrcasestr(const char *haystack, const char *needle);
|
||||||
|
|||||||
2
colors.c
2
colors.c
@@ -108,7 +108,7 @@ void colors_init() {
|
|||||||
if (line[0] == '.') {
|
if (line[0] == '.') {
|
||||||
extension = strtok(line, " ");
|
extension = strtok(line, " ");
|
||||||
colors[i].file_extension = malloc(strlen(extension)+1);
|
colors[i].file_extension = malloc(strlen(extension)+1);
|
||||||
strcpy(colors[i].file_extension, extension);
|
memcpy(colors[i].file_extension, extension, strlen(extension)+1);
|
||||||
|
|
||||||
colors[i].color_pair = i+11;
|
colors[i].color_pair = i+11;
|
||||||
parse_colors(line, &fg, &bg);
|
parse_colors(line, &fg, &bg);
|
||||||
|
|||||||
@@ -56,6 +56,9 @@
|
|||||||
#define YANK_CUT 2
|
#define YANK_CUT 2
|
||||||
#define YANK_COPY 4
|
#define YANK_COPY 4
|
||||||
|
|
||||||
|
#define BTM_WINDOW_HEIGHT_ON_STR_INTERACTION 5
|
||||||
|
#define INPUT_BUFFER_SIZE 255
|
||||||
|
|
||||||
#ifndef STRUCT_GUARD
|
#ifndef STRUCT_GUARD
|
||||||
#define STRUCT_GUARD
|
#define STRUCT_GUARD
|
||||||
/* complex types are good actually */
|
/* complex types are good actually */
|
||||||
|
|||||||
2
dir.c
2
dir.c
@@ -66,7 +66,7 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
||||||
} else {
|
} else {
|
||||||
dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1);
|
dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1);
|
||||||
strcpy(dir_content[i].file_name, entry[i]->d_name);
|
memcpy(dir_content[i].file_name, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
||||||
|
|
||||||
|
|
||||||
struct stat *file;
|
struct stat *file;
|
||||||
|
|||||||
239
interactions.c
239
interactions.c
@@ -40,14 +40,14 @@ extern char *input;
|
|||||||
|
|
||||||
extern time_t *seed;
|
extern time_t *seed;
|
||||||
|
|
||||||
char search_buffer[255];
|
char search_buffer[INPUT_BUFFER_SIZE];
|
||||||
unsigned int timeout_time = 0;
|
unsigned int timeout_time = 0;
|
||||||
unsigned int input_pass;
|
unsigned int input_pass;
|
||||||
unsigned long parsed_input_number;
|
unsigned long parsed_input_number;
|
||||||
yank yank_files = { 0 };
|
yank yank_files = { 0 };
|
||||||
|
|
||||||
int read_string(WINDOW *win, int y, int x, char *str);
|
|
||||||
extern void render_pass();
|
extern void render_pass();
|
||||||
|
extern void window_btm(WINDOW *win, char force_render);
|
||||||
extern int (*order_func)();
|
extern int (*order_func)();
|
||||||
|
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ void user_interactions() {
|
|||||||
if (ch == 27) { /* esc key */
|
if (ch == 27) { /* esc key */
|
||||||
memset(input, ' ', terminal_width);
|
memset(input, ' ', terminal_width);
|
||||||
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
||||||
memset(input, 0, 255);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
timeout(100); /* blocking timeout of getch() */
|
timeout(100); /* blocking timeout of getch() */
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ void user_interactions() {
|
|||||||
attroff(A_UNDERLINE);
|
attroff(A_UNDERLINE);
|
||||||
status &= ~STATUS_INPUT_MATCH;
|
status &= ~STATUS_INPUT_MATCH;
|
||||||
} else if (number_length != strlen(input)) {
|
} else if (number_length != strlen(input)) {
|
||||||
memset(input, 0, 255);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
binding_pass = 0;
|
binding_pass = 0;
|
||||||
number_length = 0;
|
number_length = 0;
|
||||||
@@ -236,7 +236,7 @@ void move_right(){
|
|||||||
if (mid_content->file_name[0] == '\0') {
|
if (mid_content->file_name[0] == '\0') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mid_content[selected_file_current].file_type &= FILE_TYPE_DIR) {
|
if ((mid_content[selected_file_current].file_type & FILE_TYPE_DIR) == FILE_TYPE_DIR) {
|
||||||
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
||||||
FAIL("move_right", "unhandled error of chdir");
|
FAIL("move_right", "unhandled error of chdir");
|
||||||
} else {
|
} else {
|
||||||
@@ -272,9 +272,7 @@ void move_right(){
|
|||||||
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
|
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, "\"");
|
||||||
btm_buffer = malloc(strlen(cmd));
|
|
||||||
|
|
||||||
strcpy(btm_buffer, cmd-1);
|
|
||||||
|
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
@@ -325,26 +323,25 @@ void jump_top(){
|
|||||||
void open_with(){
|
void open_with(){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
|
|
||||||
|
char *btm_buffer_tmp = btm_buffer;
|
||||||
|
werase(win_b);
|
||||||
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
btm_buffer = concat("open \"", mid_content[selected_file_current].file_name);
|
btm_buffer = concat("open \"", mid_content[selected_file_current].file_name);
|
||||||
btm_buffer = concat(btm_buffer, "\" with:");
|
btm_buffer = concat(btm_buffer, "\" with:");
|
||||||
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
window_btm(win_b, 1);
|
||||||
werase(win_b);
|
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
|
||||||
|
|
||||||
render_pass();
|
|
||||||
unsigned long local_height;
|
|
||||||
local_height = getmaxy(win_b);
|
|
||||||
|
|
||||||
|
|
||||||
/* TODO(2025-06-22T01:24:36) fix fixed buffer size */
|
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||||
char *str = malloc(255);
|
memset(str, ' ', INPUT_BUFFER_SIZE);
|
||||||
memset(str, ' ', 255);
|
str[INPUT_BUFFER_SIZE-1] = '\0';
|
||||||
int err = read_string(win_b, local_height - 1, 0 , str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0 , str);
|
||||||
|
|
||||||
|
|
||||||
if (!err) {
|
if (err == 0) {
|
||||||
char *cmd = concat(str, " ./\"");
|
char *cmd = concat(str, " ./\"");
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, "\"");
|
||||||
@@ -356,39 +353,34 @@ void open_with(){
|
|||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
FAIL("open_with", "creating subcommand failed unhandled");
|
FAIL("open_with", "creating subcommand failed unhandled");
|
||||||
}
|
}
|
||||||
|
|
||||||
free(btm_buffer);
|
|
||||||
btm_buffer = cmd;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = btm_buffer_tmp;
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
|
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rename_hovered(){
|
void rename_hovered(){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
|
char *btm_buffer_tmp = btm_buffer;
|
||||||
|
werase(win_b);
|
||||||
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name);
|
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name);
|
||||||
btm_buffer = concat(btm_buffer, "\" to:");
|
btm_buffer = concat(btm_buffer, "\" to:");
|
||||||
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
window_btm(win_b, 1);
|
||||||
werase(win_b);
|
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||||
render_pass();
|
memset(str, ' ', INPUT_BUFFER_SIZE);
|
||||||
pthread_mutex_lock(&mutex_btm);
|
str[INPUT_BUFFER_SIZE-1] = '\0';
|
||||||
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
unsigned long local_height;
|
|
||||||
local_height = getmaxy(win_b);
|
|
||||||
|
|
||||||
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
|
||||||
char *str = malloc(255);
|
|
||||||
memset(str, ' ', 255);
|
|
||||||
int err = read_string(win_b, local_height - 1, 0, str);
|
|
||||||
|
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@@ -402,17 +394,21 @@ void rename_hovered(){
|
|||||||
};
|
};
|
||||||
btm_buffer = cmd;
|
btm_buffer = cmd;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
free(str);
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = btm_buffer_tmp;
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
|
|
||||||
free(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete(){
|
void delete(){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
|
char *btm_buffer_tmp = btm_buffer;
|
||||||
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int hits = 0;
|
unsigned int hits = 0;
|
||||||
char *file_str = " ";
|
char *file_str = " ";
|
||||||
@@ -425,32 +421,52 @@ void delete(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hits) {
|
|
||||||
btm_buffer = concat("delete:", file_str);
|
|
||||||
} else {
|
|
||||||
btm_buffer = concat("delete: \"", mid_content[selected_file_current].file_name);
|
|
||||||
btm_buffer = concat(btm_buffer, "\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
btm_buffer = concat(btm_buffer, "?");
|
|
||||||
btm_buffer = concat(btm_buffer, "\n\n");
|
|
||||||
btm_buffer = concat(btm_buffer, "(y/N)");
|
|
||||||
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
if (strlen(file_str) < (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION-1) * (terminal_width/3)) {
|
||||||
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3));
|
||||||
|
memset(btm_buffer, ' ', (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)));
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
memcpy(btm_buffer, "delete: ",strlen("delete: "));
|
||||||
render_pass();
|
if (hits) {
|
||||||
pthread_mutex_lock(&mutex_btm);
|
memcpy(btm_buffer + strlen("delete: "), file_str, strlen(file_str));
|
||||||
|
} else {
|
||||||
|
btm_buffer[strlen("delete: ")] = '"';
|
||||||
|
memcpy(btm_buffer + strlen("delete: ") + sizeof(char), mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)-1);
|
||||||
|
btm_buffer[strlen("delete: ") + sizeof(char) + strlen(mid_content[selected_file_current].file_name)] = '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3) - (terminal_width/3)) , "(y/N)", strlen("(y/N)"));
|
||||||
|
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)] = '\0';
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/*since more data is present than can be represented using div3, we do the uncool thing*/
|
||||||
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width);
|
||||||
|
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||||
|
memset(btm_buffer, ' ', BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||||
|
|
||||||
|
memcpy(btm_buffer, "delete: ",strlen("delete: "));
|
||||||
|
|
||||||
|
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
|
||||||
|
/*lets hope im never gonna need to format something like this ever again*/
|
||||||
|
memcpy(btm_buffer + strlen("delete: "), file_str,
|
||||||
|
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
|
||||||
|
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
|
||||||
|
strlen(file_str)));
|
||||||
|
|
||||||
|
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width - terminal_width) , "(y/N)", strlen("(y/N)"));
|
||||||
|
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
timeout(-1); /* negative numbers block until enter is pressed */
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
/* TODO(2025-06-22T01:24:30) fix fixed buffer size */
|
|
||||||
char ch = wgetch(win_b);
|
char ch = wgetch(win_b);
|
||||||
|
|
||||||
if (ch == 'y' || ch == 'Y') {
|
if (ch == 'y' || ch == 'Y') {
|
||||||
/* TODO(2025-06-30T02:27:06) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
|
||||||
if (hits) {
|
if (hits) {
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
@@ -458,54 +474,45 @@ void delete(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = concat("deleted: ", file_str);
|
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
||||||
recursive_delete(mid_content[selected_file_current]);
|
recursive_delete(mid_content[selected_file_current]);
|
||||||
}
|
}
|
||||||
remove(mid_content[selected_file_current].file_name);
|
remove(mid_content[selected_file_current].file_name);
|
||||||
btm_buffer = concat("deleted: \"", mid_content[selected_file_current].file_name);
|
|
||||||
btm_buffer = concat(btm_buffer, "\"");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*system(cmd);*/
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = "cancled deletion";
|
btm_buffer = btm_buffer_tmp;
|
||||||
|
if (hits) {
|
||||||
|
free(file_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout(10);
|
timeout(10);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
|
||||||
if (hits) {
|
|
||||||
free(file_str);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void makedir(){
|
void makedir(){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
|
|
||||||
|
char *btm_buffer_tmp = btm_buffer;
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
memset(btm_buffer, ' ', terminal_width);
|
|
||||||
memcpy(btm_buffer, "create dir: ", strlen("create dir: "));
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
btm_buffer = "create dir: ";
|
||||||
render_pass();
|
|
||||||
pthread_mutex_lock(&mutex_btm);
|
|
||||||
|
|
||||||
unsigned long local_height;
|
window_btm(win_b, 1);
|
||||||
local_height = getmaxy(win_b);
|
|
||||||
|
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||||
|
memset(str, ' ', INPUT_BUFFER_SIZE);
|
||||||
|
str[INPUT_BUFFER_SIZE-1] = '\0';
|
||||||
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
/* TODO(2025-07-03T01:19:55) fix fixed buffer size */
|
|
||||||
char *str = malloc(255);
|
|
||||||
memset(str, ' ', 255);
|
|
||||||
int err = read_string(win_b, local_height - 1, 0, str);
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
btm_buffer = concat(btm_buffer, str);
|
btm_buffer = concat(btm_buffer, str);
|
||||||
mode_t mask = umask(0);
|
mode_t mask = umask(0);
|
||||||
@@ -513,29 +520,29 @@ void makedir(){
|
|||||||
umask(mask);
|
umask(mask);
|
||||||
}
|
}
|
||||||
free(str);
|
free(str);
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = btm_buffer_tmp;
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
void makefile(){
|
void makefile(){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
memcpy(btm_buffer, "create file: ", strlen("create file: "));
|
char *btm_buffer_tmp = btm_buffer;
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
btm_buffer = "create file: ";
|
||||||
render_pass();
|
|
||||||
pthread_mutex_lock(&mutex_btm);
|
|
||||||
|
|
||||||
unsigned long local_height;
|
window_btm(win_b, 1);
|
||||||
local_height = getmaxy(win_b);
|
|
||||||
|
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||||
|
memset(str, ' ', INPUT_BUFFER_SIZE);
|
||||||
|
str[INPUT_BUFFER_SIZE-1] = '\0';
|
||||||
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
/* TODO(2025-07-03T01:19:49) fix fixed buffer size */
|
|
||||||
char *str = malloc(255);
|
|
||||||
memset(str, ' ', 255);
|
|
||||||
int err = read_string(win_b, local_height - 1, 0, str);
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
btm_buffer = concat(btm_buffer, str);
|
btm_buffer = concat(btm_buffer, str);
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@@ -543,8 +550,11 @@ void makefile(){
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
free(str);
|
free(str);
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
free(btm_buffer);
|
||||||
|
btm_buffer = btm_buffer_tmp;
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(){
|
void update(){
|
||||||
@@ -590,7 +600,7 @@ void jump_to_dir(unsigned long passes, int index){
|
|||||||
ch = (char*)key_binding[index].black_magic;
|
ch = (char*)key_binding[index].black_magic;
|
||||||
if (*ch == '/') {
|
if (*ch == '/') {
|
||||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||||
strcpy(path, (char*)key_binding[index].black_magic);
|
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
||||||
} else if (slash) {
|
} else if (slash) {
|
||||||
env_str = malloc(env_len * sizeof(char));
|
env_str = malloc(env_len * sizeof(char));
|
||||||
memcpy(env_str, (char*)key_binding[index].black_magic +1, env_len);
|
memcpy(env_str, (char*)key_binding[index].black_magic +1, env_len);
|
||||||
@@ -600,16 +610,16 @@ void jump_to_dir(unsigned long passes, int index){
|
|||||||
path = concat(env_parsed, (char*)key_binding[index].black_magic + env_len);
|
path = concat(env_parsed, (char*)key_binding[index].black_magic + env_len);
|
||||||
} else {
|
} else {
|
||||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||||
strcpy(path, (char*)key_binding[index].black_magic);
|
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
env_parsed = getenv((char*)key_binding[index].black_magic +1);
|
env_parsed = getenv((char*)key_binding[index].black_magic +1);
|
||||||
if (env_parsed) {
|
if (env_parsed) {
|
||||||
path = malloc(strlen(env_parsed)+1);
|
path = malloc(strlen(env_parsed)+1);
|
||||||
strcpy(path, env_parsed);
|
memcpy(path, env_parsed, strlen(env_parsed)+1);
|
||||||
} else {
|
} else {
|
||||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||||
strcpy(path, (char*)key_binding[index].black_magic);
|
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chdir(path) != 0) {
|
if (chdir(path) != 0) {
|
||||||
@@ -642,6 +652,7 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
(void)passes;
|
(void)passes;
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
|
char *btm_buffer_tmp = btm_buffer;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int hits = 0;
|
unsigned int hits = 0;
|
||||||
char *file_str = " ";
|
char *file_str = " ";
|
||||||
@@ -666,15 +677,11 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
btm_buffer = concat(btm_buffer, "\n\n");
|
btm_buffer = concat(btm_buffer, "\n\n");
|
||||||
btm_buffer = concat(btm_buffer, "(y/N)");
|
btm_buffer = concat(btm_buffer, "(y/N)");
|
||||||
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
|
||||||
render_pass();
|
|
||||||
pthread_mutex_lock(&mutex_btm);
|
|
||||||
|
|
||||||
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
timeout(-1); /* negative numbers block until enter is pressed */
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
/* TODO(2025-07-06T07:22:49) fix fixed buffer size */
|
/* TODO(2025-07-06T07:22:49) fix fixed buffer size */
|
||||||
@@ -717,6 +724,8 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
memcpy(btm_buffer, "cancled deletion", strlen("cancled deletion"));
|
memcpy(btm_buffer, "cancled deletion", strlen("cancled deletion"));
|
||||||
}
|
}
|
||||||
|
free(btm_buffer);
|
||||||
|
btm_buffer = btm_buffer_tmp;
|
||||||
|
|
||||||
timeout(10);
|
timeout(10);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
@@ -772,13 +781,13 @@ void yank_file(unsigned long passes, int index){
|
|||||||
yank_files.count = 1;
|
yank_files.count = 1;
|
||||||
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
|
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
|
||||||
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
||||||
strcpy(*yank_files.list, mid_content[selected_file_current].file_name);
|
memcpy(*yank_files.list, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
||||||
} else {
|
} else {
|
||||||
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
||||||
strcpy(*yank_files.list, mid_content[i].file_name);
|
memcpy(*yank_files.list, mid_content[i].file_name, strlen(mid_content[i].file_name));
|
||||||
yank_files.list += 1;
|
yank_files.list += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -808,11 +817,11 @@ void paste(){
|
|||||||
cmd = concat(cmd, " ./");
|
cmd = concat(cmd, " ./");
|
||||||
cmd = concat(cmd, *yank_files.list);
|
cmd = concat(cmd, *yank_files.list);
|
||||||
cmd = concat(cmd, " 2>&1");
|
cmd = concat(cmd, " 2>&1");
|
||||||
char *line = malloc(255);
|
char *line = malloc(INPUT_BUFFER_SIZE);
|
||||||
FILE *cmd_open;
|
FILE *cmd_open;
|
||||||
while (1) {
|
while (1) {
|
||||||
cmd_open = popen(cmd, "r");
|
cmd_open = popen(cmd, "r");
|
||||||
if (fgets(line, 255, cmd_open) == 0) {
|
if (fgets(line, INPUT_BUFFER_SIZE, cmd_open) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strstr(line, "are the same file")) {
|
if (strstr(line, "are the same file")) {
|
||||||
@@ -844,11 +853,9 @@ void search(){
|
|||||||
|
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
local_height = getmaxy(win_b);
|
local_height = getmaxy(win_b);
|
||||||
memset(search_buffer, '\0', 255);
|
memset(search_buffer, '\0', INPUT_BUFFER_SIZE);
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
window_btm(win_b, 1);
|
||||||
render_pass();
|
|
||||||
pthread_mutex_lock(&mutex_btm);
|
|
||||||
|
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
|
|
||||||
@@ -936,9 +943,9 @@ void search_previous(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void jmp_file_index(){
|
void jmp_file_index(){
|
||||||
char *index = malloc(255);
|
char *index = malloc(INPUT_BUFFER_SIZE);
|
||||||
memset(index, ' ', 255);
|
memset(index, ' ', INPUT_BUFFER_SIZE);
|
||||||
index[254] = '\0';
|
index[INPUT_BUFFER_SIZE-1] = '\0';
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
local_height = getmaxy(win_b);
|
local_height = getmaxy(win_b);
|
||||||
read_string(win_b, local_height - 1, 0, index);
|
read_string(win_b, local_height - 1, 0, index);
|
||||||
|
|||||||
11
main.c
11
main.c
@@ -145,11 +145,6 @@ void render_pass(){
|
|||||||
|
|
||||||
/*TODO: check if deallocation of window and reallocation is faster than this or not */
|
/*TODO: check if deallocation of window and reallocation is faster than this or not */
|
||||||
|
|
||||||
wclear(win_t);
|
|
||||||
wclear(win_b);
|
|
||||||
wclear(win_l);
|
|
||||||
wclear(win_m);
|
|
||||||
wclear(win_r);
|
|
||||||
|
|
||||||
wresize(win_t, 1, terminal_width);
|
wresize(win_t, 1, terminal_width);
|
||||||
wresize(win_l, terminal_height-2, terminal_width/8);
|
wresize(win_l, terminal_height-2, terminal_width/8);
|
||||||
@@ -174,7 +169,7 @@ void render_pass(){
|
|||||||
window_lft(win_l);
|
window_lft(win_l);
|
||||||
window_mid(win_m);
|
window_mid(win_m);
|
||||||
window_rgt(win_r);
|
window_rgt(win_r);
|
||||||
window_btm(win_b);
|
window_btm(win_b, 0);
|
||||||
wrefresh(win_t);
|
wrefresh(win_t);
|
||||||
wrefresh(win_l);
|
wrefresh(win_l);
|
||||||
wrefresh(win_m);
|
wrefresh(win_m);
|
||||||
@@ -192,8 +187,8 @@ void init() {
|
|||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
||||||
input = malloc(sizeof(char)*255); /* size of input buffer, out of bounds access will not be accounted for */
|
input = malloc(INPUT_BUFFER_SIZE); /* size of input buffer, out of bounds access will not be accounted for */
|
||||||
memset(input, 0, 255);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
if (getuid() == 0) {
|
if (getuid() == 0) {
|
||||||
status |= STATUS_USER_ROOT;
|
status |= STATUS_USER_ROOT;
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ void *thread_rgt(){
|
|||||||
char *path;
|
char *path;
|
||||||
if (mid_file_count != 0) {
|
if (mid_file_count != 0) {
|
||||||
path = malloc(strlen(mid_content[selected_file_current].file_name) + 1);
|
path = malloc(strlen(mid_content[selected_file_current].file_name) + 1);
|
||||||
strcpy(path, mid_content[selected_file_current].file_name);
|
memcpy(path, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)+1);
|
||||||
} else {
|
} else {
|
||||||
path = malloc(sizeof(char));
|
path = malloc(sizeof(char));
|
||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
|
|||||||
6
window.c
6
window.c
@@ -48,7 +48,7 @@ void window_top(WINDOW *win){
|
|||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_btm(WINDOW *win){
|
void window_btm(WINDOW *win, char force_render){
|
||||||
werase(win);
|
werase(win);
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_btm) == 0) {
|
if (pthread_mutex_trylock(&mutex_btm) == 0) {
|
||||||
@@ -58,6 +58,10 @@ void window_btm(WINDOW *win){
|
|||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
/*the printing of the input char is done in user_interactions*/
|
/*the printing of the input char is done in user_interactions*/
|
||||||
/*the printing of all possible inputs are done in user_interactions */
|
/*the printing of all possible inputs are done in user_interactions */
|
||||||
|
} else if (force_render) {
|
||||||
|
/*force_render is used in stuff like open_with, search, and other functions that take over win_b,
|
||||||
|
* while needing to avoid possible conflicts like thread_btm itself*/
|
||||||
|
mvwprintw(win, 0, 0, "%s", btm_buffer);
|
||||||
} else {
|
} else {
|
||||||
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
|||||||
2
window.h
2
window.h
@@ -1,7 +1,7 @@
|
|||||||
#include "window.c"
|
#include "window.c"
|
||||||
|
|
||||||
void window_top(WINDOW *win);
|
void window_top(WINDOW *win);
|
||||||
void window_btm(WINDOW *win);
|
void window_btm(WINDOW *win, char force_render);
|
||||||
void window_lft(WINDOW *win);
|
void window_lft(WINDOW *win);
|
||||||
void window_mid(WINDOW *win);
|
void window_mid(WINDOW *win);
|
||||||
void window_rgt(WINDOW *win);
|
void window_rgt(WINDOW *win);
|
||||||
|
|||||||
Reference in New Issue
Block a user