NeoMutt  2023-05-17-16-g61469c
Teaching an old dog new tricks
dlg_pattern.c File Reference

Pattern Selection Dialog. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "menu/lib.h"
#include "format_flags.h"
#include "functions.h"
#include "keymap.h"
#include "mutt_logging.h"
#include "muttlib.h"
#include "opcodes.h"
+ Include dependency graph for dlg_pattern.c:

Go to the source code of this file.


static const char * pattern_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 Format a string for the pattern completion menu - Implements format_t -. More...
static void make_pattern_entry (struct Menu *menu, char *buf, size_t buflen, int num)
 Create a line for the Pattern Completion menu - Implements Menu::make_entry() -. More...
static void free_pattern_menu (struct Menu *menu, void **ptr)
 Free the Pattern Completion menu - Implements Menu::mdata_free() -. More...
static struct Menucreate_pattern_menu (struct MuttWindow *dlg)
 Create the Pattern Completion menu. More...
static int pattern_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -. More...
static int pattern_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -. More...
bool dlg_select_pattern (char *buf, size_t buflen)
 Show menu to select a Pattern. More...


static const struct Mapping PatternHelp []
 Help Bar for the Pattern selection dialog. More...

Detailed Description

Pattern Selection Dialog.

  • Michael R. Elkins
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

Definition in file dlg_pattern.c.

Function Documentation

◆ create_pattern_menu()

static struct Menu * create_pattern_menu ( struct MuttWindow dlg)

Create the Pattern Completion menu.

dlgDialog holding the Menu
Return values
ptrNew Menu

Definition at line 170 of file dlg_pattern.c.

172 int num_entries = 0, i = 0;
173 struct Buffer *entrybuf = NULL;
175 while (Flags[num_entries].tag)
176 num_entries++;
177 /* Add three more hard-coded entries */
178 num_entries += 3;
179 struct PatternEntry *entries = mutt_mem_calloc(num_entries, sizeof(struct PatternEntry));
181 struct Menu *menu = dlg->wdata;
183 menu->mdata = entries;
185 menu->max = num_entries;
187 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
188 // L10N: Pattern completion menu title
189 sbar_set_title(sbar, _("Patterns"));
191 entrybuf = buf_pool_get();
192 while (Flags[i].tag)
193 {
194 entries[i].num = i + 1;
196 buf_printf(entrybuf, "~%c", (char) Flags[i].tag);
197 entries[i].tag = mutt_str_dup(buf_string(entrybuf));
199 switch (Flags[i].eat_arg)
200 {
201 case EAT_REGEX:
202 /* L10N:
203 Pattern Completion Menu argument type: a regular expression
204 */
205 buf_add_printf(entrybuf, " %s", _("EXPR"));
206 break;
207 case EAT_RANGE:
209 /* L10N:
210 Pattern Completion Menu argument type: a numeric range.
211 Used by ~m, ~n, ~X, ~z.
212 */
213 buf_add_printf(entrybuf, " %s", _("RANGE"));
214 break;
215 case EAT_DATE:
216 /* L10N:
217 Pattern Completion Menu argument type: a date range
218 Used by ~d, ~r.
219 */
220 buf_add_printf(entrybuf, " %s", _("DATERANGE"));
221 break;
222 case EAT_QUERY:
223 /* L10N:
224 Pattern Completion Menu argument type: a query
225 Used by ~I.
226 */
227 buf_add_printf(entrybuf, " %s", _("QUERY"));
228 break;
229 default:
230 break;
231 }
232 entries[i].expr = mutt_str_dup(buf_string(entrybuf));
233 entries[i].desc = mutt_str_dup(_(Flags[i].desc));
235 i++;
236 }
238 /* Add struct MuttThread patterns manually.
239 * Note we allocated 3 extra slots for these above. */
241 /* L10N:
242 Pattern Completion Menu argument type: a nested pattern.
243 Used by ~(), ~<(), ~>().
244 */
245 const char *patternstr = _("PATTERN");
247 entries[i].num = i + 1;
248 entries[i].tag = mutt_str_dup("~()");
249 buf_printf(entrybuf, "~(%s)", patternstr);
250 entries[i].expr = mutt_str_dup(buf_string(entrybuf));
251 // L10N: Pattern Completion Menu description for ~()
252 entries[i].desc = mutt_str_dup(_("messages in threads containing messages matching PATTERN"));
253 i++;
255 entries[i].num = i + 1;
256 entries[i].tag = mutt_str_dup("~<()");
257 buf_printf(entrybuf, "~<(%s)", patternstr);
258 entries[i].expr = mutt_str_dup(buf_string(entrybuf));
259 // L10N: Pattern Completion Menu description for ~<()
260 entries[i].desc = mutt_str_dup(_("messages whose immediate parent matches PATTERN"));
261 i++;
263 entries[i].num = i + 1;
264 entries[i].tag = mutt_str_dup("~>()");
265 buf_printf(entrybuf, "~>(%s)", patternstr);
266 entries[i].expr = mutt_str_dup(buf_string(entrybuf));
267 // L10N: Pattern Completion Menu description for ~>()
268 entries[i].desc = mutt_str_dup(_("messages having an immediate child matching PATTERN"));
270 buf_pool_release(&entrybuf);
272 return menu;
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:171
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:214
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
static void make_pattern_entry(struct Menu *menu, char *buf, size_t buflen, int num)
Create a line for the Pattern Completion menu - Implements Menu::make_entry() -.
Definition: dlg_pattern.c:139
static void free_pattern_menu(struct Menu *menu, void **ptr)
Free the Pattern Completion menu - Implements Menu::mdata_free() -.
Definition: dlg_pattern.c:151
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
const struct PatternFlags Flags[]
Lookup table for all patterns.
Definition: flags.c:40
Process a number (range)
Definition: private.h:53
Process a message number (range)
Definition: private.h:54
Process a date (range)
Definition: private.h:52
Process a query string.
Definition: private.h:55
Process a regex.
Definition: private.h:51
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:106
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:119
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
String manipulation buffer.
Definition: buffer.h:34
Definition: lib.h:70
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
void * wdata
Private data.
Definition: mutt_window.h:145
A line in the Pattern Completion menu.
Definition: private.h:36
const char * desc
Description of pattern.
Definition: private.h:40
const char * tag
Copied to buffer if selected.
Definition: private.h:38
int num
Index number.
Definition: private.h:37
const char * expr
Displayed in the menu.
Definition: private.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_select_pattern()

