NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h
Go to the documentation of this file.
1
38#ifndef MUTT_KEY_LIB_H
39#define MUTT_KEY_LIB_H
40
41#include "config.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);
155int km_expand_key (char *s, size_t len, struct Keymap *map);
156int km_expand_key_string (char *str, char *buf, size_t buflen);
157struct Keymap * km_find_func (enum MenuType menu, int func);
158const struct MenuFuncOp *km_get_table (enum MenuType mtype);
159void km_init (void);
160const char * km_keyname (int c);
161void init_extended_keys (void);
162int main_config_observer (struct NotifyCallback *nc);
165void mutt_init_abort_key (void);
166void mutt_keys_cleanup (void);
167void mw_what_key (void);
168
169// Private to libkey
170struct Keymap * alloc_keys (size_t len, keycode_t *keys);
171enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
172void generic_tokenize_push_string(char *s);
173int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len);
174enum CommandResult km_bindkey (const char *s, enum MenuType mtype, int op);
175struct Keymap * km_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos);
176const char * mutt_get_func (const struct MenuFuncOp *bindings, int op);
177void mutt_keymap_free (struct Keymap **ptr);
178size_t parsekeys (const char *str, keycode_t *d, size_t max);
179
180#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:46
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:171
void mw_what_key(void)
Display the value of a key -.
Definition: curs_lib.c:510
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:51
const char * km_keyname(int c)
Get the human name for a key.
Definition: lib.c:414
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: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:342
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:126
int km_dokey(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:475
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:279
struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition: lib.c:154
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:135
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:513
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:220
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: lib.c:461
const char * mutt_get_func(const struct MenuFuncOp *bindings, int op)
Get the name of a function.
Definition: lib.c:325
void km_error_key(enum MenuType menu)
Handle an unbound key sequence.
Definition: get.c:305
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:56
void mutt_flush_unget_to_endcond(void)
Clear entries from UngetKeyEvents.
Definition: get.c:177
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:529
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:64
int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition: lib.c:303
int km_expand_key_string(char *str, char *buf, size_t buflen)
Get a human-readable key string.
Definition: lib.c:490
struct KeyEvent km_dokey_event(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:357
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:129
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:34
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:32
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