NeoMutt  2024-12-12-14-g7b49f7
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 "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, buf);
109}
110
119void dlg_history(struct Buffer *buf, struct HistoryArray *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 do
140 {
141 menu_tagging_dispatcher(menu->win, op);
142 window_redraw(NULL);
143
145 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
146 if (op < 0)
147 continue;
148 if (op == OP_NULL)
149 {
151 continue;
152 }
154
155 int rc = history_function_dispatcher(sdw.dlg, op);
156 if (rc == FR_UNKNOWN)
157 rc = menu_function_dispatcher(menu->win, op);
158 if (rc == FR_UNKNOWN)
159 rc = global_function_dispatcher(NULL, op);
160 } while (!hd.done);
161 // ---------------------------------------------------------------------------
162
163 window_set_focus(old_focus);
165}
#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.
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:75
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, 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:79
void dlg_history(struct Buffer *buf, struct HistoryArray *matches)
Select an item from a history list -.
Definition: dlg_history.c:119
#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:88
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
const struct ExpandoRenderCallback HistoryRenderCallbacks[]
Callbacks for History Expandos.
Definition: expando.c:63
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:634
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:684
@ WT_DLG_HISTORY
History Dialog, dlg_history()
Definition: mutt_window.h:86
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
Sidebar Expando definitions.
Sidebar functions.
Key value store.
String manipulation buffer.
Definition: buffer.h:36
Parsed Expando trees.
Definition: expando.h:41
Data to pass to the History Functions.
Definition: functions.h:37
struct Menu * menu
History Menu.
Definition: functions.h:41
struct Buffer * buf
Buffer for the results.
Definition: functions.h:40
struct HistoryArray * matches
History entries.
Definition: functions.h:42
bool done
Should we close the Dialog?
Definition: functions.h:38
A line in the History menu.
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
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