NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
init.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <stdio.h>
32#include <string.h>
33#include <strings.h>
34#include "mutt/lib.h"
35#include "config/lib.h"
36#include "core/lib.h"
37#include "gui/lib.h"
38#include "key/lib.h"
39#include "menu/lib.h"
40#include "ncrypt/lib.h"
41
42extern const struct MenuOpSeq AliasDefaultBindings[];
43extern const struct MenuOpSeq AttachmentDefaultBindings[];
44#ifdef USE_AUTOCRYPT
45extern const struct MenuOpSeq AutocryptDefaultBindings[];
46#endif
47extern const struct MenuOpSeq BrowserDefaultBindings[];
48extern const struct MenuOpSeq ComposeDefaultBindings[];
49extern const struct MenuOpSeq EditorDefaultBindings[];
50extern const struct MenuOpSeq IndexDefaultBindings[];
51extern const struct MenuOpSeq PagerDefaultBindings[];
52extern const struct MenuOpSeq PgpDefaultBindings[];
53extern const struct MenuOpSeq PostponedDefaultBindings[];
54extern const struct MenuOpSeq QueryDefaultBindings[];
55extern const struct MenuOpSeq SmimeDefaultBindings[];
56
60struct Extkey
61{
62 const char *name;
63 const char *sym;
64};
65
69static const struct Extkey ExtKeys[] = {
70 { "<c-up>", "kUP5" },
71 { "<s-up>", "kUP" },
72 { "<a-up>", "kUP3" },
73
74 { "<s-down>", "kDN" },
75 { "<a-down>", "kDN3" },
76 { "<c-down>", "kDN5" },
77
78 { "<c-right>", "kRIT5" },
79 { "<s-right>", "kRIT" },
80 { "<a-right>", "kRIT3" },
81
82 { "<s-left>", "kLFT" },
83 { "<a-left>", "kLFT3" },
84 { "<c-left>", "kLFT5" },
85
86 { "<s-home>", "kHOM" },
87 { "<a-home>", "kHOM3" },
88 { "<c-home>", "kHOM5" },
89
90 { "<s-end>", "kEND" },
91 { "<a-end>", "kEND3" },
92 { "<c-end>", "kEND5" },
93
94 { "<s-next>", "kNXT" },
95 { "<a-next>", "kNXT3" },
96 { "<c-next>", "kNXT5" },
97
98 { "<s-prev>", "kPRV" },
99 { "<a-prev>", "kPRV3" },
100 { "<c-prev>", "kPRV5" },
101
102 { 0, 0 },
103};
104
114static const char *find_ext_name(const char *key)
115{
116 for (int j = 0; ExtKeys[j].name; j++)
117 {
118 if (strcasecmp(key, ExtKeys[j].name) == 0)
119 return ExtKeys[j].sym;
120 }
121 return 0;
122}
123
135{
136#ifdef HAVE_USE_EXTENDED_NAMES
137 use_extended_names(true);
138
139 for (int j = 0; KeyNames[j].name; j++)
140 {
141 if (KeyNames[j].value == -1)
142 {
143 const char *keyname = find_ext_name(KeyNames[j].name);
144
145 if (keyname)
146 {
147 const char *s = mutt_tigetstr((char *) keyname);
148 if (s && ((long) (s) != -1))
149 {
150 int code = key_defined(s);
151 if (code > 0)
152 KeyNames[j].value = code;
153 }
154 }
155 }
156 }
157#endif
158}
159
165static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
166{
167 STAILQ_INIT(&Keymaps[mtype]);
168
169 for (int i = 0; map[i].op != OP_NULL; i++)
170 if (map[i].seq)
171 km_bindkey(map[i].seq, mtype, map[i].op);
172}
173
177void km_init(void)
178{
179 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
180
183#ifdef USE_AUTOCRYPT
185#endif
195
200
201#ifdef CRYPT_BACKEND_GPGME
204#endif
205}
206
211static void mutt_keymaplist_free(struct KeymapList *km_list)
212{
213 struct Keymap *np = NULL, *tmp = NULL;
214 STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
215 {
216 STAILQ_REMOVE(km_list, np, Keymap, entries);
217 mutt_keymap_free(&np);
218 }
219}
220
225{
226 for (enum MenuType i = 1; i < MENU_MAX; i++)
227 {
229 }
230}
231
238{
239 keycode_t buf[2];
240 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
241 size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
242 if (len == 0)
243 {
244 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
245 AbortKey = ctrl('G');
246 return;
247 }
248 if (len > 1)
249 {
250 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
251 c_abort_key);
252 }
253 AbortKey = buf[0];
254}
255
260{
261 if (nc->event_type != NT_CONFIG)
262 return 0;
263 if (!nc->event_data)
264 return -1;
265
266 struct EventConfig *ev_c = nc->event_data;
267
268 if (!mutt_str_equal(ev_c->name, "abort_key"))
269 return 0;
270
272 mutt_debug(LL_DEBUG5, "config done\n");
273 return 0;
274}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
#define mutt_warning(...)
Definition: logging2.h:90
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
int main_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: init.c:259
const struct MenuOpSeq GenericDefaultBindings[]
Key bindings for the Generic Menu.
Definition: functions.c:138
const struct MenuOpSeq DialogDefaultBindings[]
Key bindings for Simple Dialogs.
Definition: functions.c:130
Convenience wrapper for the gui headers.
const struct MenuOpSeq AttachmentDefaultBindings[]
Key bindings for the Attachment Menu.
Definition: functions.c:98
const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition: functions.c:88
const struct MenuOpSeq QueryDefaultBindings[]
Key bindings for the external Query Menu.
Definition: functions.c:109
const struct MenuOpSeq PostponedDefaultBindings[]
Key bindings for the Postpone Menu.
Definition: functions.c:62
const struct MenuOpSeq BrowserDefaultBindings[]
Key bindings for the file Browser Menu.
Definition: functions.c:105
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition: functions.c:92
static const struct Extkey ExtKeys[]
Mapping between NeoMutt and Curses key names.
Definition: init.c:69
void km_init(void)
Initialise all the menu keybindings.
Definition: init.c:177
const struct MenuOpSeq PagerDefaultBindings[]
Key bindings for the Pager Menu.
Definition: functions.c:229
const struct MenuOpSeq IndexDefaultBindings[]
Key bindings for the Index Menu.
Definition: functions.c:236
const struct MenuOpSeq AutocryptDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition: functions.c:67
static const char * find_ext_name(const char *key)
Find the curses name for a key.
Definition: init.c:114
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: init.c:165
const struct MenuOpSeq PgpDefaultBindings[]
Key bindings for the Pgp Menu.
Definition: functions.c:64
const struct MenuOpSeq ComposeDefaultBindings[]
Key bindings for the Compose Menu.
Definition: functions.c:153
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: init.c:211
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
const struct MenuOpSeq SmimeDefaultBindings[]
Key bindings for the Smime Menu.
Definition: functions.c:74
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition: init.c:237
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: lib.c:122
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:131
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:125
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:216
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:60
Manage keymappings.
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:55
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
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
#define mutt_array_size(x)
Definition: memory.h:38
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
#define ctrl(ch)
Definition: mutt_curses.h:52
API for encryption/signing of emails.
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
#define WithCrypto
Definition: lib.h:116
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_INIT(head)
Definition: queue.h:372
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
Map key names from NeoMutt's style to Curses style.
Definition: init.c:61
const char * sym
Curses key name.
Definition: init.c:63
const char * name
NeoMutt key name.
Definition: init.c:62
A keyboard mapping.
Definition: lib.h:65
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition: lib.h:70
int value
Integer value.
Definition: mapping.h:35
const char * name
String value.
Definition: mapping.h:34
Mapping between an operation and a key sequence.
Definition: lib.h:110
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:111
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
const char * mutt_tigetstr(const char *name)
Get terminal capabilities.
Definition: terminal.c:57
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_KEY_SELECT_PGP
Select a PGP key.
Definition: type.h:48
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:51
@ MENU_DIALOG
Simple Dialog.
Definition: type.h:43
@ MENU_KEY_SELECT_SMIME
Select a SMIME key.
Definition: type.h:49
@ MENU_QUERY
Select from results of external query.
Definition: type.h:55
@ MENU_AUTOCRYPT
Autocrypt Account menu.
Definition: type.h:40
@ MENU_COMPOSE
Compose an email.
Definition: type.h:42
@ MENU_ATTACHMENT
Select an attachment.
Definition: type.h:38
@ MENU_PGP
PGP encryption menu.
Definition: type.h:53
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:52
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:56
@ MENU_MAX
Definition: type.h:57
@ MENU_EDITOR
Text entry area.
Definition: type.h:44
@ MENU_ALIAS
Select an email address by its alias.
Definition: type.h:37
@ MENU_FOLDER
General file/mailbox browser.
Definition: type.h:45
@ MENU_POSTPONED
Select a postponed email.
Definition: type.h:54