NeoMutt  2025-12-11-980-ge38c27
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
menu.c
Go to the documentation of this file.
1
23
29
30#include "config.h"
31#include <stdbool.h>
32#include <stdio.h>
33#include "private.h"
34#include "mutt/lib.h"
35#include "gui/lib.h"
36#include "lib.h"
37#include "color/lib.h"
38#include "expando/lib.h" // IWYU pragma: keep
39#include "key/lib.h"
40#include "type.h"
41
42struct ConfigSubset;
43
47static const struct AttrColor *default_color(struct Menu *menu, int line)
48{
50}
51
55static int generic_search(struct Menu *menu, regex_t *rx, int line)
56{
57 struct Buffer *buf = buf_pool_get();
58
59 menu->make_entry(menu, line, -1, buf);
60 int rc = regexec(rx, buf->data, 0, NULL, 0);
61 buf_pool_release(&buf);
62
63 return rc;
64}
65
70void menu_init2(char **search_buffers)
71{
72 for (int i = 0; i < MENU_MAX; i++)
73 search_buffers[i] = NULL;
74}
75
81{
82 struct MuttWindow *win = window_get_focus();
83
84 // This should only happen before the first window is created
85 if (!win)
86 return MENU_INDEX;
87
88 if ((win->type == WT_CUSTOM) && (win->parent->type == WT_PAGER))
89 return MENU_PAGER;
90
91 if (win->type != WT_MENU)
92 return MENU_GENERIC;
93
94 struct Menu *menu = win->wdata;
95 if (!menu)
96 return MENU_GENERIC;
97
98 return menu->md->id;
99}
100
105void menu_free(struct Menu **ptr)
106{
107 if (!ptr || !*ptr)
108 return;
109
110 struct Menu *menu = *ptr;
111
112 notify_free(&menu->notify);
113
114 if (menu->mdata_free && menu->mdata)
115 menu->mdata_free(menu, &menu->mdata); // Custom function to free private data
116
117 FREE(ptr);
118}
119
127struct Menu *menu_new(const struct MenuDefinition *md, struct MuttWindow *win,
128 struct ConfigSubset *sub)
129{
130 struct Menu *menu = MUTT_MEM_CALLOC(1, struct Menu);
131
132 menu->md = md;
133 menu->redraw = MENU_REDRAW_FULL;
134 menu->color = default_color;
135 menu->search = generic_search;
136 menu->notify = notify_new();
137 menu->win = win;
138 menu->page_len = win->state.rows;
139 menu->sub = sub;
140 menu->show_indicator = true;
141
143 menu_add_observers(menu);
144
145 return menu;
146}
147
153int menu_get_index(struct Menu *menu)
154{
155 if (!menu)
156 return -1;
157
158 return menu->current;
159}
160
167MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
168{
169 return menu_move_selection(menu, index);
170}
171
178{
179 if (!menu)
180 return;
181
182 menu->redraw |= redraw;
183 menu->win->actions |= WA_RECALC;
184}
Color and attribute parsing.
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition simple.c:98
@ MT_COLOR_NORMAL
Plain text.
Definition color.h:53
Parse Expando string.
static const struct AttrColor * default_color(struct Menu *menu, int line)
Get the default colour for a line of the menu - Implements Menu::color() -.
Definition menu.c:47
static int generic_search(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex - Implements Menu::search() -.
Definition menu.c:55
Convenience wrapper for the gui headers.
Manage keymappings.
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
GUI present the user with a selectable list.
uint8_t MenuRedrawFlags
Definition lib.h:66
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
MenuRedrawFlags menu_move_selection(struct Menu *menu, int index)
Move the selection, keeping within between [0, menu->max].
Definition move.c:236
enum MenuType menu_get_current_type(void)
Get the type of the current Window.
Definition menu.c:80
void menu_init2(char **search_buffers)
Initialise all the Menus.
Definition menu.c:70
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:177
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:153
struct Menu * menu_new(const struct MenuDefinition *md, struct MuttWindow *win, struct ConfigSubset *sub)
Create a new Menu.
Definition menu.c:127
void menu_free(struct Menu **ptr)
Free a Menu.
Definition menu.c:105
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition menu.c:167
void menu_add_observers(struct Menu *menu)
Add the notification observers.
Definition observer.c:137
Private Menu functions.
Convenience wrapper for the library headers.
struct Notify * notify_new(void)
Create a new notifications handler.
Definition notify.c:62
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
@ WT_CUSTOM
Window with a custom drawing function.
Definition mutt_window.h:95
@ WT_PAGER
A panel containing the Pager Window.
@ WT_MENU
An Window containing a Menu.
Definition mutt_window.h:98
@ WA_RECALC
Recalculate the contents of the Window.
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
A curses colour and its attributes.
Definition attr.h:65
String manipulation buffer.
Definition buffer.h:36
char * data
Pointer to data.
Definition buffer.h:37
A set of inherited config items.
Definition subset.h:46
Functions for a Dialog or Window.
Definition menudef.h:44
int id
Menu ID, e.g. MENU_ALIAS.
Definition menudef.h:45
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
int current
Current entry.
Definition lib.h:87
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition lib.h:151
MenuRedrawFlags redraw
When to redraw the screen.
Definition lib.h:89
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:169
bool show_indicator
Show the Indicator colour.
Definition lib.h:93
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition lib.h:127
const struct MenuDefinition * md
Menu definition for keymap entries.
Definition lib.h:90
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition lib.h:114
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:95
struct Notify * notify
Notifications.
Definition lib.h:153
void * mdata
Private data.
Definition lib.h:155
int page_len
Number of entries per screen.
Definition lib.h:91
struct WindowState state
Current state of the Window.
void * wdata
Private data.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
struct MuttWindow * parent
Parent Window.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:61
Menu types.
MenuType
Types of GUI selections.
Definition type.h:33
@ MENU_INDEX
Index panel (list of emails)
Definition type.h:45
@ MENU_GENERIC
Generic selection list.
Definition type.h:44
@ MENU_PAGER
Pager pager (email viewer)
Definition type.h:47
@ MENU_MAX
Definition type.h:53