NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
global.c
Go to the documentation of this file.
1
24
30
31#include "config.h"
32#include <stdbool.h>
33#include <stdio.h>
34#include "mutt/lib.h"
35#include "core/lib.h"
36#include "global.h"
37#include "index/lib.h"
38#include "key/lib.h"
39#include "pager/lib.h"
40#include "curs_lib.h"
41#include "external.h"
42#include "mutt_curses.h"
43#include "mutt_mailbox.h"
44#include "mutt_window.h"
45#include "opcodes.h"
46#include "version.h"
47
57
61static int op_enter_command(struct MuttWindow *win, const struct KeyEvent *event)
62{
64 window_redraw(NULL);
65 return FR_SUCCESS;
66}
67
71static int op_redraw(struct MuttWindow *win, const struct KeyEvent *event)
72{
73 clearok(stdscr, true);
76 window_redraw(NULL);
77 return FR_SUCCESS;
78}
79
83static int op_shell_escape(struct MuttWindow *win, const struct KeyEvent *event)
84{
86 {
87 struct Mailbox *m_cur = get_current_mailbox();
88 if (m_cur)
89 {
90 m_cur->last_checked = 0; // force a check on the next mx_mbox_check() call
92 }
93 }
94 return FR_SUCCESS;
95}
96
100static int op_show_log_messages(struct MuttWindow *win, const struct KeyEvent *event)
101{
102 struct Buffer *tempfile = buf_pool_get();
103 buf_mktemp(tempfile);
104
105 FILE *fp = mutt_file_fopen(buf_string(tempfile), "a+");
106 if (!fp)
107 {
108 mutt_perror("fopen");
109 buf_pool_release(&tempfile);
110 return FR_ERROR;
111 }
112
113 char buf[32] = { 0 };
114 struct LogLine *ll = NULL;
115 const struct LogLineList lll = log_queue_get();
116 STAILQ_FOREACH(ll, &lll, entries)
117 {
118 mutt_date_localtime_format(buf, sizeof(buf), "%H:%M:%S", ll->time);
119 fprintf(fp, "[%s]<%c> %s", buf, LogLevelAbbr[ll->level + 3], ll->message);
120 if (ll->level <= LL_MESSAGE)
121 fputs("\n", fp);
122 }
123
124 mutt_file_fclose(&fp);
125
126 struct PagerData pdata = { 0 };
127 struct PagerView pview = { &pdata };
128
129 pdata.fname = buf_string(tempfile);
130
131 pview.banner = "messages";
133 pview.mode = PAGER_MODE_OTHER;
134
135 mutt_do_pager(&pview, NULL);
136 buf_pool_release(&tempfile);
137
138 return FR_SUCCESS;
139}
140
144static int op_version(struct MuttWindow *win, const struct KeyEvent *event)
145{
146 mutt_message("NeoMutt %s", mutt_make_version());
147 return FR_SUCCESS;
148}
149
153static int op_what_key(struct MuttWindow *win, const struct KeyEvent *event)
154{
155 mw_what_key();
156 return FR_SUCCESS;
157}
158
159// -----------------------------------------------------------------------------
160
164static const struct GlobalFunction GlobalFunctions[] = {
165 // clang-format off
166 { OP_CHECK_STATS, op_check_stats },
167 { OP_ENTER_COMMAND, op_enter_command },
168 { OP_REDRAW, op_redraw },
169 { OP_SHELL_ESCAPE, op_shell_escape },
170 { OP_SHOW_LOG_MESSAGES, op_show_log_messages },
171 { OP_VERSION, op_version },
172 { OP_WHAT_KEY, op_what_key },
173 { 0, NULL },
174 // clang-format on
175};
176
182int global_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
183{
184 if (!event || !win)
185 return FR_UNKNOWN;
186
187 const int op = event->op;
188 int rc = FR_UNKNOWN;
189 for (size_t i = 0; GlobalFunctions[i].op != OP_NULL; i++)
190 {
191 const struct GlobalFunction *fn = &GlobalFunctions[i];
192 if (fn->op == op)
193 {
194 rc = fn->function(win, event);
195 break;
196 }
197 }
198
199 if (rc == FR_UNKNOWN) // Not our function
200 return rc;
201
202 const char *result = dispatcher_get_retval_name(rc);
203 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
204
205 return FR_SUCCESS; // Whatever the outcome, we handled it
206}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Convenience wrapper for the core headers.
GUI miscellaneous curses (window drawing) routines.
const char * dispatcher_get_retval_name(int rv)
Get the name of a return value.
Definition dispatcher.c:54
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition do_pager.c:122
bool mutt_shell_escape(void)
Invoke a command in a subshell.
Definition external.c:576
void mutt_enter_command(struct MuttWindow *win)
Enter a neomutt command.
Definition external.c:619
Manage where the email is piped to external commands.
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
static const struct GlobalFunction GlobalFunctions[]
All the NeoMutt functions that the Global supports.
Definition global.c:164
Global functions.
int global_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Global function - Implements function_dispatcher_t -.
Definition global.c:182
static int op_redraw(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Redraw the screen - Implements enter_function_t -.
Definition functions.c:483
static int op_version(struct MuttWindow *win, const struct KeyEvent *event)
Show the NeoMutt version number - Implements global_function_t -.
Definition global.c:144
static int op_enter_command(struct MuttWindow *win, const struct KeyEvent *event)
Enter a neomuttrc command - Implements global_function_t -.
Definition global.c:61
static int op_redraw(struct MuttWindow *win, const struct KeyEvent *event)
Clear and redraw the screen - Implements global_function_t -.
Definition global.c:71
static int op_show_log_messages(struct MuttWindow *win, const struct KeyEvent *event)
Show log (and debug) messages - Implements global_function_t -.
Definition global.c:100
static int op_shell_escape(struct MuttWindow *win, const struct KeyEvent *event)
Invoke a command in a subshell - Implements global_function_t -.
Definition global.c:83
static int op_what_key(struct MuttWindow *win, const struct KeyEvent *event)
display the keycode for a key press - Implements global_function_t -
Definition global.c:153
static int op_check_stats(struct MuttWindow *win, const struct KeyEvent *event)
Calculate message statistics for all mailboxes - Implements global_function_t -.
Definition global.c:51
void mw_what_key(void)
Display the value of a key -.
Definition curs_lib.c:505
#define mutt_message(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
#define mutt_perror(...)
Definition logging2.h:95
GUI manage the main index (list of emails)
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition index.c:726
Manage keymappings.
@ LL_MESSAGE
Log informational message.
Definition logging2.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
size_t mutt_date_localtime_format(char *buf, size_t buflen, const char *format, time_t t)
Format localtime.
Definition date.c:952
Convenience wrapper for the library headers.
struct LogLineList log_queue_get(void)
Get the Log Queue.
Definition logging.c:368
const char * LogLevelAbbr
Abbreviations of logging level names.
Definition logging.c:47
Define wrapper functions around Curses.
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size.
Definition resize.c:76
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Mailbox helper functions.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Window management.
#define MUTT_MAILBOX_CHECK_STATS
Ignore mail_check_stats and calculate statistics (used by <check-stats>)
Definition mxapi.h:51
#define MUTT_MAILBOX_CHECK_POSTPONED
Make sure the number of postponed messages is updated.
Definition mxapi.h:50
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
All user-callable functions.
GUI display a file/email/help in a viewport with paging.
#define MUTT_PAGER_LOGS
Logview mode.
Definition lib.h:75
#define MUTT_PAGER_BOTTOM
Start at the bottom.
Definition lib.h:76
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition lib.h:143
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define NONULL(x)
Definition string2.h:44
String manipulation buffer.
Definition buffer.h:36
A NeoMutt function.
Definition global.h:48
global_function_t function
Function to call.
Definition global.h:50
int op
Op code, e.g. OP_ENTER_COMMAND.
Definition global.h:49
An event such as a keypress.
Definition get.h:50
A Log line.
Definition logging2.h:80
char * message
Message to be logged.
Definition logging2.h:86
enum LogLevel level
Log level, e.g. LL_DEBUG1.
Definition logging2.h:85
time_t time
Timestamp of the message.
Definition logging2.h:81
A mailbox.
Definition mailbox.h:78
time_t last_checked
Last time we checked this mailbox for new mail.
Definition mailbox.h:104
Data to be displayed by PagerView.
Definition lib.h:162
const char * fname
Name of the file to read.
Definition lib.h:166
Paged view into some data.
Definition lib.h:173
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition lib.h:174
enum PagerMode mode
Pager mode.
Definition lib.h:175
PagerFlags flags
Additional settings to tweak pager's function.
Definition lib.h:176
const char * banner
Title to display in status bar.
Definition lib.h:177
#define buf_mktemp(buf)
Definition tmp.h:33
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Definition version.c:293
Display version and copyright about NeoMutt.