NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
Go to the documentation of this file.
58#include "config.h"
59#include <stdbool.h>
60#include <stdint.h>
61#include <stdio.h>
62#include "mutt/lib.h"
63#include "core/lib.h"
64#include "gui/lib.h"
65#include "lib.h"
66#include "menu/lib.h"
67#include "format_flags.h"
68#include "functions.h"
69#include "keymap.h"
70#include "mutt_logging.h"
71#include "muttlib.h"
72#include "opcodes.h"
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
92static const char *history_format_str(char *buf, size_t buflen, size_t col, int cols,
93 char op, const char *src, const char *prec,
94 const char *if_str, const char *else_str,
95 intptr_t data, MuttFormatFlags flags)
97 char *match = (char *) data;
99 switch (op)
100 {
101 case 's':
102 mutt_format_s(buf, buflen, prec, match);
103 break;
104 }
106 return src;
114static void history_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
116 char *entry = ((char **) menu->mdata)[line];
118 mutt_expando_format(buf, buflen, 0, menu->win->state.cols, "%s", history_format_str,
119 (intptr_t) entry, MUTT_FORMAT_ARROWCURSOR);
129void dlg_select_history(char *buf, size_t buflen, char **matches, int match_count)
133 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
134 char title[256] = { 0 };
135 snprintf(title, sizeof(title), _("History '%s'"), buf);
136 sbar_set_title(sbar, title);
138 struct Menu *menu = dlg->wdata;
140 menu->max = match_count;
141 menu->mdata = matches;
142 menu->mdata_free = NULL; // Menu doesn't own the data
144 struct HistoryData hd = { false, false, buf, buflen,
146 dlg->wdata = &hd;
148 // ---------------------------------------------------------------------------
149 // Event Loop
150 int op = OP_NULL;
151 do
152 {
154 window_redraw(NULL);
156 struct KeyEvent event = km_dokey_event(MENU_GENERIC);
157 if ( == 'q')
158 op = OP_EXIT;
159 else
160 op = event.op;
162 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
163 if (op < 0)
164 continue;
165 if (op == OP_NULL)
166 {
168 continue;
169 }
172 int rc = history_function_dispatcher(dlg, op);
174 if (rc == FR_UNKNOWN)
175 rc = menu_function_dispatcher(menu->win, op);
176 if (rc == FR_UNKNOWN)
177 rc = global_function_dispatcher(NULL, op);
178 } while (!hd.done);
179 // ---------------------------------------------------------------------------
181 simple_dialog_free(&dlg);
Convenience wrapper for the core headers.
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:794
Unknown function.
Definition: dispatcher.h:33
static const struct Mapping HistoryHelp[]
Help Bar for the History Selection dialog.
Definition: dlg_history.c:75
void dlg_select_history(char *buf, size_t buflen, char **matches, int match_count)
Select an item from a history list.
Definition: dlg_history.c:129
Flags to control mutt_expando_format()
Reserve space for arrow_cursor.
Definition: format_flags.h:35
uint8_t MuttFormatFlags
Flags for mutt_expando_format(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: format_flags.h:29
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
int history_function_dispatcher(struct MuttWindow *win, int op)
Perform a History function - Implements function_dispatcher_t -.
Definition: functions.c:76
static const char * history_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the history list - Implements format_t -.
Definition: dlg_history.c:92
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
Definition: muttlib.c:726
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static void history_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the history list - Implements Menu::make_entry() -.
Definition: dlg_history.c:114
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
struct KeyEvent km_dokey_event(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:637
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1065
Manage keymappings.
Log at debug level 1.
Definition: logging.h:40
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:73
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:605
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
History Dialog, dlg_select_history()
Definition: mutt_window.h:85
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
Some miscellaneous functions.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
All user-callable functions.
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
Sidebar functions.
Key value store.
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
An event such as a keypress.
Definition: keymap.h:65
int op
Function opcode, e.g. OP_HELP.
Definition: keymap.h:67
int ch
Raw key pressed.
Definition: keymap.h:66
Mapping between user-readable string and a constant.
Definition: mapping.h:32
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * wdata
Private data.
Definition: mutt_window.h:145
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
Generic selection list.
Definition: type.h:45