NeoMutt  2024-10-02-37-gfa9146
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 char *entry = ((char **) menu->mdata)[line];
114
115 struct HistoryEntry h = { line, entry };
116
117 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
118 if (c_arrow_cursor)
119 {
120 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
121 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
122 }
123
124 const struct Expando *c_history_format = cs_subset_expando(NeoMutt->sub, "history_format");
125 return expando_filter(c_history_format, HistoryRenderData, &h,
126 MUTT_FORMAT_ARROWCURSOR, max_cols, buf);
127}
128
139void dlg_history(char *buf, size_t buflen, char **matches, int match_count)
140{
142
143 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
144 char title[256] = { 0 };
145 snprintf(title, sizeof(title), _("History '%s'"), buf);
146 sbar_set_title(sbar, title);
147
148 struct Menu *menu = dlg->wdata;
150 menu->max = match_count;
151 menu->mdata = matches;
152 menu->mdata_free = NULL; // Menu doesn't own the data
153
154 struct HistoryData hd = { false, false, buf, buflen,
156 dlg->wdata = &hd;
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(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);
187 simple_dialog_free(&dlg);
188}
189
195const struct ExpandoRenderData HistoryRenderData[] = {
196 // clang-format off
199 { -1, -1, NULL, NULL },
200 // clang-format on
201};
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
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:75
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(char *buf, size_t buflen, char **matches, int match_count)
Select an item from a history list -.
Definition: dlg_history.c:139
#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 MuttWindow * 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:77
@ ED_HIS_NUMBER
HistoryEntry.num.
Definition: lib.h:78
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
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:532
@ WT_DLG_HISTORY
History Dialog, dlg_history()
Definition: mutt_window.h:85
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:101
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:35
size_t buflen
Length of the results buffer.
Definition: functions.h:39
struct Menu * menu
History Menu.
Definition: functions.h:40
char ** matches
History entries.
Definition: functions.h:41
bool done
Should we close the Dialog?
Definition: functions.h:36
char * buf
Buffer for the results.
Definition: functions.h:38
int match_count
Number of history entries.
Definition: functions.h:42
A line in the History menu.
Definition: lib.h:65
int num
Index number.
Definition: lib.h:66
const char * history
Description of history.
Definition: lib.h:67
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
void * wdata
Private data.
Definition: mutt_window.h:144
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
@ MENU_DIALOG
Simple Dialog.
Definition: type.h:43
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46