summaryrefslogtreecommitdiff
path: root/src/core/buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/buffer.h')
-rw-r--r--src/core/buffer.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/core/buffer.h b/src/core/buffer.h
new file mode 100644
index 0000000..8fac8ab
--- /dev/null
+++ b/src/core/buffer.h
@@ -0,0 +1,38 @@
+#ifndef LEMACS_BUFFER_H
+#define LEMACS_BUFFER_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+typedef struct {
+ char *data;
+ size_t capacity;
+ size_t gap_start;
+ size_t gap_end;
+ char path[1024];
+ bool modified;
+} Buffer;
+
+bool buffer_init(Buffer *buffer);
+void buffer_free(Buffer *buffer);
+
+size_t buffer_length(const Buffer *buffer);
+size_t buffer_point(const Buffer *buffer);
+void buffer_set_point(Buffer *buffer, size_t point);
+
+bool buffer_insert_char(Buffer *buffer, char c);
+bool buffer_insert_cstr(Buffer *buffer, const char *text);
+bool buffer_backspace(Buffer *buffer);
+bool buffer_delete_forward(Buffer *buffer);
+
+char buffer_char_at(const Buffer *buffer, size_t index);
+
+bool buffer_load_file(Buffer *buffer, const char *path);
+bool buffer_save_file(Buffer *buffer, const char *path);
+const char *buffer_path(const Buffer *buffer);
+bool buffer_modified(const Buffer *buffer);
+
+void buffer_index_to_line_col(const Buffer *buffer, size_t index, int *line, int *col);
+size_t buffer_line_col_to_index(const Buffer *buffer, int target_line, int target_col);
+
+#endif