NeoMutt  2025-01-09-117-gace867
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};
75STAILQ_HEAD(KeymapList, Keymap);
76
81{
82 int ch;
83 int op;
84};
85ARRAY_HEAD(KeyEventArray, struct KeyEvent);
86
94{
95 const char *a[3];
96};
97ARRAY_HEAD(BindingInfoArray, struct BindingInfo);
98
99extern struct KeyEventArray MacroEvents;
100
101extern struct KeymapList Keymaps[];
102extern struct Mapping KeyNames[];
103
104extern keycode_t AbortKey;
105
106extern const struct Mapping Menus[];
107
112{
113 const char *name;
114 int op;
115};
116
121{
122 int op;
123 const char *seq;
124};
125
130{
132 const char *key;
133 int op;
134};
135
144{
148
152};
153
154// key/init.c
155void km_init (void);
156void init_extended_keys (void);
158void mutt_init_abort_key (void);
159void mutt_keys_cleanup (void);
160
161// key/parse.c
162enum CommandResult km_bind (char *s, enum MenuType menu, int op, char *macro, char *desc);
163enum CommandResult parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
164enum CommandResult parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
165enum CommandResult parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
166enum CommandResult parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
167enum CommandResult parse_unbind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
168
169// key/get.c
170int km_dokey (enum MenuType menu, GetChFlags flags);
171struct KeyEvent km_dokey_event (enum MenuType menu, GetChFlags flags);
172void km_error_key (enum MenuType menu);
174
175// key/lib.c
176bool km_expand_key (struct Keymap *map, struct Buffer *buf);
177void km_expand_key_string(char *str, struct Buffer *buf);
178struct Keymap * km_find_func (enum MenuType menu, int func);
179const struct MenuFuncOp *km_get_table (enum MenuType mtype);
180void km_keyname (int c, struct Buffer *buf);
181
182// Private to libkey
183struct Keymap * alloc_keys (size_t len, keycode_t *keys);
184enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
185void generic_tokenize_push_string(char *s);
186int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len);
187enum CommandResult km_bindkey (const char *s, enum MenuType mtype, int op);
188struct Keymap * km_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos);
189const char * mutt_get_func (const struct MenuFuncOp *bindings, int op);
190void mutt_keymap_free (struct Keymap **ptr);
191int parse_fkey (char *s);
192size_t parsekeys (const char *str, keycode_t *d, size_t max);
193
194int measure_column(struct BindingInfoArray *bia, int col);
195void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro);
196int gather_unbound(const struct MenuFuncOp *funcs, const struct KeymapList *km_menu, const struct KeymapList *km_aux, struct BindingInfoArray *bia_unbound);
197int binding_sort(const void *a, const void *b, void *sdata);
198
199#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.
enum CommandResult 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 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 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 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:174
enum CommandResult 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
int main_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: init.c:250
int binding_sort(const void *a, const void *b, void *sdata)
Compare two BindingInfo by their keybinding - Implements sort_t -.
Definition: lib.c:405
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:144
@ NT_MACRO_ADD
Key macro has been added.
Definition: lib.h:149
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: lib.h:150
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: lib.h:151
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: lib.h:146
@ NT_BINDING_ADD
Key binding has been added.
Definition: lib.h:145
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: lib.h:147
int parse_fkey(char *s)
Parse a function key string.
Definition: lib.c:165
void generic_tokenize_push_string(char *s)
Parse and queue a 'push' command.
Definition: get.c:348
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:537
int measure_column(struct BindingInfoArray *bia, int col)
Measure one column of a table.
Definition: lib.c:419
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 gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro)
Gather info about one menu.
Definition: lib.c:624
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:176
struct Keymap * km_find_func(enum MenuType menu, int func)
Find a function's mapping in a Menu.
Definition: lib.c:541
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:465
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:557
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
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:441
struct KeyEvent km_dokey_event(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:419
void mutt_keys_cleanup(void)
Free the key maps.
Definition: init.c:215
void init_extended_keys(void)
Initialise map of ncurses extended keys.
Definition: init.c:133
bool km_expand_key(struct Keymap *map, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition: lib.c:509
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:228
void km_expand_key_string(char *str, struct Buffer *buf)
Get a human-readable key string.
Definition: lib.c:527
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:94
const char * a[3]
Array of info.
Definition: lib.h:95
String manipulation buffer.
Definition: buffer.h:36
A key binding Event.
Definition: lib.h:130
const char * key
Key string being bound (for new bind/macro)
Definition: lib.h:132
int op
Operation the key's bound to (for bind), e.g. OP_DELETE.
Definition: lib.h:133
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition: lib.h:131
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: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:112
const char * name
Name of the function.
Definition: lib.h:113
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:114
Mapping between an operation and a key sequence.
Definition: lib.h:121
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:122
const char * seq
Default key binding.
Definition: lib.h:123
Data passed to a notification function.
Definition: observer.h:34
MenuType
Types of GUI selections.
Definition: type.h:36