NeoMutt  2024-03-23-23-gec7045
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
global.c
Go to the documentation of this file.
1
31#include "config.h"
32#include <stddef.h>
33#include <stdbool.h>
34#include <stdio.h>
35#include "mutt/lib.h"
36#include "core/lib.h"
37#include "global.h"
38#include "index/lib.h"
39#include "key/lib.h"
40#include "pager/lib.h"
41#include "external.h"
42#include "mutt_curses.h"
43#include "mutt_mailbox.h"
44#include "mutt_window.h"
45#include "muttlib.h"
46#include "opcodes.h"
47
51static int op_check_stats(int op)
52{
55 return FR_SUCCESS;
56}
57
61static int op_enter_command(int op)
62{
64 window_redraw(NULL);
65 return FR_SUCCESS;
66}
67
71static int op_redraw(int op)
72{
73 clearok(stdscr, true);
76 window_redraw(NULL);
77 return FR_SUCCESS;
78}
79
83static int op_shell_escape(int op)
84{
86 {
87 struct Mailbox *m_cur = get_current_mailbox();
88 m_cur->last_checked = 0; // force a check on the next mx_mbox_check() call
90 }
91 return FR_SUCCESS;
92}
93
97static int op_show_log_messages(int op)
98{
99 struct Buffer *tempfile = buf_pool_get();
100 buf_mktemp(tempfile);
101
102 FILE *fp = mutt_file_fopen(buf_string(tempfile), "a+");
103 if (!fp)
104 {
105 mutt_perror("fopen");
106 buf_pool_release(&tempfile);
107 return FR_ERROR;
108 }
109
110 log_queue_save(fp);
111 mutt_file_fclose(&fp);
112
113 struct PagerData pdata = { 0 };
114 struct PagerView pview = { &pdata };
115
116 pdata.fname = buf_string(tempfile);
117
118 pview.banner = "messages";
120 pview.mode = PAGER_MODE_OTHER;
121
122 mutt_do_pager(&pview, NULL);
123 buf_pool_release(&tempfile);
124
125 return FR_SUCCESS;
126}
127
131static int op_version(int op)
132{
134 return FR_SUCCESS;
135}
136
140static int op_what_key(int op)
141{
142 mw_what_key();
143 return FR_SUCCESS;
144}
145
146// -----------------------------------------------------------------------------
147
151static const struct GlobalFunction GlobalFunctions[] = {
152 // clang-format off
153 { OP_CHECK_STATS, op_check_stats },
154 { OP_ENTER_COMMAND, op_enter_command },
155 { OP_REDRAW, op_redraw },
156 { OP_SHELL_ESCAPE, op_shell_escape },
157 { OP_SHOW_LOG_MESSAGES, op_show_log_messages },
158 { OP_VERSION, op_version },
159 { OP_WHAT_KEY, op_what_key },
160 { 0, NULL },
161 // clang-format on
162};
163
170{
171 int rc = FR_UNKNOWN;
172 for (size_t i = 0; GlobalFunctions[i].op != OP_NULL; i++)
173 {
174 const struct GlobalFunction *fn = &GlobalFunctions[i];
175 if (fn->op == op)
176 {
177 rc = fn->function(op);
178 break;
179 }
180 }
181
182 if (rc == FR_UNKNOWN) // Not our function
183 return rc;
184
185 const char *result = dispatcher_get_retval_name(rc);
186 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
187
188 return FR_SUCCESS; // Whatever the outcome, we handled it
189}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
Convenience wrapper for the core headers.
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:39
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
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:123
void mutt_enter_command(void)
Enter a neomutt command.
Definition: external.c:622
bool mutt_shell_escape(void)
Invoke a command in a subshell.
Definition: external.c:580
Manage where the email is piped to external commands.
#define mutt_file_fclose(FP)
Definition: file.h:148
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:147
static const struct GlobalFunction GlobalFunctions[]
All the NeoMutt functions that the Global supports.
Definition: global.c:151
Global functions.
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:169
static int op_redraw(int op)
Clear and redraw the screen - Implements global_function_t -.
Definition: global.c:71
static int op_check_stats(int op)
Calculate message statistics for all mailboxes - Implements global_function_t -.
Definition: global.c:51
static int op_enter_command(int op)
Enter a neomuttrc command - Implements global_function_t -.
Definition: global.c:61
static int op_shell_escape(int op)
Invoke a command in a subshell - Implements global_function_t -.
Definition: global.c:83
static int op_show_log_messages(int op)
Show log (and debug) messages - Implements global_function_t -.
Definition: global.c:97
static int op_what_key(int op)
display the keycode for a key press - Implements global_function_t -
Definition: global.c:140
static int op_version(int op)
Show the NeoMutt version number - Implements global_function_t -.
Definition: global.c:131
void mw_what_key(void)
Display the value of a key -.
Definition: curs_lib.c:501
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
GUI manage the main index (list of emails)
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:715
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
Convenience wrapper for the library headers.
int log_queue_save(FILE *fp)
Save the contents of the queue to a temporary file.
Definition: logging.c:367
Define wrapper functions around Curses.
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size.
Definition: resize.c:75
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:168
Mailbox helper functions.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:634
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:767
Window management.
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Definition: muttlib.c:893
Some miscellaneous functions.
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Ignore MailboxType and calculate statistics.
Definition: mxapi.h:55
#define MUTT_MAILBOX_CHECK_FORCE
Ignore MailboxTime and check for new mail.
Definition: mxapi.h:54
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:74
#define MUTT_PAGER_BOTTOM
Start at the bottom.
Definition: lib.h:75
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:142
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define NONULL(x)
Definition: string2.h:37
String manipulation buffer.
Definition: buffer.h:36
A NeoMutt function.
Definition: global.h:43
global_function_t function
Function to call.
Definition: global.h:45
int op
Op code, e.g. OP_GLOBAL_NEXT.
Definition: global.h:44
A mailbox.
Definition: mailbox.h:79
time_t last_checked
Last time we checked this mailbox for new mail.
Definition: mailbox.h:105
Data to be displayed by PagerView.
Definition: lib.h:161
const char * fname
Name of the file to read.
Definition: lib.h:165
Paged view into some data.
Definition: lib.h:172
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:173
enum PagerMode mode
Pager mode.
Definition: lib.h:174
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:175
const char * banner
Title to display in status bar.
Definition: lib.h:176
#define buf_mktemp(buf)
Definition: tmp.h:33