aboutsummaryrefslogtreecommitdiff
path: root/include/types.h
blob: 1dc2158cf9a9606103236e938e5531d67272cee7 (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
#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 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 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_COMPILE,
    ECEX_PROMPT_GREP,
    ECEX_PROMPT_ISEARCH_FORWARD,
    ECEX_PROMPT_ISEARCH_BACKWARD,
} ecex_prompt_request_t;

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;
};

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;

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;

    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;

    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