aboutsummaryrefslogtreecommitdiff
path: root/include/types.h
blob: 800c3d61f215d1c623ae1bf5a4ecb2a1a1c0e77f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#ifndef ECEX_TYPES_H
#define ECEX_TYPES_H

#include <stddef.h>

typedef struct ecex ecex_t;
typedef struct buffer buffer_t;
typedef struct ecex_window ecex_window_t;
typedef struct ecex_draw_context ecex_draw_context_t;

typedef int (*ecex_command_fn)(ecex_t *ed);
typedef int (*ecex_interactive_line_fn)(ecex_t *ed, buffer_t *buffer, size_t line, const char *payload, void *userdata);
typedef const char *(*ecex_clipboard_get_fn)(void *userdata);
typedef void (*ecex_clipboard_set_fn)(void *userdata, const char *text);
typedef int (*ecex_buffer_render_fn)(ecex_t *ed, buffer_t *buffer, ecex_draw_context_t *ctx, void *userdata);
typedef int (*ecex_buffer_tick_fn)(ecex_t *ed, buffer_t *buffer, double now_seconds, void *userdata);
typedef int (*ecex_buffer_tick_ms_fn)(ecex_t *ed, buffer_t *buffer, int now_ms, void *userdata);
typedef int (*ecex_buffer_mouse_fn)(ecex_t *ed, buffer_t *buffer, int event, int x, int y, int button, void *userdata);
typedef int (*ecex_file_handler_fn)(ecex_t *ed, buffer_t *buffer);
typedef void (*ecex_buffer_userdata_free_fn)(void *userdata);

typedef enum ecex_prompt_request {
    ECEX_PROMPT_NONE = 0,
    ECEX_PROMPT_FIND_FILE,
    ECEX_PROMPT_WRITE_FILE,
    ECEX_PROMPT_EVAL_FILE,
    ECEX_PROMPT_SWITCH_BUFFER,
    ECEX_PROMPT_KILL_BUFFER,
    ECEX_PROMPT_FORCE_KILL_BUFFER,
    ECEX_PROMPT_COMPILE,
    ECEX_PROMPT_GREP,
    ECEX_PROMPT_ISEARCH_FORWARD,
    ECEX_PROMPT_ISEARCH_BACKWARD,
} ecex_prompt_request_t;


#define ECEX_RENDER_OVERLAY 0
#define ECEX_RENDER_REPLACE_CONTENT 1

#define ECEX_MOUSE_MOVE 0
#define ECEX_MOUSE_PRESS 1
#define ECEX_MOUSE_RELEASE 2
#define ECEX_MOUSE_DRAG 3
#define ECEX_MOUSE_BUTTON_LEFT 0
#define ECEX_MOUSE_BUTTON_RIGHT 1
#define ECEX_MOUSE_BUTTON_MIDDLE 2

typedef enum ecex_draw_text_align {
    ECEX_TEXT_ALIGN_LEFT = 0,
    ECEX_TEXT_ALIGN_CENTER = 1,
    ECEX_TEXT_ALIGN_RIGHT = 2,
} ecex_draw_text_align_t;

struct ecex_draw_context {
    float x;
    float y;
    float w;
    float h;
    float content_x;
    float content_y;
    float content_w;
    float content_h;
    float font_size;
    float line_height;
    float char_width;
    size_t window_index;
    int active;
    void *internal;
};

typedef struct ecex_undo_entry {
    char *data;
    size_t len;
    size_t point;
    size_t mark;
    int mark_active;
} ecex_undo_entry_t;

typedef struct ecex_color {
    float r;
    float g;
    float b;
} ecex_color_t;

typedef struct ecex_theme {
    char *font_path;
    float font_size;

    ecex_color_t bg;
    ecex_color_t fg;

    ecex_color_t status_bg;
    ecex_color_t status_fg;
    ecex_color_t status_border;

    ecex_color_t cursor;
    ecex_color_t region_bg;
    ecex_color_t minibuffer_bg;
    ecex_color_t minibuffer_fg;

    ecex_color_t completion_fg;
    int completion_enabled;

    ecex_color_t interactive_highlight_bg;
    ecex_color_t interactive_highlight_fg;
    ecex_color_t current_line_bg;
    ecex_color_t search_bg;
    int line_numbers_enabled;
    int current_line_enabled;
} ecex_theme_t;

struct buffer {
    char *name;
    char *path;

    char *data;
    size_t len;
    size_t cap;

    size_t point;
    size_t mark;
    int mark_active;

    size_t scroll_line;
    size_t scroll_col;

