NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
global.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include <limits.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 "lib.h"
38#include "index/lib.h"
39#include "pager/lib.h"
40#include "commands.h"
41#include "keymap.h"
42#include "mutt_mailbox.h"
43#include "muttlib.h"
44#include "opcodes.h"
45
49static int op_check_stats(int op)
50{
53 return FR_SUCCESS;
54}
55
59static int op_enter_command(int op)
60{
62 window_redraw(NULL);
63 return FR_SUCCESS;
64}
65
69static int op_redraw(int op)
70{
71 clearok(stdscr, true);
74 window_redraw(NULL);
75 return FR_SUCCESS;
76}
77
81static int op_shell_escape(int op)
82{
84 {
85 struct Mailbox *m_cur = get_current_mailbox();
87 }
88 return FR_SUCCESS;
89}
90
94static int op_show_log_messages(int op)
95{
96 char tempfile[PATH_MAX] = { 0 };
97 mutt_mktemp(tempfile, sizeof(tempfile));
98
99 FILE *fp = mutt_file_fopen(tempfile, "a+");
100 if (!fp)
101 {
102 mutt_perror("fopen");
103 return FR_ERROR;
104 }
105
106 log_queue_save(fp);
107 mutt_file_fclose(&fp);
108
109 struct PagerData pdata = { 0 };
110 struct PagerView pview = { &pdata };
111
112 pdata.fname = tempfile;
113
114 pview.banner = "messages";
116 pview.mode = PAGER_MODE_OTHER;
117
118 mutt_do_pager(&pview, NULL);
119
120 return FR_SUCCESS;
121}
122
126static int op_version(int op)
127{
129 return FR_SUCCESS;
130}
131
135static int op_what_key(int op)
136{
138 return FR_SUCCESS;
139}
140
141// -----------------------------------------------------------------------------
142
147 // clang-format off
148 { OP_CHECK_STATS, op_check_stats },
149 { OP_ENTER_COMMAND, op_enter_command },
150 { OP_REDRAW, op_redraw },
151 { OP_SHELL_ESCAPE, op_shell_escape },
152 { OP_SHOW_LOG_MESSAGES, op_show_log_messages },
153 { OP_VERSION, op_version },
154 { OP_WHAT_KEY, op_what_key },
155 { 0, NULL },
156 // clang-format on
157};
158
165{
166 int rc = FR_UNKNOWN;
167 for (size_t i = 0; GlobalFunctions[i].op != OP_NULL; i++)
168 {
169 const struct GlobalFunction *fn = &GlobalFunctions[i];
170 if (fn->op == op)
171 {
172 rc = fn->function(op);
173 break;
174 }
175 }
176
177 if (rc == FR_UNKNOWN) // Not our function
178 return rc;
179
180 const char *result = dispacher_get_retval_name(rc);
181 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
182
183 return FR_SUCCESS; // Whatever the outcome, we handled it
184}
void mutt_enter_command(void)
Enter a neomutt command.
Definition: commands.c:641
bool mutt_shell_escape(void)
Invoke a command in a subshell.
Definition: commands.c:599
Manage where the email is piped to external commands.
Convenience wrapper for the core headers.
const char * dispacher_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
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:618
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
struct GlobalFunction GlobalFunctions[]
All the NeoMutt functions that the Global supports.
Definition: global.c:146
Global functions.
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
static int op_redraw(int op)
Clear and redraw the screen - Implements global_function_t -.
Definition: global.c:69
static int op_check_stats(int op)
Calculate message statistics for all mailboxes - Implements global_function_t -.
Definition: global.c:49
static int op_enter_command(int op)
Enter a neomuttrc command - Implements global_function_t -.
Definition: global.c:59
static int op_shell_escape(int op)
Invoke a command in a subshell - Implements global_function_t -.
Definition: global.c:81
static int op_show_log_messages(int op)
Show log (and debug) messages - Implements global_function_t -.
Definition: global.c:94
static int op_what_key(int op)
display the keycode for a key press - Implements global_function_t -
Definition: global.c:135
static int op_version(int op)
Show the NeoMutt version number - Implements global_function_t -.
Definition: global.c:126
#define mutt_message(...)
Definition: logging.h:86
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
#define mutt_perror(...)
Definition: logging.h:88
GUI manage the main index (list of emails)
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:624
void mutt_what_key(void)
Ask the user to press a key.
Definition: keymap.c:1638
Manage keymappings.
int log_queue_save(FILE *fp)
Save the contents of the queue to a temporary file.
Definition: logging.c:367
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
Convenience wrapper for the library headers.
#define PATH_MAX
Definition: mutt.h:40
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size (CURSES)
Definition: resize.c:73
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:156
Mailbox helper functions.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:604
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:742
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Definition: muttlib.c:1470
Some miscellaneous functions.
#define mutt_mktemp(buf, buflen)
Definition: muttlib.h:71
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Ignore MailboxType and calculate statistics.
Definition: mxapi.h:76
#define MUTT_MAILBOX_CHECK_FORCE
Ignore MailboxTime and check for new mail.
Definition: mxapi.h:75
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
All user-callable functions.
GUI display a file/email/help in a viewport with paging.
#define MUTT_PAGER_LOGS
Logview mode.
Definition: lib.h:72
#define MUTT_PAGER_BOTTOM
Start at the bottom.
Definition: lib.h:73
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:139
Key value store.
#define NONULL(x)
Definition: string2.h:37
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
Data to be displayed by PagerView.
Definition: lib.h:158
const char * fname
Name of the file to read.
Definition: lib.h:162
Paged view into some data.
Definition: lib.h:169
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:170
enum PagerMode mode
Pager mode.
Definition: lib.h:171
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:172
const char * banner
Title to display in status bar.
Definition: lib.h:173