NeoMutt  2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_history.c
Go to the documentation of this file.
1
23
63
64#include "config.h"
65#include <stdbool.h>
66#include <stdio.h>
67#include "mutt/lib.h"
68#include "config/lib.h"
69#include "core/lib.h"
70#include "gui/lib.h"
71#include "lib.h"
72#include "expando/lib.h"
73#include "key/lib.h"
74#include "menu/lib.h"
75#include "expando.h"
76#include "functions.h"
77#include "mutt_logging.h"
78
80static const struct Mapping HistoryHelp[] = {
81 // clang-format off
82 { N_("Exit"), OP_EXIT },
83 { N_("Select"), OP_GENERIC_SELECT_ENTRY },
84 { N_("Search"), OP_SEARCH },
85 { N_("Help"), OP_HELP },
86 { NULL, 0 },
87 // clang-format on
88};
89
93static int history_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
94{
95 struct HistoryData *hd = menu->mdata;
96
97 const char **pentry = ARRAY_GET(hd->matches, line);
98 if (!pentry)
99 return 0;
100
101 struct HistoryEntry h = { line, *pentry };
102
103 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
104 if (c_arrow_cursor)
105 {
106 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
107 if (max_cols > 0)
108 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
109 }
110
111 const struct Expando *c_history_format = cs_subset_expando(NeoMutt->sub, "history_format");
112 return expando_filter(c_history_format, HistoryRenderCallbacks, &h,
113 MUTT_FORMAT_ARROWCURSOR, max_cols, NeoMutt->env, buf);
114}
115
122{
123 if (nc->event_type != NT_CONFIG)
124 return 0;
125 if (!nc->global_data || !nc->event_data)
126 return -1;
127
128 struct EventConfig *ev_c = nc->event_data;
129 if (!mutt_str_equal(ev_c->name, "history_format"))
130 return 0;
131
132 struct Menu *menu = nc->global_data;
134 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
135
136 return 0;
137}
138
147void dlg_history(struct Buffer *buf, struct StringArray *matches)
148{
149 const struct MenuDefinition *md_generic = generic_get_menu_definition();
151 struct Menu *menu = sdw.menu;
152
153 struct HistoryData hd = { false, false, buf, menu, matches };
154
155 char title[256] = { 0 };
156 snprintf(title, sizeof(title), _("History '%s'"), buf_string(buf));
157 sbar_set_title(sdw.sbar, title);
158
161 menu->mdata = &hd;
162 menu->mdata_free = NULL; // Menu doesn't own the data
163
164 // NT_COLOR is handled by the SimpleDialog
166
167 struct MuttWindow *old_focus = window_set_focus(menu->win);
168 // ---------------------------------------------------------------------------
169 // Event Loop
170 int op = OP_NULL;
171 struct KeyEvent event = { 0, OP_NULL };
172 do
173 {
174 menu_tagging_dispatcher(menu->win, &event);
175 window_redraw(NULL);
176
177 event = km_dokey(md_generic, GETCH_NONE);
178 op = event.op;
179 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
180 if (op < 0)
181 continue;
182 if (op == OP_NULL)
183 {
184 km_error_key(md_generic);
185 continue;
186 }
188
189 int rc = history_function_dispatcher(sdw.dlg, &event);
190 if (rc == FR_UNKNOWN)
191 rc = menu_function_dispatcher(menu->win, &event);
192 if (rc == FR_UNKNOWN)
193 rc = global_function_dispatcher(menu->win, &event);
194 } while (!hd.done);
195 // ---------------------------------------------------------------------------
196
197 window_set_focus(old_focus);
200}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
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:449
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
static const struct Mapping HistoryHelp[]
Help Bar for the History Selection dialog.
Definition dlg_history.c:80
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, char **env_list, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition filter.c:139
Parse Expando string.
struct KeyEvent km_dokey(const struct MenuDefinition *md, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:519
void km_error_key(const struct MenuDefinition *md)
Handle an unbound key sequence.
Definition get.c:328
@ GETCH_NONE
No flags are set.
Definition get.h:38
int menu_tagging_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition tagging.c:239
int global_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Global function - Implements function_dispatcher_t -.
Definition global.c:193
int menu_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Menu function - Implements function_dispatcher_t -.
Definition functions.c:366
int history_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a History function - Implements function_dispatcher_t -.
Definition functions.c:85
void dlg_history(struct Buffer *buf, struct StringArray *matches)
Select an item from a history list -.
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int history_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format a History Item for the Menu - Implements Menu::make_entry() -.
Definition dlg_history.c:93
static int history_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
struct MenuDefinition * generic_get_menu_definition(void)
Get the Generic Menu Definition.
Definition functions.c:177
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition simple.c:169
struct SimpleDialogWindows simple_dialog_new(const struct MenuDefinition *md, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition simple.c:132
const struct ExpandoRenderCallback HistoryRenderCallbacks[]
Callbacks for History Expandos.
Definition expando.c:63
History Expando definitions.
History functions.
Read/write command history from/to a file.
Manage keymappings.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
GUI present the user with a selectable list.
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:177
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition notify.c:230
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:191
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:666
void mutt_clear_error(void)
Clear the message line (bottom line of screen).
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
@ WT_DLG_HISTORY
History Dialog, dlg_history().
Definition mutt_window.h:85
@ NT_CONFIG
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
@ MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition render.h:41
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition sbar.c:227
String manipulation buffer.
Definition buffer.h:36
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
A config-change event.
Definition subset.h:70
const char * name
Name of config item that changed.
Definition subset.h:72
Parsed Expando trees.
Definition expando.h:41
Data to pass to the History Functions.
Definition functions.h:35
struct Menu * menu
History Menu.
Definition functions.h:39
struct Buffer * buf
Buffer for the results.
Definition functions.h:38
struct StringArray * matches
History entries.
Definition functions.h:40
bool done
Should we close the Dialog?
Definition functions.h:36
A line in the History menu.
Definition lib.h:71
An event such as a keypress.
Definition get.h:75
int op
Function opcode, e.g. OP_HELP.
Definition get.h:77
Mapping between user-readable string and a constant.
Definition mapping.h:33
Functions for a Dialog or Window.
Definition menudef.h:44
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:169
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
void * mdata
Private data.
Definition lib.h:155
int max
Number of entries in the menu.
Definition lib.h:88
Container for Accounts, Notifications.
Definition neomutt.h:41
char ** env
Private copy of the environment variables.
Definition neomutt.h:57
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
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
void * global_data
Data from notify_observer_add().
Definition observer.h:39
Tuple for the results of simple_dialog_new().
Definition simple.h:35
struct MuttWindow * sbar
Simple Bar.
Definition simple.h:37
struct Menu * menu
Menu.
Definition simple.h:38
struct MuttWindow * dlg
Main Dialog Window.
Definition simple.h:36