    int modified;
    int read_only;

    int major_mode;

    ecex_undo_entry_t *undo_stack;
    size_t undo_count;
    size_t undo_cap;
    ecex_undo_entry_t *redo_stack;
    size_t redo_count;
    size_t redo_cap;
    int undo_disabled;

    int interactive;
    struct ecex_interactive_line_action *interactive_actions;
    size_t interactive_action_cap;
    size_t interactive_action_count;

    int media_kind;
    char *media_path;
    int media_width;
    int media_height;
    unsigned char *media_pixels;
    int media_dirty;
    unsigned int media_texture;
    int media_texture_width;
    int media_texture_height;
    void *media_pipe;
    double media_last_frame_time;
    int media_playing;
    char media_status[256];

    ecex_buffer_render_fn render_fn;
    void *render_userdata;
    ecex_buffer_userdata_free_fn render_userdata_free;
    int render_flags;

    ecex_buffer_mouse_fn mouse_fn;
    void *mouse_userdata;
    ecex_buffer_userdata_free_fn mouse_userdata_free;

    ecex_buffer_tick_fn tick_fn;
    ecex_buffer_tick_ms_fn tick_ms_fn;
    void *tick_userdata;
    ecex_buffer_userdata_free_fn tick_userdata_free;
    double tick_interval;
    double tick_last_time;
    int tick_enabled;
    int tick_uses_ms;
};

typedef struct ecex_interactive_line_action {
    size_t line;
    ecex_interactive_line_fn fn;
    char *payload;
    void *userdata;
} ecex_interactive_line_action_t;

typedef struct ecex_command {
    char *name;
    ecex_command_fn fn;
} ecex_command_t;

typedef struct ecex_keybind {
    char *key;
    char *command;
} ecex_keybind_t;

typedef struct ecex_mode_keybind {
    int mode;
    char *key;
    char *command;
} ecex_mode_keybind_t;

typedef struct ecex_major_mode {
    int id;
    char *name;
} ecex_major_mode_t;

typedef enum ecex_var_kind {
    ECEX_VAR_BYTES = 0,
    ECEX_VAR_I32 = 1,
} ecex_var_kind_t;

typedef struct ecex_var_entry {
    void *owner;
    char *name;
    void *data;
    size_t elem_size;
    size_t count;
    int kind;
    int dynamic;
} ecex_var_entry_t;

typedef struct ecex_text_entry {
    void *owner;
    int id;
    char *text;
    size_t len;
} ecex_text_entry_t;

typedef struct ecex_file_handler {
    char *extension;
    ecex_file_handler_fn fn;
} ecex_file_handler_t;

typedef struct ecex_object_entry {
    void *ptr;
    size_t size;
} ecex_object_entry_t;

struct ecex_window {
    buffer_t *buffer;
    float x;
    float y;
    float w;
    float h;
};

struct ecex {
    buffer_t **buffers;
    size_t buffer_cap;
    size_t buffer_count;

    size_t current_buffer_index;
    buffer_t *current_buffer;
    buffer_t *previous_buffer;

    ecex_window_t *windows;
    size_t window_cap;
    size_t window_count;
    size_t current_window_index;

    void **jit_modules;
    size_t jit_module_cap;
    size_t jit_module_count;

    ecex_command_t *commands;
    size_t command_cap;
    size_t command_count;

    ecex_keybind_t *keybinds;
    size_t keybind_cap;
    size_t keybind_count;

    ecex_mode_keybind_t *mode_keybinds;
    size_t mode_keybind_cap;
    size_t mode_keybind_count;

    ecex_major_mode_t *major_modes;
    size_t major_mode_cap;
    size_t major_mode_count;
    int next_major_mode_id;

    ecex_var_entry_t *vars;
    size_t var_cap;
    size_t var_count;

    ecex_text_entry_t *texts;
    size_t text_cap;
    size_t text_count;

    ecex_file_handler_t *file_handlers;
    size_t file_handler_cap;
    size_t file_handler_count;

    ecex_object_entry_t *objects;
    size_t object_cap;
    size_t object_count;

    char *last_eval_source;
    char *last_eval_filename;
    int last_eval_wrap_as_statements;

    char *last_compile_command;
    char *last_grep_command;

    ecex_prompt_request_t prompt_request;
    char prompt_message[128];

    char *config_path;

    ecex_clipboard_get_fn clipboard_get;
    ecex_clipboard_set_fn clipboard_set;
    void *clipboard_userdata;

    int should_quit;

    ecex_theme_t theme;
};

#endif