NeoMutt  2025-12-11-58-g09398d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h
Go to the documentation of this file.
1
22
37
38#ifndef MUTT_KEY_LIB_H
39#define MUTT_KEY_LIB_H
40
41#include "config.h"
42#include <stdbool.h>
43#include <stddef.h>
44#include <stdint.h>
45#include "mutt/lib.h"
46#include "core/lib.h"
47#include "menu/lib.h"
48
49#define MUTT_UNBIND (1 << 0)
50#define MUTT_UNMACRO (1 << 1)
51
52typedef uint8_t GetChFlags;
53#define GETCH_NO_FLAGS 0
54#define GETCH_IGNORE_MACRO (1 << 0)
55
57typedef short keycode_t;
58
66struct Keymap
67{
68 char *macro;
69 char *desc;
70 short op;
71 short eq;
72 short len;
75};
76STAILQ_HEAD(KeymapList, Keymap);
77
82{
83 int ch;
84 int op;
85};
86ARRAY_HEAD(KeyEventArray, struct KeyEvent);
87
95{
96 const char *a[3];
97};
98ARRAY_HEAD(BindingInfoArray, struct BindingInfo);
99
100extern struct KeyEventArray MacroEvents;
101
102extern struct KeymapList Keymaps[];
103extern struct Mapping KeyNames[];
104
105extern keycode_t AbortKey;
106
107extern const struct Mapping Menus[];
108
109typedef uint8_t MenuFuncFlags;
110#define MFF_NO_FLAGS 0
111#define MFF_DEPRECATED (1 << 1)
112
117{
118 const char *name;
119 int op;
121};
122
127{
128 int op;
129 const char *seq;
130};
131
136{
138 const char *key;
139 int op;
140};
141
159
160// key/extended
161#ifdef HAVE_USE_EXTENDED_NAMES
162void init_extended_keys(void);
163#else
164static inline void init_extended_keys(void) {}
165#endif
166
167// key/commands.c
168enum CommandResult km_bind (const char *s, enum MenuType mtype, int op, char *macro, char *desc, struct Buffer *err);
169enum CommandResult parse_bind (const struct Command *cmd, struct Buffer *line, struct Buffer *err);
170enum CommandResult parse_exec (const struct Command *cmd, struct Buffer *line, struct Buffer *err);
171enum CommandResult parse_macro (const struct Command *cmd, struct Buffer *line, struct Buffer *err);
172enum CommandResult parse_push (const struct Command *cmd, struct Buffer *line, struct Buffer *err);
173enum CommandResult parse_unbind(const struct Command *cmd, struct Buffer *line, struct Buffer *err);
174
175// key/init.c
176void km_init (void);
178void mutt_init_abort_key (void);
179void mutt_keys_cleanup (void);
180
181// key/get.c
182int km_dokey (enum MenuType menu, GetChFlags flags);
183struct KeyEvent km_dokey_event (enum MenuType menu, GetChFlags flags);
184void km_error_key (enum MenuType menu);
186
187// key/lib.c
188bool km_expand_key (struct Keymap *map, struct Buffer *buf);
189struct Keymap * km_find_func (enum MenuType menu, int func);
190const struct MenuFuncOp *km_get_table (enum MenuType mtype);
191void km_keyname (int c, struct Buffer *buf);
192
193// Private to libkey
194struct Keymap * alloc_keys (size_t len, keycode_t *keys);
195enum CommandResult parse_bind_macro (const struct Command *cmd, struct Buffer *line, struct Buffer *err);
196void generic_tokenize_push_string(char *s);
197int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len);
198struct Keymap * km_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos);
199const char * mutt_get_func (const struct MenuFuncOp *bindings, int op);
200void mutt_keymap_free (struct Keymap **ptr);
201int parse_fkey (char *s);
202size_t parsekeys (const char *str, keycode_t *d, size_t max);
203void km_expand_key_string (char *str, struct Buffer *buf);
204
205struct KeyEvent mutt_getch(GetChFlags flags);
206void mutt_flushinp(void);
207void mutt_push_macro_event(int ch, int op);
208void mutt_unget_ch(int ch);
209void mutt_unget_op(int op);
210void mutt_unget_string(const char *s);
211
212int measure_column(struct BindingInfoArray *bia, int col);
213void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro);
214int gather_unbound(const struct MenuFuncOp *funcs, const struct KeymapList *km_menu, const struct KeymapList *km_aux, struct BindingInfoArray *bia_unbound);
215int binding_sort(const void *a, const void *b, void *sdata);
216
217#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:35
Convenience wrapper for the core headers.
struct KeyEvent km_dokey_event(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:419
struct KeyEventArray MacroEvents
These are used for macros and exec/push commands.
Definition get.c:49
struct KeyEvent mutt_getch(GetChFlags flags)
Read a character from the input buffer.
Definition get.c:210
enum CommandResult parse_push(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'push' command - Implements Command::parse() -.
Definition commands.c:310
enum CommandResult parse_bind_macro(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse 'bind' and 'macro' commands - Implements Command::parse() -.
Definition dump.c:175
enum CommandResult parse_macro(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'macro' command - Implements Command::parse() -.
Definition commands.c:572
enum CommandResult parse_exec(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'exec' command - Implements Command::parse() -.
Definition commands.c:673
enum CommandResult parse_bind(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'bind' command - Implements Command::parse() -.
Definition commands.c:345
enum CommandResult parse_unbind(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'unbind' command - Implements Command::parse() -.
Definition commands.c:472
int binding_sort(const void *a, const void *b, void *sdata)
Compare two BindingInfo by their keybinding - Implements sort_t -.
Definition dump.c:263
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition lib.c:122
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition lib.c:125
struct Mapping KeyNames[]
Key name lookup table.
Definition lib.c:58
int main_config_observer(struct NotifyCallback *nc)
uint8_t GetChFlags
Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.
Definition lib.h:52
const struct Mapping Menus[]
enum CommandResult km_bind(const char *s, enum MenuType mtype, int op, char *macro, char *desc, struct Buffer *err)
Set up a key binding.
Definition commands.c:56
NotifyBinding
Key Binding notification types.
Definition lib.h:150
@ NT_MACRO_ADD
Key macro has been added.
Definition lib.h:155
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition lib.h:156
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition lib.h:157
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition lib.h:152
@ NT_BINDING_ADD
Key binding has been added.
Definition lib.h:151
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition lib.h:153
int parse_fkey(char *s)
Parse a function key string.
Definition lib.c:166
void generic_tokenize_push_string(char *s)
Parse and queue a 'push' command.
Definition get.c:348
int km_dokey(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:537
int measure_column(struct BindingInfoArray *bia, int col)
Measure one column of a table.
Definition dump.c:414
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:275
struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition lib.c:150
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition get.c:58
void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro)
Gather info about one menu.
Definition dump.c:358
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition lib.c:131
void km_init(void)
Initialise all the menu keybindings.
Definition init.c:104
struct Keymap * km_find_func(enum MenuType menu, int func)
Find a function's mapping in a Menu.
Definition lib.c:469
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition get.c:137
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition get.c:155
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition lib.c:216
void mutt_unget_op(int op)
Return an operation to the input buffer.
Definition get.c:126
const char * mutt_get_func(const struct MenuFuncOp *bindings, int op)
Get the name of a function.
Definition lib.c:321
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:393
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition lib.h:57
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition get.c:166
uint8_t MenuFuncFlags
Flags, e.g. MFF_DEPRECATED.
Definition lib.h:109
static void init_extended_keys(void)
Definition lib.h:164
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition lib.c:485
int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition lib.c:299
int gather_unbound(const struct MenuFuncOp *funcs, const struct KeymapList *km_menu, const struct KeymapList *km_aux, struct BindingInfoArray *bia_unbound)
Gather info about unbound functions for one menu.
Definition lib.c:363
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition get.c:115
void mutt_keys_cleanup(void)
Free the key maps.
Definition init.c:165
bool km_expand_key(struct Keymap *map, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition lib.c:437
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition init.c:181
void km_expand_key_string(char *str, struct Buffer *buf)
Get a human-readable key string.
Definition lib.c:455
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
#define STAILQ_HEAD(name, type)
Definition queue.h:312
Info about one keybinding.
Definition lib.h:95
const char * a[3]
Array of info.
Definition lib.h:96
String manipulation buffer.
Definition buffer.h:36
A key binding Event.
Definition lib.h:136
const char * key
Key string being bound (for new bind/macro)
Definition lib.h:138
int op
Operation the key's bound to (for bind), e.g. OP_DELETE.
Definition lib.h:139
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition lib.h:137
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:67
keycode_t * keys
Key sequence.
Definition lib.h:73
char * macro
Macro expansion (op == OP_MACRO)
Definition lib.h:68
STAILQ_ENTRY(Keymap) entries
Linked list.
short eq
Number of leading keys equal to next entry.
Definition lib.h:71
char * desc
Description of a macro for the help menu.
Definition lib.h:69
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition lib.h:72
short op
Operation to perform.
Definition lib.h:70
Mapping between user-readable string and a constant.
Definition mapping.h:33
Mapping between a function and an operation.
Definition lib.h:117
const char * name
Name of the function.
Definition lib.h:118
MenuFuncFlags flags
Flags, e.g. MFF_DEPRECATED.
Definition lib.h:120
int op
Operation, e.g. OP_DELETE.
Definition lib.h:119
Mapping between an operation and a key sequence.
Definition lib.h:127
int op
Operation, e.g. OP_DELETE.
Definition lib.h:128
const char * seq
Default key binding.
Definition lib.h:129
Data passed to a notification function.
Definition observer.h:34
MenuType
Types of GUI selections.
Definition type.h:35