1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-21 18:30:15 -04:00

implemented file search

This commit is contained in:
nova
2025-08-17 21:29:49 +02:00
parent f0a2f14966
commit 1d54169c2d
3 changed files with 97 additions and 2 deletions

View File

@@ -42,7 +42,9 @@ static const binding key_binding[] = {
{ " ", 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 */
{ "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 */
{ "t", move_down, NULL, "move down" },

View File

@@ -1,6 +1,7 @@
#include <curses.h>
#include <pthread.h>
#include <dirent.h>
#include <string.h>
#include "file_previews.h"
#include "backend.h"
@@ -34,6 +35,7 @@ extern unsigned int status;
extern char *start_path;
extern char *input;
char search_buffer[255];
unsigned int timeout_time = 0;
unsigned int input_pass;
int parsed_input_number;
@@ -289,7 +291,7 @@ void jump_bottom(){
pthread_mutex_lock(&mutex_selection);
selected_file_current = 0 - 1;
update_selected_file();
status |= (STATUS_UPDATE_SCREEN_MASK);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
}
void jump_top(){
@@ -732,3 +734,91 @@ void paste(){
yank_files.list -= yank_files.count;
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;
}
}
}

View File

@@ -27,3 +27,6 @@ void order_by(int passes, int index);
void cmd_on_selected(int passes, int index);
void yank_file(int passes, int index);
void paste();
void search();
void search_next();
void search_previous();