aboutsummaryrefslogtreecommitdiff
path: root/examples/dte/editor.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dte/editor.h')
-rw-r--r--examples/dte/editor.h121
1 files changed, 0 insertions, 121 deletions
diff --git a/examples/dte/editor.h b/examples/dte/editor.h
deleted file mode 100644
index 86a8103..0000000
--- a/examples/dte/editor.h
+++ /dev/null
@@ -1,121 +0,0 @@
1#ifndef EDITOR_H
2#define EDITOR_H
3
4#include <stdbool.h>
5#include <stddef.h>
6#include "buffer.h"
7#include "cmdline.h"
8#include "command/macro.h"
9#include "command/run.h"
10#include "commands.h"
11#include "copy.h"
12#include "file-history.h"
13#include "frame.h"
14#include "history.h"
15#include "msg.h"
16#include "options.h"
17#include "regexp.h"
18#include "search.h"
19#include "syntax/color.h"
20#include "tag.h"
21#include "terminal/cursor.h"
22#include "terminal/terminal.h"
23#include "util/debug.h"
24#include "util/hashmap.h"
25#include "util/intmap.h"
26#include "util/macros.h"
27#include "util/ptr-array.h"
28#include "util/string-view.h"
29#include "view.h"
30
31typedef enum {
32 EDITOR_INITIALIZING = -2,
33 EDITOR_RUNNING = -1,
34 // Values 0-125 are exit codes
35 EDITOR_EXIT_OK = 0,
36 EDITOR_EXIT_MAX = 125,
37} EditorStatus;
38
39typedef enum {
40 INPUT_NORMAL,
41 INPUT_COMMAND,
42 INPUT_SEARCH,
43} InputMode;
44
45typedef struct {
46 const CommandSet *cmds;
47 IntMap key_bindings;
48} ModeHandler;
49
50typedef struct EditorState {
51 EditorStatus status;
52 InputMode input_mode;
53 CommandLine cmdline;
54 SearchState search;
55 GlobalOptions options;
56 Terminal terminal;
57 StringView home_dir;
58 const char *user_config_dir;
59 bool child_controls_terminal;
60 bool everything_changed;
61 bool cursor_style_changed;
62 bool session_leader;
63 size_t cmdline_x;
64 ModeHandler modes[3];
65 Clipboard clipboard;
66 TagFile tagfile;
67 HashMap aliases;
68 HashMap compilers;
69 HashMap syntaxes;
70 ColorScheme colors;
71 CommandMacroState macro;
72 TermCursorStyle cursor_styles[NR_CURSOR_MODES];
73 Frame *root_frame;
74 struct Window *window;
75 View *view;
76 Buffer *buffer;
77 PointerArray buffers;
78 PointerArray filetypes;
79 PointerArray file_options;
80 PointerArray bookmarks;
81 MessageArray messages;
82 FileHistory file_history;
83 History search_history;
84 History command_history;
85 RegexpWordBoundaryTokens regexp_word_tokens;
86 const char *version;
87} EditorState;
88
89static inline void mark_everything_changed(EditorState *e)
90{
91 e->everything_changed = true;
92}
93
94static inline void set_input_mode(EditorState *e, InputMode mode)
95{
96 e->cursor_style_changed = true;
97 e->input_mode = mode;
98}
99
100static inline CommandRunner cmdrunner_for_mode(EditorState *e, InputMode mode, bool allow_recording)
101{
102 BUG_ON(mode >= ARRAYLEN(e->modes));
103 CommandRunner runner = {
104 .cmds = e->modes[mode].cmds,
105 .lookup_alias = (mode == INPUT_NORMAL) ? find_normal_alias : NULL,
106 .home_dir = &e->home_dir,
107 .allow_recording = allow_recording,
108 .userdata = e,
109 };
110 return runner;
111}
112
113EditorState *init_editor_state(void) RETURNS_NONNULL;
114void free_editor_state(EditorState *e) NONNULL_ARGS;
115void any_key(Terminal *term, unsigned int esc_timeout) NONNULL_ARGS;
116int main_loop(EditorState *e) NONNULL_ARGS WARN_UNUSED_RESULT;
117void ui_start(EditorState *e) NONNULL_ARGS;
118void ui_end(EditorState *e) NONNULL_ARGS;
119void ui_resize(EditorState *e) NONNULL_ARGS;
120
121#endif