NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_history.c
Go to the documentation of this file.
1
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 "functions.h"
71#include "mutt_logging.h"
72
74
76static const struct Mapping HistoryHelp[] = {
77 // clang-format off
78 { N_("Exit"), OP_EXIT },
79 { N_("Select"), OP_GENERIC_SELECT_ENTRY },
80 { N_("Search"), OP_SEARCH },
81 { N_("Help"), OP_HELP },
82 { NULL, 0 },
83 // clang-format on
84};
85
89long history_C_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
90{
91 const struct HistoryEntry *entry = data;
92
93 return entry->num + 1;
94}
95
99void history_s(const struct ExpandoNode *node, void *data,
100 MuttFormatFlags flags, struct Buffer *buf)
101{
102 const struct HistoryEntry *entry = data;
103
104 const char *s = entry->history;
105 buf_strcpy(buf, s);
106}
107
111static int history_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
112{
113 struct HistoryData *hd = menu->mdata;
114
115 const char **pentry = ARRAY_GET(hd->matches, line);
116 if (!pentry)
117 return 0;
118
119 struct HistoryEntry h = { line, *pentry };
120
121 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
122 if (c_arrow_cursor)
123 {
124 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
125 if (max_cols > 0)
126 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
127 }
128
129 const struct Expando *c_history_format = cs_subset_expando(NeoMutt->sub, "history_format");
130 return expando_filter(c_history_format, HistoryRenderData, &h,
131 MUTT_FORMAT_ARROWCURSOR, max_cols, buf);
132}
133
142void dlg_history(struct Buffer *buf, struct HistoryArray *matches)
143{
145 struct Menu *menu = sdw.menu;
146
147 struct HistoryData hd = { false, false, buf, menu, matches };
148
149 char title[256] = { 0 };
150 snprintf(title, sizeof(title), _("History '%s'"), buf_string(buf));
151 sbar_set_title(sdw.sbar, title);
152
155 menu->mdata = &hd;
156 menu->mdata_free = NULL; // Menu doesn't own the data
157
158 struct MuttWindow *old_focus = window_set_focus(menu->win);
159 // ---------------------------------------------------------------------------
160 // Event Loop
161 int op = OP_NULL;
162 do
163 {
164 menu_tagging_dispatcher(menu->win, op);
165 window_redraw(NULL);
166
168 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
169 if (op < 0)
170 continue;
171 if (op == OP_NULL)
172 {
174 continue;
175 }
177
178 int rc = history_function_dispatcher(sdw.dlg, op);
179 if (rc == FR_UNKNOWN)
180 rc = menu_function_dispatcher(menu->win, op);
181 if (rc == FR_UNKNOWN)
182 rc = global_function_dispatcher(NULL, op);
183 } while (!hd.done);
184 // ---------------------------------------------------------------------------
185
186 window_set_focus(old_focus);
188}
189
195const struct ExpandoRenderData HistoryRenderData[] = {
196 // clang-format off
199 { -1, -1, NULL, NULL },
200 // clang-format on
201};
#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
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
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.
Definition: config_type.c:357
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:443
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
static const struct Mapping HistoryHelp[]
Help Bar for the History Selection dialog.
Definition: dlg_history.c:76
const struct ExpandoRenderData HistoryRenderData[]
Callbacks for History Expandos.
Definition: dlg_history.c:73
@ ED_HISTORY
History ED_HIS_ ExpandoDataHistory.
Definition: domain.h:45
int expando_filter(const struct Expando *exp, const struct ExpandoRenderData *rdata, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition: filter.c:138
Parse Expando string.
int km_dokey(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:464
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:294
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:230
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:172
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:318
int history_function_dispatcher(struct MuttWindow *win, int op)
Perform a History function - Implements function_dispatcher_t -.
Definition: functions.c:78
long history_C_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
History: Index number - Implements ExpandoRenderData::get_number() -.
Definition: dlg_history.c:89
void history_s(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
History: History match - Implements ExpandoRenderData::get_string() -.
Definition: dlg_history.c:99
void dlg_history(struct Buffer *buf, struct HistoryArray *matches)
Select an item from a history list -.
Definition: dlg_history.c:142
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
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:111
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:168
struct SimpleDialogWindows simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:132
@ ED_HIS_MATCH
HistoryEntry.history.
Definition: lib.h:80
@ ED_HIS_NUMBER
HistoryEntry.num.
Definition: lib.h:81
Manage keymappings.
#define GETCH_NO_FLAGS
No flags are set.
Definition: lib.h:51
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
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)
Definition: mutt_logging.c:74
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:633
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:683
@ 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
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
Sidebar functions.
Key value store.
String manipulation buffer.
Definition: buffer.h:36
Basic Expando Node.
Definition: node.h:67
Parsed Expando trees.
Definition: expando.h:41
Data to pass to the History Functions.
Definition: functions.h:38
struct Menu * menu
History Menu.
Definition: functions.h:42
struct Buffer * buf
Buffer for the results.
Definition: functions.h:41
struct HistoryArray * matches
History entries.
Definition: functions.h:43
bool done
Should we close the Dialog?
Definition: functions.h:39
A line in the History menu.
Definition: lib.h:68
int num
Index number.
Definition: lib.h:69
const char * history
Description of history.
Definition: lib.h:70
Mapping between user-readable string and a constant.
Definition: mapping.h:33
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition: lib.h:106
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:87
void * mdata
Private data.
Definition: lib.h:147
int max
Number of entries in the menu.
Definition: lib.h:81
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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
@ MENU_DIALOG
Simple Dialog.
Definition: type.h:43
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46