feat: add fzf-based file/plugin/port selection and update build system
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
@@ -350,6 +351,18 @@ void tui_run(void) {
|
||||
rack_mode = !rack_mode;
|
||||
rack_selected = 0;
|
||||
break;
|
||||
case KEY_F(5):
|
||||
script_handle_fzf_command("sample");
|
||||
draw_grid();
|
||||
break;
|
||||
case KEY_F(6):
|
||||
script_handle_fzf_command("plugin");
|
||||
draw_grid();
|
||||
break;
|
||||
case KEY_F(7):
|
||||
script_handle_fzf_command("from");
|
||||
draw_grid();
|
||||
break;
|
||||
case 27: case 'Q':
|
||||
if (rack_mode) {
|
||||
rack_mode = false;
|
||||
@@ -396,6 +409,69 @@ void tui_run(void) {
|
||||
}
|
||||
}
|
||||
|
||||
char* tui_fzf_select(const char *const items[], size_t count, const char *prompt) {
|
||||
if (!items || count == 0) return NULL;
|
||||
|
||||
// Save ncurses state
|
||||
def_prog_mode();
|
||||
endwin();
|
||||
|
||||
// Build a temporary file with the items list
|
||||
char tmpfile[] = "/tmp/tui_fzf_XXXXXX";
|
||||
int fd = mkstemp(tmpfile);
|
||||
if (fd == -1) {
|
||||
reset_prog_mode();
|
||||
refresh();
|
||||
return NULL;
|
||||
}
|
||||
FILE *tmp = fdopen(fd, "w");
|
||||
if (!tmp) {
|
||||
close(fd);
|
||||
unlink(tmpfile);
|
||||
reset_prog_mode();
|
||||
refresh();
|
||||
return NULL;
|
||||
}
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (items[i])
|
||||
fprintf(tmp, "%s\n", items[i]);
|
||||
}
|
||||
fclose(tmp);
|
||||
|
||||
// Build fzf command reading from the temporary file
|
||||
char cmd[8192];
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"fzf --prompt='%s' < %s",
|
||||
prompt ? prompt : "Select: ",
|
||||
tmpfile);
|
||||
|
||||
FILE *result = popen(cmd, "r");
|
||||
if (!result) {
|
||||
unlink(tmpfile);
|
||||
reset_prog_mode();
|
||||
refresh();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char selected[4096] = {0};
|
||||
if (fgets(selected, sizeof(selected), result) != NULL) {
|
||||
size_t len = strlen(selected);
|
||||
if (len > 0 && selected[len-1] == '\n')
|
||||
selected[len-1] = '\0';
|
||||
}
|
||||
pclose(result);
|
||||
unlink(tmpfile);
|
||||
|
||||
// Restore ncurses
|
||||
reset_prog_mode();
|
||||
refresh();
|
||||
|
||||
if (selected[0] == '\0')
|
||||
return NULL;
|
||||
|
||||
return strdup(selected);
|
||||
}
|
||||
|
||||
void tui_cleanup(void) {
|
||||
if (yank_buffer.clip_indices) free(yank_buffer.clip_indices);
|
||||
/* free script note allocations */
|
||||
|
||||
Reference in New Issue
Block a user