NeoMutt  2024-04-16-36-g75b6fb
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 <stddef.h>
42#include <stdint.h>
43#include "mutt/lib.h"
44#include "core/lib.h"
45#include "menu/lib.h"
46
47#define MUTT_UNBIND (1 << 0)
48#define MUTT_UNMACRO (1 << 1)
49
50typedef uint8_t GetChFlags;
51#define GETCH_NO_FLAGS 0
52#define GETCH_IGNORE_MACRO (1 << 0)
53
55typedef short keycode_t;
56
64struct Keymap
65{
66 char *macro;
67 char *desc;
68 short op;
69 short eq;
70 short len;
73};
74
75STAILQ_HEAD(KeymapList, Keymap);
76
81{
82 int ch;
83 int op;
84};
85
86ARRAY_HEAD(KeyEventArray, struct KeyEvent);
87
88extern struct KeyEventArray MacroEvents;
89
90extern struct KeymapList Keymaps[];
91extern struct Mapping KeyNames[];
92
93extern keycode_t AbortKey;
94
95extern const struct Mapping Menus[];
96
101{
102 const char *name;
103 int op;
104};
105
110{
111 int op;
112 const char *seq;
113};
114
119{
121 const char *key;
122 int op;
123};
124
133{
137
141};
142
143enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
144enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
145enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
146enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
147enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
148enum CommandResult mutt_parse_unmacro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
149
150enum CommandResult km_bind (char *s, enum MenuType menu, int op, char *macro, char *desc);
151int km_dokey (enum MenuType menu, GetChFlags flags);
152struct KeyEvent km_dokey_event (enum MenuType menu, GetChFlags flags);
153void km_error_key (enum MenuType menu);
154int km_expand_key (char *s, size_t len, struct Keymap *map);
155int km_expand_key_string (char *str, char *buf, size_t buflen);
156struct Keymap * km_find_func (enum MenuType menu, int func);
157const struct MenuFuncOp *km_get_table (enum MenuType mtype);
158void km_init (void);
159const char * km_keyname (int c);
160void init_extended_keys (void);
161int main_config_observer (struct NotifyCallback *nc);
163void mutt_init_abort_key (void);
164void mutt_keys_cleanup (void);
165void mw_what_key (void);
166
167// Private to libkey
168struct Keymap * alloc_keys (size_t len, keycode_t *keys);
169enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
170void generic_tokenize_push_string(char *s);
171int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len);
172enum CommandResult km_bindkey (const char *s, enum MenuType mtype, int op);
173struct Keymap * km_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos);
174const char * mutt_get_func (const struct MenuFuncOp *bindings, int op);
175void mutt_keymap_free (struct Keymap **ptr);
176size_t parsekeys (const char *str, keycode_t *d, size_t max);
177
178#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:363
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:472
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:559
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:344
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:645
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:172
void mw_what_key(void)
Display the value of a key -.
Definition: curs_lib.c:499
int main_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: init.c:265
uint8_t GetChFlags
Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.
Definition: lib.h:50
const char * km_keyname(int c)
Get the human name for a key.
Definition: lib.c:413
struct KeyEventArray MacroEvents
These are used for macros and exec/push commands.
Definition: get.c:48
const struct Mapping Menus[]
NotifyBinding
Key Binding notification types.
Definition: lib.h:133
@ NT_MACRO_ADD
Key macro has been added.
Definition: lib.h:138
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: lib.h:139
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: lib.h:140
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: lib.h:135
@ NT_BINDING_ADD
Key binding has been added.
Definition: lib.h:134
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: lib.h:136
void generic_tokenize_push_string(char *s)
Parse and queue a 'push' command.
Definition: lib.c:341
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:125
int km_dokey(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:463
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:278
struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition: lib.c:153
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:134
void km_init(void)
Initialise all the menu keybindings.
Definition: init.c:180
struct Keymap * km_find_func(enum MenuType menu, int func)
Find a function's mapping in a Menu.
Definition: lib.c:512
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:219
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: lib.c:460
const char * mutt_get_func(const struct MenuFuncOp *bindings, int op)
Get the name of a function.
Definition: lib.c:324
void km_error_key(enum MenuType menu)
Handle an unbound key sequence.
Definition: get.c:293
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:55
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: get.c:165
enum CommandResult km_bindkey(const char *s, enum MenuType mtype, int op)
Bind a key in a Menu to an operation.
Definition: parse.c:186
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: lib.c:528
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:63
int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition: lib.c:302
int km_expand_key_string(char *str, char *buf, size_t buflen)
Get a human-readable key string.
Definition: lib.c:489
struct KeyEvent km_dokey_event(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:345
void mutt_keys_cleanup(void)
Free the key maps.
Definition: init.c:230
void init_extended_keys(void)
Initialise map of ncurses extended keys.
Definition: init.c:137
enum CommandResult km_bind(char *s, enum MenuType menu, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: parse.c:160
struct KeymapList Keymaps[]
Array of Keymap keybindings, one for each Menu.
Definition: lib.c:128
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition: init.c:243
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:119
const char * key
Key string being bound (for new bind/macro)
Definition: lib.h:121
int op
Operation the key's bound to (for bind), e.g. OP_DELETE.
Definition: lib.h:122
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition: lib.h:120
An event such as a keypress.
Definition: lib.h:81
int op
Function opcode, e.g. OP_HELP.
Definition: lib.h:83
int ch
Raw key pressed.
Definition: lib.h:82
A keyboard mapping.
Definition: lib.h:65
keycode_t * keys
key sequence
Definition: lib.h:71
char * macro
Macro expansion (op == OP_MACRO)
Definition: lib.h:66
STAILQ_ENTRY(Keymap) entries
Linked list.
short eq
Number of leading keys equal to next entry.
Definition: lib.h:69
char * desc
Description of a macro for the help menu.
Definition: lib.h:67
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition: lib.h:70
short op
Operation to perform.
Definition: lib.h:68
Mapping between user-readable string and a constant.
Definition: mapping.h:33
Mapping between a function and an operation.
Definition: lib.h:101
const char * name
Name of the function.
Definition: lib.h:102
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:103
Mapping between an operation and a key sequence.
Definition: lib.h:110
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:111
const char * seq
Default key binding.
Definition: lib.h:112
Data passed to a notification function.
Definition: observer.h:34
MenuType
Types of GUI selections.
Definition: type.h:36