NeoMutt  2025-01-09-144-gb44c67
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 "lib.h"
39#include "menu/lib.h"
40
41extern const struct MenuOpSeq AliasDefaultBindings[];
42extern const struct MenuOpSeq AttachmentDefaultBindings[];
43#ifdef USE_AUTOCRYPT
44extern const struct MenuOpSeq AutocryptDefaultBindings[];
45#endif
46extern const struct MenuOpSeq BrowserDefaultBindings[];
47extern const struct MenuOpSeq ComposeDefaultBindings[];
48extern const struct MenuOpSeq EditorDefaultBindings[];
49extern const struct MenuOpSeq IndexDefaultBindings[];
50extern const struct MenuOpSeq PagerDefaultBindings[];
51extern const struct MenuOpSeq PgpDefaultBindings[];
52extern const struct MenuOpSeq PostponedDefaultBindings[];
53extern const struct MenuOpSeq QueryDefaultBindings[];
54extern const struct MenuOpSeq SmimeDefaultBindings[];
55
59struct Extkey
60{
61 const char *name;
62 const char *sym;
63};
64
68static const struct Extkey ExtKeys[] = {
69 { "<c-up>", "kUP5" },
70 { "<s-up>", "kUP" },
71 { "<a-up>", "kUP3" },
72
73 { "<s-down>", "kDN" },
74 { "<a-down>", "kDN3" },
75 { "<c-down>", "kDN5" },
76
77 { "<c-right>", "kRIT5" },
78 { "<s-right>", "kRIT" },
79 { "<a-right>", "kRIT3" },
80
81 { "<s-left>", "kLFT" },
82 { "<a-left>", "kLFT3" },
83 { "<c-left>", "kLFT5" },
84
85 { "<s-home>", "kHOM" },
86 { "<a-home>", "kHOM3" },
87 { "<c-home>", "kHOM5" },
88
89 { "<s-end>", "kEND" },
90 { "<a-end>", "kEND3" },
91 { "<c-end>", "kEND5" },
92
93 { "<s-next>", "kNXT" },
94 { "<a-next>", "kNXT3" },
95 { "<c-next>", "kNXT5" },
96
97 { "<s-prev>", "kPRV" },
98 { "<a-prev>", "kPRV3" },
99 { "<c-prev>", "kPRV5" },
100
101 { 0, 0 },
102};
103
113static const char *find_ext_name(const char *key)
114{
115 for (int j = 0; ExtKeys[j].name; j++)
116 {
117 if (strcasecmp(key, ExtKeys[j].name) == 0)
118 return ExtKeys[j].sym;
119 }
120 return 0;
121}
122
134{
135#ifdef HAVE_USE_EXTENDED_NAMES
136 use_extended_names(true);
137
138 for (int j = 0; KeyNames[j].name; j++)
139 {
140 if (KeyNames[j].value == -1)
141 {
142 const char *keyname = find_ext_name(KeyNames[j].name);
143
144 if (keyname)
145 {
146 const char *s = mutt_tigetstr((char *) keyname);
147 if (s && ((long) (s) != -1))
148 {
149 int code = key_defined(s);
150 if (code > 0)
151 KeyNames[j].value = code;
152 }
153 }
154 }
155 }
156#endif
157}
158
164static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
165{
166 STAILQ_INIT(&Keymaps[mtype]);
167
168 for (int i = 0; map[i].op != OP_NULL; i++)
169 if (map[i].seq)
170 km_bindkey(map[i].seq, mtype, map[i].op);
171}
172
176void km_init(void)
177{
178 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
179
182#ifdef USE_AUTOCRYPT
184#endif
196}
197
202static void mutt_keymaplist_free(struct KeymapList *km_list)
203{
204 struct Keymap *np = NULL, *tmp = NULL;
205 STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
206 {
207 STAILQ_REMOVE(km_list, np, Keymap, entries);
208 mutt_keymap_free(&np);
209 }
210}
211
216{
217 for (enum MenuType i = 1; i < MENU_MAX; i++)
218 {
220 }
221}
222
229{
230 keycode_t buf[2];
231 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
232 size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
233 if (len == 0)
234 {
235 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
236 AbortKey = ctrl('G');
237 return;
238 }
239 if (len > 1)
240 {
241 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
242 c_abort_key);
243 }
244 AbortKey = buf[0];
245}
246
251{
252 if (nc->event_type != NT_CONFIG)
253 return 0;
254 if (!nc->event_data)
255 return -1;
256
257 struct EventConfig *ev_c = nc->event_data;
258
259 if (!mutt_str_equal(ev_c->name, "abort_key"))
260 return 0;
261
263 mutt_debug(LL_DEBUG5, "config done\n");
264 return 0;
265}
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:91
#define mutt_error(...)
Definition: logging2.h:93
#define mutt_debug(LEVEL,...)
Definition: logging2.h:90
int main_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: init.c:250
const struct MenuOpSeq GenericDefaultBindings[]
Key bindings for the Generic Menu.
Definition: functions.c:139
const struct MenuOpSeq DialogDefaultBindings[]
Key bindings for Simple Dialogs.
Definition: functions.c:131
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:110
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:106
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition: functions.c:93
static const struct Extkey ExtKeys[]
Mapping between NeoMutt and Curses key names.
Definition: init.c:68
void km_init(void)
Initialise all the menu keybindings.
Definition: init.c:176
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:235
const struct MenuOpSeq AutocryptDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition: functions.c:68
static const char * find_ext_name(const char *key)
Find the curses name for a key.
Definition: init.c:113
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: init.c:164
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:155
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: init.c:202
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
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:228
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: lib.c:121
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:130
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:124
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:215
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:59
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:56
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
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:48
#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:661
#define ctrl(ch)
Definition: mutt_curses.h:52
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:441
#define STAILQ_INIT(head)
Definition: queue.h:410
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:400
Key value store.
A config-change event.
Definition: subset.h:70
const char * name
Name of config item that changed.
Definition: subset.h:72
Map key names from NeoMutt's style to Curses style.
Definition: init.c:60
const char * sym
Curses key name.
Definition: init.c:62
const char * name
NeoMutt key name.
Definition: init.c:61
A keyboard mapping.
Definition: lib.h:66
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition: lib.h:71
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:121
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:122
Container for Accounts, Notifications.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:47
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_INDEX
Index panel (list of emails)
Definition: type.h:47
@ MENU_DIALOG
Simple Dialog.
Definition: type.h:43
@ MENU_QUERY
Select from results of external query.
Definition: type.h:51
@ 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:49
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:48
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:52
@ MENU_MAX
Definition: type.h:53
@ 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:50