Thanks to visit codestin.com
Credit goes to code.neomutt.org

NeoMutt  2025-12-11-189-gceedb6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
help.c
Go to the documentation of this file.
1
27
33
34#include "config.h"
35#include <stdbool.h>
36#include <stdio.h>
37#include "mutt/lib.h"
38#include "config/lib.h"
39#include "core/lib.h"
40#include "gui/lib.h"
41#include "index/lib.h"
42#include "key/lib.h"
43#include "menu/lib.h"
44#include "pager/lib.h"
45
51static const char *FlagCharsDesc[] = {
52 N_("message is tagged"),
53 N_("message is flagged"),
54 N_("message is deleted"),
55 N_("attachment is deleted"),
56 N_("message has been replied to"),
57 N_("message has been read"),
58 N_("message is new"),
59 N_("thread has been read"),
60 N_("thread has at least one new message"),
61 N_("message has been read (%S expando)"),
62 N_("message has been read (%Z expando)"),
63};
64
70static const char *CryptCharsDesc[] = {
71 N_("message signed with a verified key"),
72 N_("message is PGP-encrypted"),
73 N_("message is signed"),
74 N_("message contains a PGP key"),
75 N_("message has no cryptography information"),
76};
77
83static const char *ToCharsDesc[] = {
84 N_("message is not To: you"),
85 N_("message is To: you and only you"),
86 N_("message is To: you"),
87 N_("message is Cc: to you"),
88 N_("message is From: you"),
89 N_("message is sent to a subscribed mailing list"),
90 N_("you are in the Reply-To: list"),
91};
92
103static void dump_message_flags(enum MenuType menu, FILE *fp)
104{
105 if (menu != MENU_INDEX)
106 return;
107
108 const char *flag = NULL;
109 int cols;
110
111 fprintf(fp, "\n%s\n\n", _("Message flags:"));
112
113 const struct MbTable *c_flag_chars = cs_subset_mbtable(NeoMutt->sub, "flag_chars");
114 fprintf(fp, "$flag_chars:\n");
115 for (int i = FLAG_CHAR_TAGGED; i <= FLAG_CHAR_ZEMPTY; i++)
116 {
117 flag = mbtable_get_nth_wchar(c_flag_chars, i);
118 cols = mutt_strwidth(flag);
119 fprintf(fp, " '%s'%*s %s\n", flag, 4 - cols, "", _(FlagCharsDesc[i]));
120 }
121
122 const struct MbTable *c_crypt_chars = cs_subset_mbtable(NeoMutt->sub, "crypt_chars");
123 fprintf(fp, "\n$crypt_chars:\n");
125 {
126 flag = mbtable_get_nth_wchar(c_crypt_chars, i);
127 cols = mutt_strwidth(flag);
128 fprintf(fp, " '%s'%*s %s\n", flag, 4 - cols, "", _(CryptCharsDesc[i]));
129 }
130
131 const struct MbTable *c_to_chars = cs_subset_mbtable(NeoMutt->sub, "to_chars");
132 fprintf(fp, "\n$to_chars:\n");
134 {
135 flag = mbtable_get_nth_wchar(c_to_chars, i);
136 cols = mutt_strwidth(flag);
137 fprintf(fp, " '%s'%*s %s\n", flag, 4 - cols, "", _(ToCharsDesc[i]));
138 }
139
140 fprintf(fp, "\n");
141}
142
147void mutt_help(enum MenuType menu)
148{
149 struct BindingInfoArray bia_bind = ARRAY_HEAD_INITIALIZER;
150 struct BindingInfoArray bia_macro = ARRAY_HEAD_INITIALIZER;
151 struct BindingInfoArray bia_unbound = ARRAY_HEAD_INITIALIZER;
152 struct Buffer *banner = NULL;
153 struct Buffer *tempfile = NULL;
154 struct BindingInfo *bi = NULL;
155
156 // ---------------------------------------------------------------------------
157 // Gather the data
158
159 gather_menu(menu, &bia_bind, &bia_macro, false);
160
161 ARRAY_SORT(&bia_bind, binding_sort, NULL);
162 ARRAY_SORT(&bia_macro, binding_sort, NULL);
163
164 int wb0 = measure_column(&bia_bind, 0);
165 int wb1 = measure_column(&bia_bind, 1);
166
167 const int wm0 = measure_column(&bia_macro, 0);
168
169 gather_unbound(menu, &bia_unbound);
170
171 ARRAY_SORT(&bia_unbound, binding_sort, NULL);
172 const int wu1 = measure_column(&bia_unbound, 1);
173
174 // ---------------------------------------------------------------------------
175 // Save the data to a file
176
177 tempfile = buf_pool_get();
178 buf_mktemp(tempfile);
179 FILE *fp = mutt_file_fopen(buf_string(tempfile), "w");
180 if (!fp)
181 {
182 mutt_perror("%s", buf_string(tempfile));
183 goto cleanup;
184 }
185
186 const char *menu_name = NULL;
187 ARRAY_FOREACH(bi, &bia_bind)
188 {
189 if (!bi->a[0])
190 {
191 menu_name = bi->a[2];
192 continue;
193 }
194
195 if (menu_name)
196 {
197 if (ARRAY_FOREACH_IDX_bi > 0)
198 fprintf(fp, "\n");
199
200 fprintf(fp, "%s bindings\n", menu_name);
201 fprintf(fp, "\n");
202 menu_name = NULL;
203 }
204
205 // key text description
206 fprintf(fp, "%*s %*s %s\n", -wb0, bi->a[0], -wb1, bi->a[1], bi->a[2]);
207 }
208
209 ARRAY_FOREACH(bi, &bia_macro)
210 {
211 if (!bi->a[0])
212 {
213 menu_name = bi->a[2];
214 continue;
215 }
216
217 if (menu_name)
218 {
219 if (ARRAY_FOREACH_IDX_bi > 0)
220 fprintf(fp, "\n");
221
222 fprintf(fp, "%s macros\n", menu_name);
223 fprintf(fp, "\n");
224 menu_name = NULL;
225 }
226
227 if (bi->a[2]) // description
228 {
229 // key description, macro-text, blank line
230 fprintf(fp, "%*s %s\n", -wm0, bi->a[0], bi->a[2]);
231 fprintf(fp, "%s\n", bi->a[1]);
232 fprintf(fp, "\n");
233 }
234 else
235 {
236 // key macro-text
237 fprintf(fp, "%*s %s\n", -wm0, bi->a[0], bi->a[1]);
238 }
239 }
240 fprintf(fp, "\n");
241
242 fprintf(fp, "unbound functions\n");
243 fprintf(fp, "\n");
244 ARRAY_FOREACH(bi, &bia_unbound)
245 {
246 // function description
247 fprintf(fp, "%*s %s\n", -wu1, bi->a[1], bi->a[2]);
248 }
249
250 dump_message_flags(menu, fp);
251 mutt_file_fclose(&fp);
252
253 // ---------------------------------------------------------------------------
254 // Display data
255
256 struct PagerData pdata = { 0 };
257 struct PagerView pview = { &pdata };
258
259 pview.mode = PAGER_MODE_HELP;
261
263 menu_name = km_get_menu_name(menu);
264 buf_printf(banner, _("Help for %s"), menu_name);
265 pdata.fname = buf_string(tempfile);
266 pview.banner = buf_string(banner);
267 mutt_do_pager(&pview, NULL);
268
269cleanup:
270
271 ARRAY_FOREACH(bi, &bia_bind)
272 {
273 FREE(&bi->a[0]);
274 }
275
276 ARRAY_FOREACH(bi, &bia_macro)
277 {
278 FREE(&bi->a[0]);
279 FREE(&bi->a[1]);
280 }
281
283 buf_pool_release(&tempfile);
284 ARRAY_FREE(&bia_bind);
285 ARRAY_FREE(&bia_macro);
286 ARRAY_FREE(&bia_unbound);
287}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition array.h:373
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
struct MbTable * cs_subset_mbtable(const struct ConfigSubset *sub, const char *name)
Get a Multibyte table config item by name.
Definition helpers.c:119
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition curs_lib.c:444
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition do_pager.c:122
@ FLAG_CHAR_TO_NOT_IN_THE_LIST
Character denoting that the user is not in list.
@ FLAG_CHAR_TO_REPLY_TO
Character denoting that the user is in the Reply-To list.
@ FLAG_CHAR_CRYPT_NO_CRYPTO
Character denoting a message has no cryptography information.
@ FLAG_CHAR_CRYPT_GOOD_SIGN
Character denoting a message signed with a verified key.
@ FLAG_CHAR_ZEMPTY
Character denoting a read email, $index_format Z expando.
@ FLAG_CHAR_TAGGED
Character denoting a tagged email.
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
#define mutt_perror(...)
Definition logging2.h:95
int binding_sort(const void *a, const void *b, void *sdata)
Compare two BindingInfo by their keybinding - Implements sort_t -.
Definition dump.c:237
Convenience wrapper for the gui headers.
static void dump_message_flags(enum MenuType menu, FILE *fp)
Write out all the message flags.
Definition help.c:103
static const char * ToCharsDesc[]
Descriptions of the $to_chars flags.
Definition help.c:83
static const char * CryptCharsDesc[]
Descriptions of the $crypt_chars flags.
Definition help.c:70
static const char * FlagCharsDesc[]
Descriptions of the $flag_chars flags.
Definition help.c:51
void mutt_help(enum MenuType menu)
Display the Help Page.
Definition help.c:147
GUI manage the main index (list of emails)
int measure_column(struct BindingInfoArray *bia, int col)
Measure one column of a table.
Definition dump.c:423
void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro, bool one_submenu)
Gather info about one menu.
Definition dump.c:342
int gather_unbound(enum MenuType mtype, struct BindingInfoArray *bia_unbound)
Gather info about unbound functions for one menu.
Definition dump.c:443
Manage keymappings.
const char * km_get_menu_name(int mtype)
Get the name of a Menu.
Definition menu.c:195
const char * mbtable_get_nth_wchar(const struct MbTable *table, int index)
Extract one char from a multi-byte table.
Definition mbtable.c:340
#define FREE(x)
Definition memory.h:63
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
GUI display a file/email/help in a viewport with paging.
#define MUTT_PAGER_NOWRAP
Format for term width, ignore $wrap.
Definition lib.h:73
#define MUTT_PAGER_STRIPES
Striped highlighting.
Definition lib.h:76
#define MUTT_PAGER_MARKER
Use markers if option is set.
Definition lib.h:71
@ PAGER_MODE_HELP
Pager is invoked via 3rd path to show help.
Definition lib.h:141
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
Info about one keybinding.
Definition dump.h:41
const char * a[3]
Array of info.
Definition dump.h:43
String manipulation buffer.
Definition buffer.h:36
Multibyte character table.
Definition mbtable.h:36
Container for Accounts, Notifications.
Definition neomutt.h:128
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:134
Data to be displayed by PagerView.
Definition lib.h:161
const char * fname
Name of the file to read.
Definition lib.h:165
Paged view into some data.
Definition lib.h:172
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition lib.h:173
enum PagerMode mode
Pager mode.
Definition lib.h:174
PagerFlags flags
Additional settings to tweak pager's function.
Definition lib.h:175
const char * banner
Title to display in status bar.
Definition lib.h:176
#define buf_mktemp(buf)
Definition tmp.h:33
MenuType
Types of GUI selections.
Definition type.h:33
@ MENU_INDEX
Index panel (list of emails)
Definition type.h:44