mirror of
https://gittea.dev/nova/th.git
synced 2025-10-22 10:50:15 -04:00
improvenments to the renderer
This commit is contained in:
101
dir.c
101
dir.c
@@ -16,6 +16,7 @@ extern unsigned int file_modifiers;
|
|||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
extern unsigned int terminal_height;
|
extern unsigned int terminal_height;
|
||||||
extern volatile unsigned long selected_file_current;
|
extern volatile unsigned long selected_file_current;
|
||||||
|
extern volatile unsigned long selected_file_last;
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
int (*order_func)() = sort_natural;
|
int (*order_func)() = sort_natural;
|
||||||
|
|
||||||
@@ -187,43 +188,6 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
}
|
}
|
||||||
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) {
|
|
||||||
file_size = dir_content[i].file_size;
|
|
||||||
char size_index = 0;
|
|
||||||
while (file_size > 1) {
|
|
||||||
printed_size=file_size;
|
|
||||||
file_size /= 1024;
|
|
||||||
size_index++;
|
|
||||||
if (size_index >= 6) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size_char = sizes[size_index-1];
|
|
||||||
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
|
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1);
|
|
||||||
} else if (size_char =='B') {
|
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
|
||||||
} else {
|
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
is_selected = 1;
|
|
||||||
} else {
|
|
||||||
is_selected = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
wattron(win, COLOR_PAIR(8));
|
|
||||||
} else {
|
|
||||||
wattron(win, COLOR_PAIR(dir_content[i].color_pair));
|
|
||||||
}
|
|
||||||
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
|
||||||
wattron(win, A_REVERSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* shortens the printed file name if it is too long
|
/* shortens the printed file name if it is too long
|
||||||
* example input: aaaaaaaa.txt
|
* example input: aaaaaaaa.txt
|
||||||
* example output: aaa~.txt
|
* example output: aaa~.txt
|
||||||
@@ -258,6 +222,45 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
file_name[file_name_width] = '\0';
|
file_name[file_name_width] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (print_info) {
|
||||||
|
file_size = dir_content[i].file_size;
|
||||||
|
char size_index = 0;
|
||||||
|
while (file_size > 1) {
|
||||||
|
printed_size=file_size;
|
||||||
|
file_size /= 1024;
|
||||||
|
size_index++;
|
||||||
|
if (size_index >= 6) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size_char = sizes[size_index-1];
|
||||||
|
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
|
||||||
|
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1);
|
||||||
|
} else if (size_char =='B') {
|
||||||
|
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
||||||
|
} else {
|
||||||
|
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
is_selected = 1;
|
||||||
|
} else {
|
||||||
|
is_selected = 0;
|
||||||
|
}
|
||||||
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
|
wattron(win, COLOR_PAIR(8));
|
||||||
|
} else {
|
||||||
|
wattron(win, COLOR_PAIR(dir_content[i].color_pair));
|
||||||
|
}
|
||||||
|
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
||||||
|
wattron(win, A_REVERSE);
|
||||||
|
} else {
|
||||||
|
wattroff(win, A_REVERSE);
|
||||||
|
}
|
||||||
|
|
||||||
mvwaddstr(win, i-offset_vertical, 0, bg);
|
mvwaddstr(win, i-offset_vertical, 0, bg);
|
||||||
if(print_info) {
|
if(print_info) {
|
||||||
#if SETTINGS_LINE_NUMBERS == 2
|
#if SETTINGS_LINE_NUMBERS == 2
|
||||||
@@ -298,9 +301,6 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
free(file_name);
|
free(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
|
||||||
wattroff(win, A_REVERSE);
|
|
||||||
}
|
|
||||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
wattroff(win, COLOR_PAIR(8));
|
wattroff(win, COLOR_PAIR(8));
|
||||||
} else {
|
} else {
|
||||||
@@ -311,3 +311,24 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
free(bg);
|
free(bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_selected_file(){
|
||||||
|
if (selected_file_current >= mid_file_count) {
|
||||||
|
selected_file_current = mid_file_count-1;
|
||||||
|
}
|
||||||
|
if (selected_file_current != selected_file_last) {
|
||||||
|
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
||||||
|
}
|
||||||
|
selected_file_last = selected_file_current;
|
||||||
|
|
||||||
|
free(file_current->file_name);
|
||||||
|
file_current->file_name = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
||||||
|
strcpy(file_current->file_name, mid_content[selected_file_current].file_name);
|
||||||
|
file_current->file_name[strlen(mid_content[selected_file_current].file_name)] = '\0';
|
||||||
|
file_current->file_size = mid_content[selected_file_current].file_size;
|
||||||
|
file_current->file_type = mid_content[selected_file_current].file_type;
|
||||||
|
file_current->color_pair = mid_content[selected_file_current].color_pair;
|
||||||
|
file_current->permissions = mid_content[selected_file_current].permissions;
|
||||||
|
|
||||||
|
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
||||||
|
file_current->status = mid_content[selected_file_current].status;
|
||||||
|
}
|
||||||
|
7
dir.h
7
dir.h
@@ -3,6 +3,7 @@
|
|||||||
#include "dir.c"
|
#include "dir.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern unsigned long get_dir_size(char *path);
|
unsigned long get_dir_size(char *path);
|
||||||
extern void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
||||||
extern void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
|
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
|
||||||
|
void update_selected_file();
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "dir.h"
|
||||||
|
|
||||||
|
|
||||||
extern volatile unsigned long selected_file_current;
|
extern volatile unsigned long selected_file_current;
|
||||||
@@ -191,9 +192,11 @@ void move_down(int passes){
|
|||||||
if (passes == 0) {
|
if (passes == 0) {
|
||||||
passes++;
|
passes++;
|
||||||
}
|
}
|
||||||
/*capping the maximum file is done inside thread_mid */
|
|
||||||
selected_file_current += passes;
|
selected_file_current += passes;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
|
||||||
|
update_selected_file();
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
void move_up(int passes){
|
void move_up(int passes){
|
||||||
@@ -201,12 +204,14 @@ void move_up(int passes){
|
|||||||
if (passes == 0) {
|
if (passes == 0) {
|
||||||
passes++;
|
passes++;
|
||||||
}
|
}
|
||||||
int i;
|
unsigned long tmp = selected_file_current;
|
||||||
for (i = 0; i < passes; i++) {
|
selected_file_current -= passes;
|
||||||
if (selected_file_current != 0) {
|
if (tmp < selected_file_current) {
|
||||||
selected_file_current--;
|
selected_file_current = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_selected_file();
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
@@ -273,6 +278,7 @@ void move_right(){
|
|||||||
}
|
}
|
||||||
free(mime);
|
free(mime);
|
||||||
}
|
}
|
||||||
|
update_selected_file();
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void toggle_hidden_files(){
|
void toggle_hidden_files(){
|
||||||
@@ -282,12 +288,14 @@ void toggle_hidden_files(){
|
|||||||
void jump_bottom(){
|
void jump_bottom(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0 - 1;
|
selected_file_current = 0 - 1;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
update_selected_file();
|
||||||
|
status |= (STATUS_UPDATE_SCREEN_MASK);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
void jump_top(){
|
void jump_top(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0;
|
selected_file_current = 0;
|
||||||
|
update_selected_file();
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
|
25
threading.c
25
threading.c
@@ -97,30 +97,11 @@ void *thread_mid(void *data){
|
|||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
|
pthread_mutex_lock(&mutex_selection);
|
||||||
|
update_selected_file();
|
||||||
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex_selection);
|
|
||||||
if (selected_file_current >= mid_file_count) {
|
|
||||||
selected_file_current = mid_file_count-1;
|
|
||||||
selected_file_current = mid_file_count-1;
|
|
||||||
}
|
|
||||||
if (selected_file_current != selected_file_last) {
|
|
||||||
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
|
||||||
}
|
|
||||||
selected_file_last = selected_file_current;
|
|
||||||
|
|
||||||
free(file_current->file_name);
|
|
||||||
file_current->file_name = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
|
||||||
strcpy(file_current->file_name, mid_content[selected_file_current].file_name);
|
|
||||||
file_current->file_name[strlen(mid_content[selected_file_current].file_name)] = '\0';
|
|
||||||
file_current->file_size = mid_content[selected_file_current].file_size;
|
|
||||||
file_current->file_type = mid_content[selected_file_current].file_type;
|
|
||||||
file_current->color_pair = mid_content[selected_file_current].color_pair;
|
|
||||||
file_current->permissions = mid_content[selected_file_current].permissions;
|
|
||||||
|
|
||||||
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
|
||||||
file_current->status = mid_content[selected_file_current].status;
|
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
|
||||||
|
|
||||||
while(wait_count < 2){
|
while(wait_count < 2){
|
||||||
/*wait for thread_rgt and thread_btm to lock*/
|
/*wait for thread_rgt and thread_btm to lock*/
|
||||||
|
3
window.c
3
window.c
@@ -65,7 +65,6 @@ void window_btm(WINDOW *win){
|
|||||||
}
|
}
|
||||||
void window_lft(WINDOW *win){
|
void window_lft(WINDOW *win){
|
||||||
werase(win);
|
werase(win);
|
||||||
box(win, 0, 0);
|
|
||||||
|
|
||||||
unsigned long local_width;
|
unsigned long local_width;
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
@@ -81,7 +80,6 @@ void window_lft(WINDOW *win){
|
|||||||
}
|
}
|
||||||
void window_mid(WINDOW *win){
|
void window_mid(WINDOW *win){
|
||||||
werase(win);
|
werase(win);
|
||||||
box(win, 0, 0);
|
|
||||||
|
|
||||||
unsigned long local_width;
|
unsigned long local_width;
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
@@ -100,7 +98,6 @@ void window_mid(WINDOW *win){
|
|||||||
}
|
}
|
||||||
void window_rgt(WINDOW *win){
|
void window_rgt(WINDOW *win){
|
||||||
werase(win);
|
werase(win);
|
||||||
box(win, 0, 0);
|
|
||||||
|
|
||||||
unsigned long local_width;
|
unsigned long local_width;
|
||||||
unsigned long local_height;
|
unsigned long local_height;
|
||||||
|
Reference in New Issue
Block a user