NeoMutt  2025-12-11-872-g385a04
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 "pager/lib.h"
44
50static const char *FlagCharsDesc[] = {
51 N_("message is tagged"),
52 N_("message is flagged"),
53 N_("message is deleted"),
54 N_("attachment is deleted"),
55 N_("message has been replied to"),
56 N_("message has been read"),
57 N_("message is new"),
58 N_("thread has been read"),
59 N_("thread has at least one new message"),
60 N_("message has been read (%S expando)"),
61 N_("message has been read (%Z expando)"),
62};
63
69static const char *CryptCharsDesc[] = {
70 N_("message signed with a verified key"),
71 N_("message is PGP-encrypted"),
72 N_("message is signed"),
73 N_("message contains a PGP key"),
74 N_("message has no cryptography information"),
75};
76
82static const char *ToCharsDesc[] = {
83 N_("message is not To: you"),
84 N_("message is To: you and only you"),
85 N_("message is To: you"),
86 N_("message is Cc: to you"),
87 N_("message is From: you"),
88 N_("message is sent to a subscribed mailing list"),
89 N_("you are in the Reply-To: list"),
90};
91
102static void dump_message_flags(const struct MenuDefinition *md, FILE *fp)
103{
104 if (md != MdIndex)
105 return;
106
107 const char *flag = NULL;
108 int cols;
109
110 fprintf(fp, "\n%s\n\n", _("Message flags:"));
111
112 const struct MbTable *c_flag_chars = cs_subset_mbtable(NeoMutt->sub, "flag_chars");
113 fprintf(fp, "$flag_chars:\n");
114 for (int i = FLAG_CHAR_TAGGED; i <= FLAG_CHAR_ZEMPTY; i++)
115 {
116 flag = mbtable_get_nth_wchar(c_flag_chars, i);
117 cols = mutt_strwidth(flag);
118 fprintf(fp, " '%s'%*s %s\n", flag, 4 - cols, "", _(FlagCharsDesc[i]));
119 }
120
121 const struct MbTable *c_crypt_chars = cs_subset_mbtable(NeoMutt->sub, "crypt_chars");
122 fprintf(fp, "\n$crypt_chars:\n");
124 {
125 flag = mbtable_get_nth_wchar(c_crypt_chars, i);
126 cols = mutt_strwidth(flag);
127 fprintf(fp, " '%s'%*s %s\n", flag, 4 - cols, "", _(CryptCharsDesc[i]));
128 }
129
130 const struct MbTable *c_to_chars = cs_subset_mbtable(NeoMutt->sub, "to_chars");
131 fprintf(fp, "\n$to_chars:\n");
133 {
134 flag = mbtable_get_nth_wchar(c_to_chars, i);
135 cols = mutt_strwidth(flag);
136 fprintf(fp, " '%s'%*s %s\n", flag, 4 - cols, "", _(ToCharsDesc[i]));
137 }
138
139 fprintf(fp, "\n");
140}
141
146void mutt_help(const struct MenuDefinition *md)
147{
148 struct BindingInfoArray bia_bind = ARRAY_HEAD_INITIALIZER;
149 struct BindingInfoArray bia_macro = ARRAY_HEAD_INITIALIZER;
150 struct BindingInfoArray bia_unbound = ARRAY_HEAD_INITIALIZER;
151 struct Buffer *banner = NULL;
152 struct Buffer *tempfile = NULL;
153 struct BindingInfo *bi = NULL;
154
155 // ---------------------------------------------------------------------------
156 // Gather the data
157
158 gather_menu(md, &bia_bind, &bia_macro, false);
159
160 ARRAY_SORT(&bia_bind, binding_sort, NULL);
161 ARRAY_SORT(&bia_macro, binding_sort, NULL);
162
163 int wb0 = measure_column(&bia_bind, 0);
164 int wb1 = measure_column(&bia_bind, 1);
165
166 const int wm0 = measure_column(&bia_macro, 0);
167
168 gather_unbound(md, &bia_unbound);
169
170 ARRAY_SORT(&bia_unbound, binding_sort, NULL);
171 const int wu1 = measure_column(&bia_unbound, 1);
172
173 // ---------------------------------------------------------------------------
174 // Save the data to a file
175
176 tempfile = buf_pool_get();
177 buf_mktemp(tempfile);
178 FILE *fp = mutt_file_fopen(buf_string(tempfile), "w");
179 if (!fp)
180 {
181 mutt_perror("%s", buf_string(tempfile));
182 goto cleanup;
183 }
184
185 const char *menu_name = NULL;
186 ARRAY_FOREACH(bi, &bia_bind)
187 {
188 if (!bi->a[0])
189 {
190 menu_name = bi->a[2];
191 continue;
192 }
193
194 if (menu_name)
195 {
196 if (ARRAY_FOREACH_IDX_bi > 0)
197 fprintf(fp, "\n");
198
199 fprintf(fp, "%s bindings\n", menu_name);
200 fprintf(fp, "\n");
201 menu_name = NULL;
202 }
203
204 // key text description
205 fprintf(fp, "%*s %*s %s\n", -wb0, bi->a[0], -wb1, bi->a[1], bi->a[2]);
206 }
207
208 ARRAY_FOREACH(bi, &bia_macro)
209 {
210 if (!bi->a[0])
211 {
212 menu_name = bi->a[2];
213 continue;
214 }
215
216 if (menu_name)
217 {
218 if (ARRAY_FOREACH_IDX_bi > 0)
219 fprintf(fp, "\n");
220
221 fprintf(fp, "%s macros\n", menu_name);
222 fprintf(fp, "\n");
223 menu_name = NULL;
224 }
225
226 if (bi->a[2]) // description
227 {
228 // key description, macro-text, blank line
229 fprintf(fp, "%*s %s\n", -wm0, bi->a[0], bi->a[2]);
230 fprintf(fp, "%s\n", bi->a[1]);
231 fprintf(fp, "\n");
232 }
233 else
234 {
235 // key macro-text
236 fprintf(fp, "%*s %s\n", -wm0, bi->a[0], bi->a[1]);
237 }
238 }
239 fprintf(fp, "\n");
240
241 fprintf(fp, "unbound functions\n");
242 fprintf(fp, "\n");
243 ARRAY_FOREACH(bi, &bia_unbound)
244 {
245 // function description
246 fprintf(fp, "%*s %s\n", -wu1, bi->a[1], bi->a[2]);
247 }
248
249 dump_message_flags(md, fp);
250 mutt_file_fclose(&fp);
251
252 // ---------------------------------------------------------------------------
253 // Display data
254
255 struct PagerData pdata = { 0 };
256 struct PagerView pview = { &pdata };
257
258 pview.mode = PAGER_MODE_HELP;
260
262 buf_printf(banner, _("Help for %s"), md->name);
263 pdata.fname = buf_string(tempfile);
264 pview.banner = buf_string(banner);
265 mutt_do_pager(&pview, NULL);
266
267cleanup:
268
269 ARRAY_FOREACH(bi, &bia_bind)
270 {
271 FREE(&bi->a[0]);
272 }
273
274 ARRAY_FOREACH(bi, &bia_macro)
275 {
276 FREE(&bi->a[0]);
277 FREE(&bi->a[1]);
278 }
279
281 buf_pool_release(&tempfile);
282 ARRAY_FREE(&bia_bind);
283 ARRAY_FREE(&bia_macro);
284 ARRAY_FREE(&bia_unbound);
285}
#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:446
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:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
#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:205
Convenience wrapper for the gui headers.
static void dump_message_flags(const struct MenuDefinition *md, FILE *fp)
Write out all the message flags.
Definition help.c:102
static const char * ToCharsDesc[]
Descriptions of the $to_chars flags.
Definition help.c:82
void mutt_help(const struct MenuDefinition *md)
Display the Help Page.
Definition help.c:146
static const char * CryptCharsDesc[]
Descriptions of the $crypt_chars flags.
Definition help.c:69
static const char * FlagCharsDesc[]
Descriptions of the $flag_chars flags.
Definition help.c:50
#define MdIndex
Definition functions.h:72
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:229
void gather_menu(const struct MenuDefinition *md, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro, bool one_submenu)
Gather info about one menu.
Definition dump.c:134
int gather_unbound(const struct MenuDefinition *md, struct BindingInfoArray *bia_unbound)
Gather info about unbound functions for one menu.
Definition dump.c:441
Manage keymappings.
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)
Free memory and set the pointer to NULL.
Definition memory.h:68
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:74
#define MUTT_PAGER_STRIPES
Striped highlighting.
Definition lib.h:77
#define MUTT_PAGER_MARKER
Use markers if option is set.
Definition lib.h:72
@ PAGER_MODE_HELP
Pager is invoked via 3rd path to show help.
Definition lib.h:142
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
Info about one keybinding.
Definition dump.h:40
const char * a[3]
Array of info.
Definition dump.h:42
String manipulation buffer.
Definition buffer.h:36
Multibyte character table.
Definition mbtable.h:36
Functions for a Dialog or Window.
Definition menu.h:77
const char * name
Menu name, e.g. "alias".
Definition menu.h:79
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Data to be displayed by PagerView.
Definition lib.h:162
const char * fname
Name of the file to read.
Definition lib.h:166
Paged view into some data.
Definition lib.h:173
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition lib.h:174
enum PagerMode mode
Pager mode.
Definition lib.h:175
PagerFlags flags
Additional settings to tweak pager's function.
Definition lib.h:176
const char * banner
Title to display in status bar.
Definition lib.h:177
#define buf_mktemp(buf)
Definition tmp.h:33