aboutsummaryrefslogtreecommitdiff
path: root/editor.h
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-08-24 10:04:28 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-08-24 10:05:37 +0200
commitbc0f09dce9fb9420ea1d5c10ebfacf50916b10af (patch)
treefdd6c4d7c791bcb540c11508b5007721f9c10c7f /editor.h
parent6f8cd49d22650ea3c91f0b96b2b576104fd0670c (diff)
downloadvis-bc0f09dce9fb9420ea1d5c10ebfacf50916b10af.tar.gz
vis-bc0f09dce9fb9420ea1d5c10ebfacf50916b10af.tar.xz
Add work in progress editor frontend
Diffstat (limited to 'editor.h')
-rw-r--r--editor.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/editor.h b/editor.h
new file mode 100644
index 0000000..d36e503
--- /dev/null
+++ b/editor.h
@@ -0,0 +1,104 @@
+#include <curses.h>
+#include <regex.h>
+
+typedef struct {
+ short fg, bg; /* fore and background color */
+ int attr; /* curses attributes */
+} Color;
+
+typedef struct {
+ char *rule; /* regex to search for */
+ int cflags; /* compilation flags (REG_*) used when compiling */
+ Color color; /* settings to apply in case of a match */
+ regex_t regex; /* compiled form of the above rule */
+} SyntaxRule;
+
+#define SYNTAX_REGEX_RULES 10
+
+typedef struct { /* a syntax definition */
+ char *name; /* syntax name */
+ char *file; /* apply to files matching this regex */
+ regex_t file_regex; /* compiled file name regex */
+ SyntaxRule rules[SYNTAX_REGEX_RULES]; /* all rules for this file type */
+} Syntax;
+
+typedef struct Editor Editor;
+typedef size_t Filepos;
+
+typedef struct {
+ Filepos start, end; /* range in bytes from start of file */
+} Filerange;
+
+typedef void (*editor_statusbar_t)(WINDOW *win, bool active, const char *filename, int line, int col);
+
+/* initialize a new editor with the available screen size */
+Editor *editor_new(int width, int height, editor_statusbar_t);
+/* loads the given file and displays it in a new window. passing NULL as
+ * filename will open a new empty buffer */
+bool editor_load(Editor*, const char *filename);
+size_t editor_insert(Editor*, const char *c, size_t len);
+size_t editor_replace(Editor *ed, const char *c, size_t len);
+size_t editor_backspace(Editor*);
+size_t editor_delete(Editor*);
+bool editor_resize(Editor*, int width, int height);
+void editor_snapshot(Editor*);
+void editor_undo(Editor*);
+void editor_redo(Editor*);
+void editor_draw(Editor *editor);
+/* flush all changes made to the ncurses windows to the screen */
+void editor_update(Editor *editor);
+void editor_free(Editor*);
+
+/* cursor movements, also updates selection if one is active, returns new cursor postion */
+size_t editor_file_begin(Editor *ed);
+size_t editor_file_end(Editor *ed);
+size_t editor_page_down(Editor *ed);
+size_t editor_page_up(Editor *ed);
+size_t editor_char_next(Editor*);
+size_t editor_char_prev(Editor*);
+size_t editor_line_goto(Editor*, size_t lineno);
+size_t editor_line_down(Editor*);
+size_t editor_line_up(Editor*);
+size_t editor_line_begin(Editor*);
+size_t editor_line_start(Editor*);
+size_t editor_line_finish(Editor*);
+size_t editor_line_end(Editor*);
+size_t editor_word_end_next(Editor*);
+size_t editor_word_end_prev(Editor *ed);
+size_t editor_word_start_next(Editor*);
+size_t editor_word_start_prev(Editor *ed);
+size_t editor_sentence_next(Editor *ed);
+size_t editor_sentence_prev(Editor *ed);
+size_t editor_paragraph_next(Editor *ed);
+size_t editor_paragraph_prev(Editor *ed);
+size_t editor_bracket_match(Editor *ed);
+
+// mark handling
+typedef int Mark;
+void editor_mark_set(Editor*, Mark, size_t pos);
+void editor_mark_goto(Editor*, Mark);
+void editor_mark_clear(Editor*, Mark);
+
+// TODO comment
+bool editor_syntax_load(Editor*, Syntax *syntaxes, Color *colors);
+void editor_syntax_unload(Editor*);
+
+size_t editor_cursor_get(Editor*);
+// TODO void return type?
+size_t editor_selection_start(Editor*);
+size_t editor_selection_end(Editor*);
+Filerange editor_selection_get(Editor*);
+void editor_selection_clear(Editor*);
+
+void editor_search(Editor *ed, const char *regex, int direction);
+
+void editor_window_split(Editor *ed, const char *filename);
+void editor_window_vsplit(Editor *ed, const char *filename);
+void editor_window_next(Editor *ed);
+void editor_window_prev(Editor *ed);
+
+/* library initialization code, should be run at startup */
+void editor_init(void);
+// TODO: comment
+short editor_color_reserve(short fg, short bg);
+short editor_color_get(short fg, short bg);