mirror of
https://gittea.dev/nova/th.git
synced 2025-10-25 04:10:15 -04:00
'refactoring'
This commit is contained in:
@@ -57,6 +57,7 @@
|
|||||||
#define YANK_COPY 4
|
#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
|
||||||
|
|
||||||
#ifndef STRUCT_GUARD
|
#ifndef STRUCT_GUARD
|
||||||
#define STRUCT_GUARD
|
#define STRUCT_GUARD
|
||||||
|
|||||||
@@ -40,15 +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();
|
||||||
void window_btm(WINDOW *win, char force_render);
|
extern void window_btm(WINDOW *win, char force_render);
|
||||||
extern int (*order_func)();
|
extern int (*order_func)();
|
||||||
|
|
||||||
|
|
||||||
@@ -78,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() */
|
||||||
}
|
}
|
||||||
@@ -126,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;
|
||||||
@@ -336,9 +335,9 @@ void open_with(){
|
|||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
|
|
||||||
/* 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, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0 , str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0 , str);
|
||||||
|
|
||||||
|
|
||||||
@@ -378,9 +377,9 @@ void rename_hovered(){
|
|||||||
|
|
||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
/* TODO(2025-06-22T01:24:30) 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, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
|
|
||||||
@@ -442,15 +441,19 @@ void delete(){
|
|||||||
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)] = '\0';
|
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)] = '\0';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width); /*since more data is present than can be represented using div3, we do the uncool thing)*/
|
/*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);
|
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||||
memset(btm_buffer, ' ', 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: "));
|
memcpy(btm_buffer, "delete: ",strlen("delete: "));
|
||||||
memcpy(btm_buffer + strlen("delete: "), file_str, /* this horrendous check tries to copy everything until the last line, while keeping said last line unwritten */
|
|
||||||
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
|
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
|
||||||
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
|
/*lets hope im never gonna need to format something like this ever again*/
|
||||||
strlen(file_str)));
|
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)"));
|
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';
|
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width] = '\0';
|
||||||
@@ -461,7 +464,6 @@ void delete(){
|
|||||||
window_btm(win_b, 1);
|
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') {
|
||||||
@@ -506,9 +508,9 @@ void makedir(){
|
|||||||
|
|
||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
/* TODO(2025-07-03T01:19:55) 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, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@@ -536,9 +538,9 @@ void makefile(){
|
|||||||
|
|
||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
/* TODO(2025-07-03T01:19:49) 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, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@@ -815,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")) {
|
||||||
@@ -851,7 +853,7 @@ 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);
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
@@ -941,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);
|
||||||
|
|||||||
4
main.c
4
main.c
@@ -187,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;
|
||||||
|
|||||||
Reference in New Issue
Block a user