bool dlg_select_pattern ( char *  buf,
size_t  buflen 

Show menu to select a Pattern.

bufBuffer for the selected Pattern
buflenLength of buffer
Return values
trueA selection was made

Definition at line 335 of file dlg_pattern.c.

338 struct Menu *menu = create_pattern_menu(dlg);
340 struct PatternData pd = { false, false, buf, buflen, menu };
341 dlg->wdata = &pd;
343 // NT_COLOR is handled by the SimpleDialog
347 // ---------------------------------------------------------------------------
348 // Event Loop
349 int op = OP_NULL;
350 do
351 {
353 window_redraw(NULL);
355 struct KeyEvent event = km_dokey_event(MENU_GENERIC);
356 if ( == 'q')
357 op = OP_EXIT;
358 else
359 op = event.op;
361 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
362 if (op < 0)
363 continue;
364 if (op == OP_NULL)
365 {
367 continue;
368 }
371 int rc = pattern_function_dispatcher(dlg, op);
373 if (rc == FR_UNKNOWN)
374 rc = menu_function_dispatcher(menu->win, op);
375 if (rc == FR_UNKNOWN)
376 rc = global_function_dispatcher(NULL, op);
377 } while (!pd.done);
378 // ---------------------------------------------------------------------------
380 simple_dialog_free(&dlg);
381 return pd.selection;
Unknown function.
Definition: dispatcher.h:33
static const struct Mapping PatternHelp[]
Help Bar for the Pattern selection dialog.
Definition: dlg_pattern.c:89
static struct Menu * create_pattern_menu(struct MuttWindow *dlg)
Create the Pattern Completion menu.
Definition: dlg_pattern.c:170
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int pattern_function_dispatcher(struct MuttWindow *win, int op)
Perform a Pattern function - Implements function_dispatcher_t -.
Definition: functions.c:78
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:317
#define mutt_debug(LEVEL,...)
Definition: logging2.h:84
static int pattern_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlg_pattern.c:306
static int pattern_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_pattern.c:280
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
struct KeyEvent km_dokey_event(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:643
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1077
Log at debug level 1.
Definition: logging2.h:40
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:605
Pattern Dialog, create_pattern_menu()
Definition: mutt_window.h:87
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
An event such as a keypress.
Definition: keymap.h:65
int op
Function opcode, e.g. OP_HELP.
Definition: keymap.h:67
int ch
Raw key pressed.
Definition: keymap.h:66
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Data to pass to the Pattern Functions.
Definition: functions.h:35
char * buf
Buffer for the results.
Definition: functions.h:38
struct Menu * menu
Pattern Menu.
Definition: functions.h:40
bool done
Should we close the Dialog?
Definition: functions.h:36
size_t buflen
Length of the results buffer.
Definition: functions.h:39
bool selection
Was a selection made?
Definition: functions.h:37
Generic selection list.
Definition: type.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ PatternHelp

const struct Mapping PatternHelp[]
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
#define N_(a)
Definition: message.h:32

Help Bar for the Pattern selection dialog.

Definition at line 89 of file dlg_pattern.c.