1
0
mirror of https://gittea.dev/nova/th.git synced 2025-12-09 09:10:10 -05:00

Compare commits

...

3 Commits

Author SHA1 Message Date
nova
5287c77648 varrious small changes 2025-11-09 17:40:56 +01:00
nova
5b7f017588 jump to /usr added 2025-11-04 22:16:51 +01:00
nova
33d7761329 some fixes to copy pasting 2025-11-04 22:16:21 +01:00
3 changed files with 39 additions and 55 deletions

View File

@@ -1,6 +1,7 @@
#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching */
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds of how often the directory should be reload */
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching; depends on ueberzug */
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds between automatic refresh of dir contents */
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
/* {{{ */
#ifndef CONFIG_GUARD
@@ -82,6 +83,7 @@ static const binding key_binding[] = {
{ "go", jump_to_dir, "/opt", "jump to /opt" },
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
{ "gv", jump_to_dir, "/var", "jump to /var" },
{ "gu", jump_to_dir, "/usr", "jump to /usr" },
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },

View File

@@ -64,53 +64,42 @@ void user_interactions() {
char ch;
unsigned long i;
unsigned long binding_matches = 0;
static char binding_pass = 0;
ch = getch();
if(ch != ERR) {
timeout(10); /* blocking timeout of getch() */
input[input_pass] = ch;
input_pass++;
if (ch == 27) { /* esc key */
memset(input, ' ', terminal_width);
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
memset(input, 0, INPUT_BUFFER_SIZE);
input_pass = 0;
timeout(100); /* blocking timeout of getch() */
}
binding_pass = 0;
status |= STATUS_UPDATE_SCREEN_0;
} else {
timeout(100);
}
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
void (*func_ptr)(int, int);
unsigned long number_length = 0;
if (!binding_pass) {
parsed_input_number = 0;
while((*input >= '0') && (*input <= '9')) {
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
input++;
number_length++;
}
input -= number_length;
binding_pass = 1;
parsed_input_number = 0;
while((*input >= '0') && (*input <= '9')) {
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
input++;
number_length++;
}
input -= number_length;
char cmp_len = strlen(input);
if(strlen(input) < 1) {
cmp_len++;
cmp_len = 1;
}
for (i = 0; i < binding_count; i++) {
if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
if (strcmp(input + number_length, key_binding[i].key) == 0) {
func_ptr = key_binding[i].func;
func_ptr(parsed_input_number, i);
timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */
} else {
binding_matches++;
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
@@ -127,10 +116,8 @@ void user_interactions() {
} else if (number_length != strlen(input)) {
memset(input, 0, INPUT_BUFFER_SIZE);
input_pass = 0;
binding_pass = 0;
number_length = 0;
binding_matches = 0;
timeout(100); /* blocking timeout of getch() */
}
}
int read_string(WINDOW *win, int y, int x, char *str){
@@ -169,7 +156,6 @@ int read_string(WINDOW *win, int y, int x, char *str){
}
str[pass] = '\0';
timeout(100);
curs_set(0);
return err;
@@ -487,7 +473,6 @@ void delete(){
free(file_str);
}
timeout(10);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
pthread_mutex_unlock(&mutex_btm);
@@ -719,7 +704,6 @@ void cmd_on_selected(unsigned long passes, int index){
free(btm_buffer);
btm_buffer = btm_buffer_tmp;
timeout(10);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
if (hits) {
@@ -773,13 +757,13 @@ void yank_file(unsigned long passes, int index){
yank_files.count = 1;
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
memcpy(*yank_files.list, mid_content[selected_file_current].file_name, strlen(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)+1);
} else {
yank_files.list = malloc(yank_files.count * sizeof(char*));
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
memcpy(*yank_files.list, mid_content[i].file_name, strlen(mid_content[i].file_name));
memcpy(*yank_files.list, mid_content[i].file_name, strlen(mid_content[i].file_name)+1);
yank_files.list += 1;
}
}
@@ -800,7 +784,7 @@ void paste(){
/*TODO(2025-08-14T22:10:44) escape path*/
char *cmd;
if (yank_files.status & YANK_COPY) {
cmd = concat("false | cp -riv ", yank_files.path);
cmd = concat("false | cp -ri ", yank_files.path);
} else {
cmd = concat("mv ", yank_files.path);
}
@@ -827,10 +811,13 @@ void paste(){
} else if ((strstr(line, "No such file or directory"))) {
pclose(cmd_open);
break;
} else if (pclose(cmd_open) == 0) {
} else if ((strstr(line, "into itself"))) {
pclose(cmd_open);
break;
}
if (pclose(cmd_open) == 0) {
break;
}
pclose(cmd_open);
}
free(cmd);
@@ -897,7 +884,6 @@ void search(){
}
search_buffer[pass] = '\0';
timeout(10);
curs_set(0);
dir_set_selected_file_current(selected_file_current);

40
main.c
View File

@@ -7,6 +7,7 @@
#include <time.h>
#include "defines.h"
#include "config.h"
#include "threading.h"
#include "window.c"
#include "colors.h"
@@ -58,7 +59,6 @@ int main(){
pthread_t thread_m;
pthread_t thread_r;
char threading = 0;
terminal_width_empty_line = malloc(terminal_width);
#if SETTINGS_RELOAD_DIR_DELTA != 0
time_t t;
@@ -71,7 +71,17 @@ int main(){
pthread_create(&thread_m, NULL, thread_mid, &status); /*current_content slash win_m*/
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
/* running through all once manually in order to get an as fast as possible first render on the screen */
pthread_cond_signal(&cond_top);
pthread_cond_signal(&cond_mid);
pthread_cond_signal(&cond_lft);
user_interactions();
render_pass();
timeout(SETTINGS_CURSES_TIMEOUT);
while(!(status & STATUS_QUIT_PROGRAM)){
getmaxyx(stdscr, terminal_height, terminal_width);
@@ -80,21 +90,17 @@ int main(){
temp_width = terminal_width;
temp_heigth = terminal_height;
}
if (threading) {
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
threading = 0;
}
if (status & STATUS_RUN_BACKEND) {
pthread_cond_signal(&cond_top);
pthread_cond_signal(&cond_mid);
pthread_cond_signal(&cond_lft);
status &= ~(STATUS_RUN_BACKEND);
status |= STATUS_UPDATE_SCREEN_0;
threading = 1;
} else {
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
}
user_interactions();
render_pass();
#if SETTINGS_RELOAD_DIR_DELTA != 0
@@ -112,16 +118,6 @@ int main(){
threading_free();
free(start_path);
/*
if (threading) {
pthread_join(thread_l, NULL);
pthread_join(thread_r, NULL);
pthread_join(thread_m, NULL);
pthread_join(thread_t, NULL);
pthread_join(thread_b, NULL);
}
*/
delwin(win_l);
delwin(win_m);
delwin(win_r);
@@ -143,9 +139,6 @@ void render_pass(){
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
}
/*TODO: check if deallocation of window and reallocation is faster than this or not */
wresize(win_t, 1, terminal_width);
wresize(win_l, terminal_height-2, terminal_width/8);
wresize(win_m, terminal_height-2, (terminal_width/2)-(terminal_width/8));
@@ -183,7 +176,10 @@ void init() {
setlocale(LC_ALL, "");
initscr(); /* start ncurses */
noecho(); /* hide keyboard input */
timeout(0); /* blocking timeout of getch() */
timeout(10); /* blocking timeout of getch(), using 10 rather than SETTINGS_CURSES_TIMEOUT to cause a faster first render
regardless on SETTINGS_CURSES_TIMEOUT, 10 was taken arbitrary.
if the blocking is too low, the first render happens delayed, however even this delay causes a quicker than
(compute time of threads) + timeout */
curs_set(0);
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/