diff options
author | Krow Savcik <krow@savcik.xyz> | 2024-01-11 16:23:38 +0200 |
---|---|---|
committer | Krow Savcik <krow@savcik.xyz> | 2024-01-11 16:23:38 +0200 |
commit | f15cde15550aaa8118b56709b67178a858f64012 (patch) | |
tree | cc6db5dc6382e96631606ea3ca509793fe773bfb /src/user.c | |
parent | 32b8f82aa85a9f616eef7b6442670d8558a0b4d8 (diff) |
feature: picking file
Now you can pick a file for import/export/open/save with an external command.
Diffstat (limited to 'src/user.c')
-rw-r--r-- | src/user.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <SDL2/SDL.h> @@ -86,7 +87,6 @@ user_canvas_open(const Arg *x) void user_canvas_export_png(const Arg *x) { - puts("called"); char line[1024]; if (cur_canvas == NULL) return; choose_file_path("Image File Name (export): ", line); @@ -226,13 +226,19 @@ user_testing_reload_tex(const Arg *_x) static void choose_file_path(const char *prompt, char *input) { - printf(prompt); - fflush(stdout); + FILE *ft; + ft = cmd_file_picker == NULL ? NULL : popen(cmd_file_picker, "r"); + input[0] = '\0'; + + if (ft == NULL) { +/*TODO: error; for now using terminal input as backup*/ + printf(prompt); + fflush(stdout); + ft = stdin; + } - do { - fgets(input, 1024, stdin); - } while (strlen(input) < 4); + while (fgets(input, 1024, ft) != NULL && strlen(input) < 4); input[strcspn(input, "\n")] = '\0'; - printf("%s\n", input); + if (ft != stdin) pclose(ft); } |