summaryrefslogtreecommitdiff
path: root/menu.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-18 20:54:07 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-18 20:54:07 -0500
commit8a4984e0e15fcfb0be6db242ab3f60325b80abd8 (patch)
treeb71eb3ec8e715164a9347cb6ce7d6d83298309d0 /menu.c
parent530001a433c847b40d109d08cd8ff0958efdca1c (diff)
bug fixes, narrow file list based on search term
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/menu.c b/menu.c
index 9ef2245..7c09d53 100644
--- a/menu.c
+++ b/menu.c
@@ -31,8 +31,10 @@ static void menu_render(Ted *ted, Menu menu) {
gl_color_rgba(colors[COLOR_MENU_BACKDROP]);
rect_render(rect(V2(0, 0), V2(window_width, window_height)));
glEnd();
+
if (menu == MENU_OPEN) {
+ char *search_term = str32_to_utf8_cstr(buffer_get_line(&ted->line_buffer, 0));
char const *directory = ".";
float padding = 20;
float menu_x1 = window_width * 0.5f - 300;
@@ -62,8 +64,21 @@ static void menu_render(Ted *ted, Menu menu) {
char **files = fs_list_directory(directory);
if (files) {
+
u32 nfiles = 0;
for (char **p = files; *p; ++p) ++nfiles;
+
+ if (search_term && *search_term) {
+ // filter files based on search term
+ u32 in, out = 0;
+ for (in = 0; in < nfiles; ++in) {
+ if (stristr(files[in], search_term)) {
+ files[out++] = files[in];
+ }
+ }
+ nfiles = out;
+ }
+
qsort(files, nfiles, sizeof *files, str_qsort_case_insensitive_cmp);
{ // render file names
@@ -79,5 +94,7 @@ static void menu_render(Ted *ted, Menu menu) {
for (u32 i = 0; i < nfiles; ++i) free(files[i]);
free(files);
}
+ free(search_term);
}
+
}