NeoMutt  2024-04-16-36-g75b6fb
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[];
51#ifdef MIXMASTER
52extern const struct MenuOpSeq MixmasterDefaultBindings[];
53#endif
54extern const struct MenuOpSeq PagerDefaultBindings[];
55extern const struct MenuOpSeq PgpDefaultBindings[];
56extern const struct MenuOpSeq PostponedDefaultBindings[];
57extern const struct MenuOpSeq QueryDefaultBindings[];
58extern const struct MenuOpSeq SmimeDefaultBindings[];
59
63struct Extkey
64{
65 const char *name;
66 const char *sym;
67};
68
72static const struct Extkey ExtKeys[] = {
73 { "<c-up>", "kUP5" },
74 { "<s-up>", "kUP" },
75 { "<a-up>", "kUP3" },
76
77 { "<s-down>", "kDN" },
78 { "<a-down>", "kDN3" },
79 { "<c-down>", "kDN5" },
80
81 { "<c-right>", "kRIT5" },
82 { "<s-right>", "kRIT" },
83 { "<a-right>", "kRIT3" },
84
85 { "<s-left>", "kLFT" },
86 { "<a-left>", "kLFT3" },
87 { "<c-left>", "kLFT5" },
88
89 { "<s-home>", "kHOM" },
90 { "<a-home>", "kHOM3" },
91 { "<c-home>", "kHOM5" },
92
93 { "<s-end>", "kEND" },
94 { "<a-end>", "kEND3" },
95 { "<c-end>", "kEND5" },
96
97 { "<s-next>", "kNXT" },
98 { "<a-next>", "kNXT3" },
99 { "<c-next>", "kNXT5" },
100
101 { "<s-prev>", "kPRV" },
102 { "<a-prev>", "kPRV3" },
103 { "<c-prev>", "kPRV5" },
104
105 { 0, 0 },
106};
107
117static const char *find_ext_name(const char *key)
118{
119 for (int j = 0; ExtKeys[j].name; j++)
120 {
121 if (strcasecmp(key, ExtKeys[j].name) == 0)
122 return ExtKeys[j].sym;
123 }
124 return 0;
125}
126
138{
139#ifdef HAVE_USE_EXTENDED_NAMES
140 use_extended_names(true);
141
142 for (int j = 0; KeyNames[j].name; j++)
143 {
144 if (KeyNames[j].value == -1)
145 {
146 const char *keyname = find_ext_name(KeyNames[j].name);
147
148 if (keyname)
149 {
150 const char *s = mutt_tigetstr((char *) keyname);
151 if (s && ((long) (s) != -1))
152 {
153 int code = key_defined(s);
154 if (code > 0)
155 KeyNames[j].value = code;
156 }
157 }
158 }
159 }
160#endif
161}
162
168static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
169{
170 STAILQ_INIT(&Keymaps[mtype]);
171
172 for (int i = 0; map[i].op != OP_NULL; i++)
173 if (map[i].seq)
174 km_bindkey(map[i].seq, mtype, map[i].op);
175}
176
180void km_init(void)
181{
182 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
183
186#ifdef USE_AUTOCRYPT
188#endif
195#ifdef MIXMASTER
197#endif
201
206
207#ifdef CRYPT_BACKEND_GPGME
210#endif
211}
212
217static void mutt_keymaplist_free(struct KeymapList *km_list)
218{
219 struct Keymap *np = NULL, *tmp = NULL;
220 STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
221 {
222 STAILQ_REMOVE(km_list, np, Keymap, entries);
223 mutt_keymap_free(&np);
224 }
225}
226
231{
232 for (enum MenuType i = 1; i < MENU_MAX; i++)
233 {
235 }
236}
237
244{
245 keycode_t buf[2];
246 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
247 size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
248 if (len == 0)
249 {
250 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
251 AbortKey = ctrl('G');
252 return;
253 }
254 if (len > 1)
255 {
256 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
257 c_abort_key);
258 }
259 AbortKey = buf[0];
260}
261
266{
267 if (nc->event_type != NT_CONFIG)
268 return 0;
269 if (!nc->event_data)
270 return -1;
271
272 struct EventConfig *ev_c = nc->event_data;
273
274 if (!mutt_str_equal(ev_c->name, "abort_key"))
275 return 0;
276
278 mutt_debug(LL_DEBUG5, "config done\n");
279 return 0;
280}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
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:265
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:100
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:103
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:108
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition: functions.c:88
static const struct Extkey ExtKeys[]
Mapping between NeoMutt and Curses key names.
Definition: init.c:72
void km_init(void)
Initialise all the menu keybindings.
Definition: init.c:180
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:239
const struct MenuOpSeq MixmasterDefaultBindings[]
Key bindings for the Mixmaster Menu.
Definition: functions.c:65
const struct MenuOpSeq AutocryptDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition: functions.c:66
static const char * find_ext_name(const char *key)
Find the curses name for a key.
Definition: init.c:117
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: init.c:168
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:159
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: init.c:217
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
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:243
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: lib.c:125
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:134
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:128
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:219
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:63
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:654
#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:64
const char * sym
Curses key name.
Definition: init.c:66
const char * name
NeoMutt key name.
Definition: init.c:65
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:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
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_MIXMASTER
Create/edit a Mixmaster chain.
Definition: type.h:53
@ MENU_KEY_SELECT_SMIME
Select a SMIME key.
Definition: type.h:49
@ MENU_QUERY
Select from results of external query.
Definition: type.h:58
@ 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:56
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:55
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:59
@ MENU_MAX
Definition: type.h:60
@ 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:57