aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h2
-rw-r--r--src/cdraw.h1
-rw-r--r--src/user.c20
3 files changed, 16 insertions, 7 deletions
diff --git a/config.def.h b/config.def.h
index 396f26a..ee8e1fa 100644
--- a/config.def.h
+++ b/config.def.h
@@ -4,6 +4,8 @@ const unsigned int maxzoom = 20;
const unsigned int fps = 30;
const char *def_palette_path = "assets/default.gpl";
const char *def_theme_path = "assets/ui.png";
+/* path to an external program for picking files. it should output only the picked file in stdout */
+const char *cmd_file_picker = NULL; /* NULL - will take input from terminal */
const unsigned int back_c = COLTOINT(146, 161, 185);
static Key keys[] = {
diff --git a/src/cdraw.h b/src/cdraw.h
index 0f57a7f..38bb058 100644
--- a/src/cdraw.h
+++ b/src/cdraw.h
@@ -10,6 +10,7 @@ extern SDL_Window *win;
extern void *ren;
extern void *def_palette;
extern const char *def_palette_path;
+extern const char *cmd_file_picker;
extern int mouseX, mouseY;
extern const unsigned int back_c;
diff --git a/src/user.c b/src/user.c
index ab86010..0261c65 100644
--- a/src/user.c
+++ b/src/user.c
@@ -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);
}