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
|
#ifndef LEMACS_EDITOR_H
#define LEMACS_EDITOR_H
#include <stdbool.h>
#include <stdint.h>
#include "core/buffer.h"
#define LEMACS_MAX_AUX_BUFFERS 8
#define LEMACS_MAX_VIEWS 16
#define LEMACS_MAX_BUFFERS 32
#define LEMACS_CURSOR_BAR 0
#define LEMACS_CURSOR_BLOCK 1
#define LEMACS_CURSOR_UNDERLINE 2
typedef struct {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
} EditorColor;
typedef struct {
int x;
int y;
int width;
int height;
int source_type;
int source_index;
bool show_cursor;
EditorColor bg;
EditorColor fg;
} EditorView;
typedef struct {
Buffer buffers[LEMACS_MAX_BUFFERS];
int buffer_count;
int current_buffer;
Buffer aux_buffers[LEMACS_MAX_AUX_BUFFERS];
int aux_buffer_count;
int desired_col;
int scroll_line;
char font_query[256];
bool font_dirty;
EditorView views[LEMACS_MAX_VIEWS];
int view_count;
EditorColor bg_top;
EditorColor bg_bottom;
EditorColor text;
EditorColor cursor;
int cursor_shape;
int cursor_thickness;
bool should_quit;
} Editor;
bool editor_init(Editor *editor);
void editor_free(Editor *editor);
void editor_set_font_query(Editor *editor, const char *query);
const char *editor_font_query(const Editor *editor);
bool editor_consume_font_dirty(Editor *editor);
bool editor_set_theme_color(Editor *editor, const char *name, int r, int g, int b, int a);
bool editor_set_cursor_shape(Editor *editor, int shape);
void editor_set_cursor_thickness(Editor *editor, int thickness);
int editor_cursor_shape(const Editor *editor);
int editor_cursor_thickness(const Editor *editor);
int editor_aux_buffer_new(Editor *editor);
bool editor_aux_buffer_set_text(Editor *editor, int aux_index, const char *text);
Buffer *editor_aux_buffer_get(Editor *editor, int aux_index);
void editor_layout_reset(Editor *editor);
bool editor_layout_add_view(Editor *editor, int source_type, int source_index, int x, int y, int width, int height, bool show_cursor, EditorColor bg, EditorColor fg);
void editor_move_left(Editor *editor);
void editor_move_right(Editor *editor);
void editor_move_up(Editor *editor);
void editor_move_down(Editor *editor);
void editor_move_beginning_of_line(Editor *editor);
void editor_move_end_of_line(Editor *editor);
void editor_set_point(Editor *editor, size_t point);
char editor_char_at(const Editor *editor, size_t index);
bool editor_open_file(Editor *editor, const char *path);
bool editor_save_file(Editor *editor, const char *path);
Buffer *editor_current_buffer(Editor *editor);
const Buffer *editor_current_buffer_const(const Editor *editor);
int editor_buffer_count(const Editor *editor);
int editor_current_buffer_index(const Editor *editor);
bool editor_switch_buffer(Editor *editor, int index);
int editor_new_buffer(Editor *editor);
const char *editor_buffer_path_at(const Editor *editor, int index);
bool editor_buffer_modified_at(const Editor *editor, int index);
#endif
|