NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_history.c
Go to the documentation of this file.
1
23
58
59#include "config.h"
60#include <stdbool.h>
61#include <stdio.h>
62#include "mutt/lib.h"
63#include "config/lib.h"
64#include "core/lib.h"
65#include "gui/lib.h"
66#include "lib.h"
67#include "expando/lib.h"
68#include "key/lib.h"
69#include "menu/lib.h"
70#include "expando.h"
71#include "functions.h"
72#include "mutt_logging.h"
73
75static const struct Mapping HistoryHelp[] = {
76 // clang-format off
77 { N_("Exit"), OP_EXIT },
78 { N_("Select"), OP_GENERIC_SELECT_ENTRY },
79 { N_("Search"), OP_SEARCH },
80 { N_("Help"), OP_HELP },
81 { NULL, 0 },
82 // clang-format on
83};
84
88static int history_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
89{
90 struct HistoryData *hd = menu->mdata;
91
92 const char **pentry = ARRAY_GET(hd->matches, line);
93 if (!pentry)
94 return 0;
95
96 struct HistoryEntry h = { line, *pentry };
97
98 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
99 if (c_arrow_cursor)
100 {
101 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
102 if (max_cols > 0)
103 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
104 }
105
106 const struct Expando *c_history_format = cs_subset_expando(NeoMutt->sub, "history_format");
107 return expando_filter(c_history_format, HistoryRenderCallbacks, &h,
108 MUTT_FORMAT_ARROWCURSOR, max_cols, NeoMutt->env, buf);
109}
110
119void dlg_history(struct Buffer *buf, struct StringArray *matches)
120{
122 struct Menu *menu = sdw.menu;
123
124 struct HistoryData hd = { false, false, buf, menu, matches };
125
126 char title[256] = { 0 };
127 snprintf(title, sizeof(title), _("History '%s'"), buf_string(buf));
128 sbar_set_title(sdw.sbar, title);
129
132 menu->mdata = &hd;
133 menu->mdata_free = NULL; // Menu doesn't own the data
134
135 struct MuttWindow *old_focus = window_set_focus(menu->win);
136 // ---------------------------------------------------------------------------
137 // Event Loop
138 int op = OP_NULL;
139 struct KeyEvent event = { 0, OP_NULL };
140 do
141 {
142 menu_tagging_dispatcher(menu->win, &event);
143 window_redraw(NULL);
144
146 op = event.op;
147 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
148 if (op < 0)
149 continue;
150 if (op == OP_NULL)
151 {
153 continue;
154 }
156
157 int rc = history_function_dispatcher(sdw.dlg, &event);
158 if (rc == FR_UNKNOWN)
159 rc = menu_function_dispatcher(menu->win, &event);
160 if (rc == FR_UNKNOWN)
161 rc = global_function_dispatcher(menu->win, &event);
162 } while (!hd.done);
163 // ---------------------------------------------------------------------------
164
165 window_set_focus(old_focus);
167}
#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:444
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
static const struct Mapping HistoryHelp[]
Help Bar for the History Selection dialog.
Definition dlg_history.c:75
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:434
void km_error_key(const struct MenuDefinition *md)
Handle an unbound key sequence.
Definition get.c:285
#define GETCH_NO_FLAGS
No flags are set.
Definition get.h:34
int menu_tagging_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition tagging.c:230
int global_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Global function - Implements function_dispatcher_t -.
Definition global.c:182
int menu_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Menu function - Implements function_dispatcher_t -.
Definition functions.c:320
int history_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a History function - Implements function_dispatcher_t -.
Definition functions.c:81
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:88
struct MenuDefinition * MdDialog
Dialog Menu Definition.
Definition functions.c:53
struct MenuDefinition * MdGeneric
Generic Menu Definition.
Definition functions.c:50
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_DEBUG1
Log at debug level 1.
Definition logging2.h:45
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
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
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition render.h:37
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
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:70
An event such as a keypress.
Definition get.h:50
int op
Function opcode, e.g. OP_HELP.
Definition get.h:52
Mapping between user-readable string and a constant.
Definition mapping.h:33
Definition lib.h:80
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:88
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:163
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition lib.h:108
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:89
void * mdata
Private data.
Definition lib.h:149
int max
Number of entries in the menu.
Definition lib.h:82
Container for Accounts, Notifications.
Definition neomutt.h:41
char ** env
Private copy of the environment variables.
Definition neomutt.h:58
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
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