mirror of
https://gittea.dev/nova/th.git
synced 2025-10-22 10:50:15 -04:00
Compare commits
2 Commits
017bf407d9
...
1d54169c2d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1d54169c2d | ||
![]() |
f0a2f14966 |
4
config.h
4
config.h
@@ -42,7 +42,9 @@ static const binding key_binding[] = {
|
|||||||
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
||||||
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||||
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" },
|
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" },
|
||||||
{ "/", not_implemented, NULL, "search" },
|
{ "/", search, NULL, "search" },
|
||||||
|
{ "l", search_next, NULL, "search next" },
|
||||||
|
{ "L", search_previous, NULL, "search previous" },
|
||||||
|
|
||||||
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
|
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
|
||||||
{ "t", move_down, NULL, "move down" },
|
{ "t", move_down, NULL, "move down" },
|
||||||
|
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();
|
||||||
|
112
interactions.c
112
interactions.c
@@ -1,11 +1,13 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "file_previews.h"
|
#include "file_previews.h"
|
||||||
#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;
|
||||||
@@ -33,6 +35,7 @@ extern unsigned int status;
|
|||||||
extern char *start_path;
|
extern char *start_path;
|
||||||
extern char *input;
|
extern char *input;
|
||||||
|
|
||||||
|
char search_buffer[255];
|
||||||
unsigned int timeout_time = 0;
|
unsigned int timeout_time = 0;
|
||||||
unsigned int input_pass;
|
unsigned int input_pass;
|
||||||
int parsed_input_number;
|
int parsed_input_number;
|
||||||
@@ -191,9 +194,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 +206,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 +280,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 +290,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;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -724,3 +734,91 @@ void paste(){
|
|||||||
yank_files.list -= yank_files.count;
|
yank_files.list -= yank_files.count;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
void search(){
|
||||||
|
mvprintw(terminal_height - 1, 0, "/");
|
||||||
|
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
|
|
||||||
|
render_pass();
|
||||||
|
unsigned long local_height;
|
||||||
|
local_height = getmaxy(win_b);
|
||||||
|
|
||||||
|
memset(search_buffer, '\0', 255);
|
||||||
|
render_pass();
|
||||||
|
|
||||||
|
curs_set(1);
|
||||||
|
|
||||||
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
|
|
||||||
|
unsigned int pass = 0;
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
wmove(win_b, local_height-1, 1);
|
||||||
|
while(1) {
|
||||||
|
/*ch = mvwgetch(win, y, x + pass);*/
|
||||||
|
werase(win_b);
|
||||||
|
mvwaddch(win_b, local_height-1, 0, '/');
|
||||||
|
mvwaddstr(win_b, local_height-1, 1, search_buffer);
|
||||||
|
ch = wgetch(win_b);
|
||||||
|
if (ch == '\n') {
|
||||||
|
break;
|
||||||
|
} else if (ch == 27) { /* esc key */
|
||||||
|
break;
|
||||||
|
} else if (ch == 127) { /* backspace */
|
||||||
|
mvwdelch(win_b, local_height-1, 1);
|
||||||
|
wdelch(win_b);
|
||||||
|
if (pass != 0) {
|
||||||
|
search_buffer[pass-1] = '\0';
|
||||||
|
pass--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
search_buffer[pass] = ch;
|
||||||
|
pass++;
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
|
if (strstr(mid_content[i].file_name, search_buffer)) {
|
||||||
|
selected_file_current = i;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
|
update_selected_file();
|
||||||
|
render_pass();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
search_buffer[pass] = '\0';
|
||||||
|
|
||||||
|
timeout(10);
|
||||||
|
curs_set(0);
|
||||||
|
|
||||||
|
update_selected_file();
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
|
}
|
||||||
|
void search_next(){
|
||||||
|
unsigned long i;
|
||||||
|
for (i = selected_file_current+1; i < mid_file_count; i++) {
|
||||||
|
if (strstr(mid_content[i].file_name, search_buffer)) {
|
||||||
|
selected_file_current = i;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
|
update_selected_file();
|
||||||
|
render_pass();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void search_previous(){
|
||||||
|
unsigned long i;
|
||||||
|
for (i = selected_file_current-1;; i--) {
|
||||||
|
if(i > selected_file_current) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (strstr(mid_content[i].file_name, search_buffer)) {
|
||||||
|
selected_file_current = i;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
|
update_selected_file();
|
||||||
|
render_pass();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -27,3 +27,6 @@ void order_by(int passes, int index);
|
|||||||
void cmd_on_selected(int passes, int index);
|
void cmd_on_selected(int passes, int index);
|
||||||
void yank_file(int passes, int index);
|
void yank_file(int passes, int index);
|
||||||
void paste();
|
void paste();
|
||||||
|
void search();
|
||||||
|
void search_next();
|
||||||
|
void search_previous();
|
||||||
|
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);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
if (selected_file_current >= mid_file_count) {
|
update_selected_file();
|
||||||
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);
|
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