NeoMutt  2025-01-09-41-g086358
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h
Go to the documentation of this file.
1
37#ifndef MUTT_KEY_LIB_H
38#define MUTT_KEY_LIB_H
39
40#include "config.h"
41#include <stdbool.h>
42#include <stddef.h>
43#include <stdint.h>
44#include "mutt/lib.h"
45#include "core/lib.h"
46#include "menu/lib.h"
47
48#define MUTT_UNBIND (1 << 0)
49#define MUTT_UNMACRO (1 << 1)
50
51typedef uint8_t GetChFlags;
52#define GETCH_NO_FLAGS 0
53#define GETCH_IGNORE_MACRO (1 << 0)
54
56typedef short keycode_t;
57
65struct Keymap
66{
67 char *macro;
68 char *desc;
69 short op;
70 short eq;
71 short len;
74};
75
76STAILQ_HEAD(KeymapList, Keymap);
77
82{
83 int ch;
84 int op;
85};
86
87ARRAY_HEAD(KeyEventArray, struct KeyEvent);
88
89extern struct KeyEventArray MacroEvents;
90
91extern struct KeymapList Keymaps[];
92extern struct Mapping KeyNames[];
93
94extern keycode_t AbortKey;
95
96extern const struct Mapping Menus[];
97
102{
103 const char *name;
104 int op;
105};
106
111{
112 int op;
113 const char *seq;
114};
115
120{
122 const char *key;
123 int op;
124};
125
134{
138
142};
143
144enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
145enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
146enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
147enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
148enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
149enum CommandResult mutt_parse_unmacro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
150
151enum CommandResult km_bind (char *s, enum MenuType menu, int op, char *macro, char *desc);
152int km_dokey (enum MenuType menu, GetChFlags flags);
153struct KeyEvent km_dokey_event (enum MenuType menu, GetChFlags flags);
154void km_error_key (enum MenuType menu);
155bool km_expand_key (struct Keymap *map, struct Buffer *buf);
156void km_expand_key_string (char *str, struct Buffer *buf);
157struct Keymap * km_find_func (enum MenuType menu, int func);
158const struct MenuFuncOp *km_get_table (enum MenuType mtype);
159void km_init (void);
160void km_keyname (int c, struct Buffer *buf);
161void init_extended_keys (void);
162int main_config_observer (struct NotifyCallback *nc);
164void mutt_init_abort_key (void);
165void mutt_keys_cleanup (void);
166void mw_what_key (void);
167
168// Private to libkey
169struct Keymap * alloc_keys (size_t len, keycode_t *keys);
170enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
171void generic_tokenize_push_string(char *s);
172int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len);
173enum CommandResult km_bindkey (const char *s, enum MenuType mtype, int op);
174struct Keymap * km_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos);
175const char * mutt_get_func (const struct MenuFuncOp *bindings, int op);
176void mutt_keymap_free (struct Keymap **ptr);
177size_t parsekeys (const char *str, keycode_t *d, size_t max);
178
179#endif /* MUTT_KEY_LIB_H */
#define ARRAY_HEAD(name, type)
Define a named struct for arrays of elements of a certain type.
Definition: array.h:47
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
Convenience wrapper for the core headers.
enum CommandResult mutt_parse_bind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'bind' command - Implements Command::parse() -.
Definition: parse.c:368
enum CommandResult mutt_parse_unbind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unbind' command - Implements Command::parse() -.
Definition: parse.c:481
enum CommandResult mutt_parse_macro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'macro' command - Implements Command::parse() -.
Definition: parse.c:569
enum CommandResult mutt_parse_push(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'push' command - Implements Command::parse() -.
Definition: parse.c:349
enum CommandResult mutt_parse_exec(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'exec' command - Implements Command::parse() -.
Definition: parse.c:659
enum CommandResult dump_bind_macro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse 'bind' and 'macro' commands - Implements Command::parse() -.
Definition: dump.c:179
void mw_what_key(void)
Display the value of a key -.
Definition: curs_lib.c:500
int main_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: init.c:259
uint8_t GetChFlags
Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.
Definition: lib.h:51
struct KeyEventArray MacroEvents
These are used for macros and exec/push commands.
Definition: get.c:49
const struct Mapping Menus[]
NotifyBinding
Key Binding notification types.
Definition: lib.h:134
@ NT_MACRO_ADD
Key macro has been added.
Definition: lib.h:139
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: lib.h:140
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: lib.h:141
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: lib.h:136
@ NT_BINDING_ADD
Key binding has been added.
Definition: lib.h:135
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: lib.h:137
void generic_tokenize_push_string(char *s)
Parse and queue a 'push' command.
Definition: lib.c:337
enum CommandResult mutt_parse_unmacro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
keycode_t AbortKey
key to abort edits etc, normally Ctrl-G
Definition: lib.c:121
int km_dokey(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:466
struct Keymap * km_compare_keys(struct Keymap *k1, struct Keymap *k2, size_t *pos)
Compare two keymaps' keyscodes and return the bigger one.
Definition: lib.c:274
struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition: lib.c:149
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:130
void km_init(void)
Initialise all the menu keybindings.
Definition: init.c:177
struct Keymap * km_find_func(enum MenuType menu, int func)
Find a function's mapping in a Menu.
Definition: lib.c:483
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:215
const char * mutt_get_func(const struct MenuFuncOp *bindings, int op)
Get the name of a function.
Definition: lib.c:320
void km_error_key(enum MenuType menu)
Handle an unbound key sequence.
Definition: get.c:294
void km_keyname(int c, struct Buffer *buf)
Get the human name for a key.
Definition: lib.c:407
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:56
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: get.c:166
enum CommandResult km_bindkey(const char *s, enum MenuType mtype, int op)
Bind a key in a Menu to an operation.
Definition: parse.c:191
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: lib.c:499
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:59
int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition: lib.c:298
struct KeyEvent km_dokey_event(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:348
void mutt_keys_cleanup(void)
Free the key maps.
Definition: init.c:224
void init_extended_keys(void)
Initialise map of ncurses extended keys.
Definition: init.c:134
bool km_expand_key(struct Keymap *map, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition: lib.c:451
enum CommandResult km_bind(char *s, enum MenuType menu, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: parse.c:165
struct KeymapList Keymaps[]
Array of Keymap keybindings, one for each Menu.
Definition: lib.c:124
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition: init.c:237
void km_expand_key_string(char *str, struct Buffer *buf)
Get a human-readable key string.
Definition: lib.c:469
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
#define STAILQ_HEAD(name, type)
Definition: queue.h:312
String manipulation buffer.
Definition: buffer.h:36
A key binding Event.
Definition: lib.h:120
const char * key
Key string being bound (for new bind/macro)
Definition: lib.h:122
int op
Operation the key's bound to (for bind), e.g. OP_DELETE.
Definition: lib.h:123
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition: lib.h:121
An event such as a keypress.
Definition: lib.h:82
int op
Function opcode, e.g. OP_HELP.
Definition: lib.h:84
int ch
Raw key pressed.
Definition: lib.h:83
A keyboard mapping.
Definition: lib.h:66
keycode_t * keys
key sequence
Definition: lib.h:72
char * macro
Macro expansion (op == OP_MACRO)
Definition: lib.h:67
STAILQ_ENTRY(Keymap) entries
Linked list.
short eq
Number of leading keys equal to next entry.
Definition: lib.h:70
char * desc
Description of a macro for the help menu.
Definition: lib.h:68
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition: lib.h:71
short op
Operation to perform.
Definition: lib.h:69
Mapping between user-readable string and a constant.
Definition: mapping.h:33
Mapping between a function and an operation.
Definition: lib.h:102
const char * name
Name of the function.
Definition: lib.h:103
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:104
Mapping between an operation and a key sequence.
Definition: lib.h:111
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:112
const char * seq
Default key binding.
Definition: lib.h:113
Data passed to a notification function.
Definition: observer.h:34
MenuType
Types of GUI selections.
Definition: type.h:36