src/mode.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef MODE_H | ||
| 2 | #define MODE_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include "command/run.h" | ||
| 6 | #include "terminal/key.h" | ||
| 7 | #include "util/hashmap.h" | ||
| 8 | #include "util/intmap.h" | ||
| 9 | #include "util/macros.h" | ||
| 10 | #include "util/ptr-array.h" | ||
| 11 | #include "util/string-view.h" | ||
| 12 | #include "util/string.h" | ||
| 13 | |||
| 14 | typedef enum { | ||
| 15 | MHF_NO_TEXT_INSERTION = 1 << 0, // Don't insert text for keys in the Unicode range | ||
| 16 | MHF_NO_TEXT_INSERTION_RECURSIVE = 1 << 1, // As above, but also overriding all fallback modes | ||
| 17 | } ModeHandlerFlags; | ||
| 18 | |||
| 19 | typedef struct { | ||
| 20 | const char *name; | ||
| 21 | const CommandSet *cmds; | ||
| 22 | IntMap key_bindings; | ||
| 23 | ModeHandlerFlags flags; | ||
| 24 | PointerArray fallthrough_modes; | ||
| 25 | } ModeHandler; | ||
| 26 | |||
| 27 | 5 | static inline ModeHandler *get_mode_handler(HashMap *modes, const char *name) | |
| 28 | { | ||
| 29 | 5 | return hashmap_get(modes, name); | |
| 30 | } | ||
| 31 | |||
| 32 | struct EditorState; | ||
| 33 | bool handle_input(struct EditorState *e, KeyCode key) NONNULL_ARGS; | ||
| 34 | ModeHandler *new_mode(HashMap *modes, char *name, const CommandSet *cmds) NONNULL_ARGS_AND_RETURN; | ||
| 35 | void string_append_def_mode(String *buf, const ModeHandler *mode) NONNULL_ARGS; | ||
| 36 | void collect_modes(const HashMap *modes, PointerArray *a, StringView prefix) NONNULL_ARGS; | ||
| 37 | |||
| 38 | #endif | ||
| 39 |