mirror of
https://gittea.dev/nova/th.git
synced 2026-01-30 16:50:10 -05:00
varrious small changes
This commit is contained in:
5
config.h
5
config.h
@@ -1,6 +1,7 @@
|
|||||||
#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */
|
#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_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 of how often the directory should be reload */
|
#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
|
#ifndef CONFIG_GUARD
|
||||||
|
|||||||
@@ -64,53 +64,42 @@ void user_interactions() {
|
|||||||
char ch;
|
char ch;
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
unsigned long binding_matches = 0;
|
unsigned long binding_matches = 0;
|
||||||
static char binding_pass = 0;
|
|
||||||
|
|
||||||
|
|
||||||
ch = getch();
|
ch = getch();
|
||||||
if(ch != ERR) {
|
if(ch != ERR) {
|
||||||
timeout(10); /* blocking timeout of getch() */
|
|
||||||
input[input_pass] = ch;
|
input[input_pass] = ch;
|
||||||
input_pass++;
|
input_pass++;
|
||||||
if (ch == 27) { /* esc key */
|
if (ch == 27) { /* esc key */
|
||||||
memset(input, ' ', terminal_width);
|
|
||||||
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
|
||||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
timeout(100); /* blocking timeout of getch() */
|
|
||||||
}
|
}
|
||||||
binding_pass = 0;
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
} else {
|
|
||||||
timeout(100);
|
|
||||||
}
|
}
|
||||||
mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void (*func_ptr)(int, int);
|
void (*func_ptr)(int, int);
|
||||||
unsigned long number_length = 0;
|
unsigned long number_length = 0;
|
||||||
|
|
||||||
if (!binding_pass) {
|
parsed_input_number = 0;
|
||||||
parsed_input_number = 0;
|
while((*input >= '0') && (*input <= '9')) {
|
||||||
while((*input >= '0') && (*input <= '9')) {
|
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
||||||
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
input++;
|
||||||
input++;
|
number_length++;
|
||||||
number_length++;
|
|
||||||
}
|
|
||||||
input -= number_length;
|
|
||||||
binding_pass = 1;
|
|
||||||
}
|
}
|
||||||
|
input -= number_length;
|
||||||
|
|
||||||
char cmp_len = strlen(input);
|
char cmp_len = strlen(input);
|
||||||
if(strlen(input) < 1) {
|
if(strlen(input) < 1) {
|
||||||
cmp_len++;
|
cmp_len = 1;
|
||||||
}
|
}
|
||||||
for (i = 0; i < binding_count; i++) {
|
for (i = 0; i < binding_count; i++) {
|
||||||
if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
||||||
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
||||||
func_ptr = key_binding[i].func;
|
func_ptr = key_binding[i].func;
|
||||||
func_ptr(parsed_input_number, i);
|
func_ptr(parsed_input_number, i);
|
||||||
|
|
||||||
|
timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */
|
||||||
} else {
|
} else {
|
||||||
binding_matches++;
|
binding_matches++;
|
||||||
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
|
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
|
||||||
@@ -127,10 +116,8 @@ void user_interactions() {
|
|||||||
} else if (number_length != strlen(input)) {
|
} else if (number_length != strlen(input)) {
|
||||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
binding_pass = 0;
|
|
||||||
number_length = 0;
|
number_length = 0;
|
||||||
binding_matches = 0;
|
binding_matches = 0;
|
||||||
timeout(100); /* blocking timeout of getch() */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int read_string(WINDOW *win, int y, int x, char *str){
|
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';
|
str[pass] = '\0';
|
||||||
|
|
||||||
timeout(100);
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@@ -487,7 +473,6 @@ void delete(){
|
|||||||
free(file_str);
|
free(file_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
@@ -719,7 +704,6 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = btm_buffer_tmp;
|
btm_buffer = btm_buffer_tmp;
|
||||||
|
|
||||||
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) {
|
if (hits) {
|
||||||
@@ -900,7 +884,6 @@ void search(){
|
|||||||
}
|
}
|
||||||
search_buffer[pass] = '\0';
|
search_buffer[pass] = '\0';
|
||||||
|
|
||||||
timeout(10);
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
dir_set_selected_file_current(selected_file_current);
|
dir_set_selected_file_current(selected_file_current);
|
||||||
|
|||||||
38
main.c
38
main.c
@@ -7,6 +7,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#include "config.h"
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "window.c"
|
#include "window.c"
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
@@ -58,7 +59,6 @@ int main(){
|
|||||||
pthread_t thread_m;
|
pthread_t thread_m;
|
||||||
pthread_t thread_r;
|
pthread_t thread_r;
|
||||||
|
|
||||||
char threading = 0;
|
|
||||||
terminal_width_empty_line = malloc(terminal_width);
|
terminal_width_empty_line = malloc(terminal_width);
|
||||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||||
time_t t;
|
time_t t;
|
||||||
@@ -72,6 +72,16 @@ int main(){
|
|||||||
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
||||||
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
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)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||||
|
|
||||||
@@ -80,21 +90,17 @@ int main(){
|
|||||||
temp_width = terminal_width;
|
temp_width = terminal_width;
|
||||||
temp_heigth = terminal_height;
|
temp_heigth = terminal_height;
|
||||||
}
|
}
|
||||||
if (threading) {
|
|
||||||
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
|
||||||
threading = 0;
|
|
||||||
}
|
|
||||||
if (status & STATUS_RUN_BACKEND) {
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
pthread_cond_signal(&cond_top);
|
pthread_cond_signal(&cond_top);
|
||||||
pthread_cond_signal(&cond_mid);
|
pthread_cond_signal(&cond_mid);
|
||||||
pthread_cond_signal(&cond_lft);
|
pthread_cond_signal(&cond_lft);
|
||||||
status &= ~(STATUS_RUN_BACKEND);
|
status &= ~(STATUS_RUN_BACKEND);
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
threading = 1;
|
} else {
|
||||||
|
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
||||||
}
|
}
|
||||||
user_interactions();
|
user_interactions();
|
||||||
|
|
||||||
|
|
||||||
render_pass();
|
render_pass();
|
||||||
|
|
||||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||||
@@ -112,16 +118,6 @@ int main(){
|
|||||||
threading_free();
|
threading_free();
|
||||||
free(start_path);
|
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_l);
|
||||||
delwin(win_m);
|
delwin(win_m);
|
||||||
delwin(win_r);
|
delwin(win_r);
|
||||||
@@ -143,9 +139,6 @@ void render_pass(){
|
|||||||
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
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_t, 1, terminal_width);
|
||||||
wresize(win_l, terminal_height-2, terminal_width/8);
|
wresize(win_l, terminal_height-2, terminal_width/8);
|
||||||
wresize(win_m, terminal_height-2, (terminal_width/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, "");
|
setlocale(LC_ALL, "");
|
||||||
initscr(); /* start ncurses */
|
initscr(); /* start ncurses */
|
||||||
noecho(); /* hide keyboard input */
|
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);
|
curs_set(0);
|
||||||
|
|
||||||
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
||||||
|
|||||||
Reference in New Issue
Block a user