aboutsummaryrefslogtreecommitdiff
path: root/include/app.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/app.h')
-rw-r--r--include/app.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/include/app.h b/include/app.h
new file mode 100644
index 0000000..cb09b04
--- /dev/null
+++ b/include/app.h
@@ -0,0 +1,95 @@
+#ifndef ECEX_APP_H
+#define ECEX_APP_H
+
+#include "ecex.h"
+#include "font.h"
+
+#include <GLFW/glfw3.h>
+#include <stddef.h>
+
+#define ECEX_MINIBUFFER_SIZE 256
+#define ECEX_PREFIX_SIZE 128
+
+typedef enum app_mode {
+ APP_MODE_EDIT = 0,
+ APP_MODE_MX = 1,
+ APP_MODE_PREFIX = 2,
+ APP_MODE_PROMPT = 3,
+ APP_MODE_ISEARCH = 4,
+} app_mode_t;
+
+typedef struct app {
+ ecex_t *ed;
+ GLFWwindow *window;
+
+ int width;
+ int height;
+ int dirty;
+
+ app_mode_t mode;
+
+ char minibuffer[ECEX_MINIBUFFER_SIZE];
+ size_t minibuffer_len;
+
+ char message[ECEX_MINIBUFFER_SIZE];
+
+ ecex_prompt_request_t prompt_kind;
+ int isearch_backward;
+ char isearch_query[ECEX_MINIBUFFER_SIZE];
+ size_t isearch_len;
+ size_t isearch_origin;
+ size_t isearch_match;
+ int isearch_has_match;
+ char last_search_query[ECEX_MINIBUFFER_SIZE];
+ char prompt_label[128];
+ char prompt_input[1024];
+ size_t prompt_input_len;
+
+ /*
+ * File/path prompt completion state for find-file and write-file.
+ * prompt_completion_query stores the original typed path/query while
+ * prompt_input is temporarily replaced with the selected candidate.
+ */
+ int prompt_completion_active;
+ char prompt_completion_query[1024];
+ size_t prompt_completion_index;
+ size_t prompt_completion_count;
+ char prompt_completion_preview[8][1024];
+ size_t prompt_completion_preview_start;
+ size_t prompt_completion_preview_count;
+
+ /*
+ * M-x completion state.
+ * completion_query is the original user query used to build the candidate
+ * list. This lets the UI replace the minibuffer with a candidate while
+ * Up/Down still cycle through matches for the original query, e.g.
+ * "-buffer" -> next-buffer / previous-buffer / end-of-buffer / ...
+ */
+ int completion_active;
+ char completion_query[ECEX_MINIBUFFER_SIZE];
+ size_t completion_index;
+ size_t completion_count;
+
+ char prefix[ECEX_PREFIX_SIZE];
+ size_t prefix_len;
+
+ int current_mods;
+
+ /*
+ * GLFW sends key events and text events separately. When a printable
+ * key is consumed as part of a command sequence, suppress the matching
+ * char_callback so it does not insert into the buffer after the command
+ * returns to edit mode.
+ */
+ int suppress_next_char;
+
+ font_t font;
+ char font_path[4096];
+} app_t;
+
+void app_init(app_t *app, ecex_t *ed);
+void app_set_window(app_t *app, GLFWwindow *window);
+void app_install_callbacks(app_t *app);
+void app_message(app_t *app, const char *msg);
+
+#endif