NeoMutt  2025-12-11-87-gae07fd
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
get.h File Reference

Get a key from the user. More...

#include <stdint.h>
#include "mutt/lib.h"
#include "menu/lib.h"
#include "keymap.h"
+ Include dependency graph for get.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KeyEvent
 An event such as a keypress. More...
 

Macros

#define GETCH_NO_FLAGS   0
 No flags are set.
 
#define GETCH_IGNORE_MACRO   (1 << 0)
 Don't use MacroEvents.
 
#define MFF_NO_FLAGS   0
 No flags are set.
 
#define MFF_DEPRECATED   (1 << 1)
 Redraw the pager.
 

Typedefs

typedef uint8_t GetChFlags
 Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.
 
typedef uint8_t MenuFuncFlags
 Flags, e.g. MFF_DEPRECATED.
 

Functions

 ARRAY_HEAD (KeyEventArray, struct KeyEvent)
 
void array_add (struct KeyEventArray *a, int ch, int op)
 Add an event to the end of the array.
 
struct KeyEventarray_pop (struct KeyEventArray *a)
 Remove an event from the array.
 
void array_to_endcond (struct KeyEventArray *a)
 Clear the array until an OP_END_COND.
 
void generic_tokenize_push_string (char *s)
 Parse and queue a 'push' command.
 
void mutt_flushinp (void)
 Empty all the keyboard buffers.
 
void mutt_flush_macro_to_endcond (void)
 Drop a macro from the input buffer.
 
struct KeyEvent mutt_getch (GetChFlags flags)
 Read a character from the input buffer.
 
void mutt_push_macro_event (int ch, int op)
 Add the character/operation to the macro buffer.
 
void mutt_unget_ch (int ch)
 Return a keystroke to the input buffer.
 
void mutt_unget_op (int op)
 Return an operation to the input buffer.
 
void mutt_unget_string (const char *s)
 Return a string to the input buffer.
 

Variables

struct KeyEventArray MacroEvents
 These are used for macros and exec/push commands.
 
struct KeyEventArray UngetKeyEvents
 These are used in all other "normal" situations, and are not ignored when passing GETCH_IGNORE_MACRO.
 

Detailed Description

Get a key from the user.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file get.h.

Macro Definition Documentation

◆ GETCH_NO_FLAGS

#define GETCH_NO_FLAGS   0

No flags are set.

Definition at line 32 of file get.h.

◆ GETCH_IGNORE_MACRO

#define GETCH_IGNORE_MACRO   (1 << 0)

Don't use MacroEvents.

Definition at line 33 of file get.h.

◆ MFF_NO_FLAGS

#define MFF_NO_FLAGS   0

No flags are set.

Definition at line 36 of file get.h.

◆ MFF_DEPRECATED

#define MFF_DEPRECATED   (1 << 1)

Redraw the pager.

Definition at line 37 of file get.h.

Typedef Documentation

◆ GetChFlags

typedef uint8_t GetChFlags

Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.

Definition at line 31 of file get.h.

◆ MenuFuncFlags

typedef uint8_t MenuFuncFlags

Flags, e.g. MFF_DEPRECATED.

Definition at line 35 of file get.h.

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( KeyEventArray ,
struct KeyEvent  )
+ Here is the call graph for this function:

◆ array_add()

void array_add ( struct KeyEventArray * a,
int ch,
int op )

Add an event to the end of the array.

Parameters
aArray
chCharacter
opOperation, e.g. OP_DELETE

Definition at line 88 of file get.c.

89{
90 struct KeyEvent event = { ch, op };
91 ARRAY_ADD(a, event);
92}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:156
An event such as a keypress.
Definition get.h:43
int op
Function opcode, e.g. OP_HELP.
Definition get.h:45
int ch
Raw key pressed.
Definition get.h:44
+ Here is the caller graph for this function:

◆ array_pop()

struct KeyEvent * array_pop ( struct KeyEventArray * a)

Remove an event from the array.

Parameters
aArray
Return values
ptrEvent

Definition at line 70 of file get.c.

71{
72 if (ARRAY_EMPTY(a))
73 {
74 return NULL;
75 }
76
77 struct KeyEvent *event = ARRAY_LAST(a);
78 ARRAY_SHRINK(a, 1);
79 return event;
80}
#define ARRAY_SHRINK(head, num)
Mark a number of slots at the end of the array as unused.
Definition array.h:172
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition array.h:144
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
+ Here is the caller graph for this function:

◆ array_to_endcond()

void array_to_endcond ( struct KeyEventArray * a)

Clear the array until an OP_END_COND.

Parameters
aArray

Definition at line 98 of file get.c.

99{
100 while (!ARRAY_EMPTY(a))
101 {
102 if (array_pop(a)->op == OP_END_COND)
103 {
104 return;
105 }
106 }
107}
struct KeyEvent * array_pop(struct KeyEventArray *a)
Remove an event from the array.
Definition get.c:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generic_tokenize_push_string()

void generic_tokenize_push_string ( char * s)

Parse and queue a 'push' command.

Parameters
sString to push into the key queue

Parses s for <function> syntax and adds the whole sequence the macro buffer.

Definition at line 348 of file get.c.

349{
350 char *pp = NULL;
351 char *p = s + mutt_str_len(s) - 1;
352 size_t l;
353 int i, op = OP_NULL;
354
355 while (p >= s)
356 {
357 /* if we see something like "<PageUp>", look to see if it is a real
358 * function name and return the corresponding value */
359 if (*p == '>')
360 {
361 for (pp = p - 1; pp >= s && *pp != '<'; pp--)
362 ; // do nothing
363
364 if (pp >= s)
365 {
366 i = parse_fkey(pp);
367 if (i > 0)
368 {
369 mutt_push_macro_event(KEY_F(i), 0);
370 p = pp - 1;
371 continue;
372 }
373
374 l = p - pp + 1;
375 for (i = 0; KeyNames[i].name; i++)
376 {
377 if (mutt_istrn_equal(pp, KeyNames[i].name, l))
378 break;
379 }
380 if (KeyNames[i].name)
381 {
382 /* found a match */
383 mutt_push_macro_event(KeyNames[i].value, 0);
384 p = pp - 1;
385 continue;
386 }
387
388 /* See if it is a valid command
389 * skip the '<' and the '>' when comparing */
390 for (enum MenuType j = 0; MenuNames[j].name; j++)
391 {
392 const struct MenuFuncOp *funcs = km_get_table(MenuNames[j].value);
393 if (funcs)
394 {
395 op = km_get_op(funcs, pp + 1, l - 2);
396 if (op != OP_NULL)
397 break;
398 }
399 }
400
401 if (op != OP_NULL)
402 {
404 p = pp - 1;
405 continue;
406 }
407 }
408 }
409 mutt_push_macro_event((unsigned char) *p--, 0); /* independent 8 bits chars */
410 }
411}
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition get.c:155
int parse_fkey(char *str)
Parse a function key string.
Definition keymap.c:263
struct Mapping KeyNames[]
Key name lookup table.
Definition keymap.c:42
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition lib.c:86
int km_get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition menu.c:63
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:500
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition string.c:457
Mapping between a function and an operation.
Definition menu.h:37
int op
Operation, e.g. OP_DELETE.
Definition menu.h:39
const struct Mapping MenuNames[]
Menu name lookup table.
Definition type.c:37
MenuType
Types of GUI selections.
Definition type.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_flushinp()

void mutt_flushinp ( void )

Empty all the keyboard buffers.

Definition at line 58 of file get.c.

59{
62 flushinp();
63}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
struct KeyEventArray MacroEvents
These are used for macros and exec/push commands.
Definition get.c:49
struct KeyEventArray UngetKeyEvents
These are used in all other "normal" situations, and are not ignored when passing GETCH_IGNORE_MACRO.
Definition get.c:53
+ Here is the caller graph for this function:

◆ mutt_flush_macro_to_endcond()

void mutt_flush_macro_to_endcond ( void )

Drop a macro from the input buffer.

All the macro text is deleted until an OP_END_COND command, or the buffer is empty.

Definition at line 166 of file get.c.

167{
169}
void array_to_endcond(struct KeyEventArray *a)
Clear the array until an OP_END_COND.
Definition get.c:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_getch()

struct KeyEvent mutt_getch ( GetChFlags flags)

Read a character from the input buffer.

Parameters
flagsFlags, e.g. GETCH_IGNORE_MACRO
Return values
objKeyEvent to process

The priority for reading events is:

  1. UngetKeyEvents buffer
  2. MacroEvents buffer
  3. Keyboard

This function can return:

  • Abort { 0, OP_ABORT }
  • Repaint { 0, OP_REPAINT }
  • Timeout { 0, OP_TIMEOUT }

Definition at line 210 of file get.c.

211{
212 static const struct KeyEvent event_abort = { 0, OP_ABORT };
213 static const struct KeyEvent event_repaint = { 0, OP_REPAINT };
214 static const struct KeyEvent event_timeout = { 0, OP_TIMEOUT };
215
216 if (!OptGui)
217 return event_abort;
218
219 struct KeyEvent *event_key = array_pop(&UngetKeyEvents);
220 if (event_key)
221 return *event_key;
222
223 if (!(flags & GETCH_IGNORE_MACRO))
224 {
225 event_key = array_pop(&MacroEvents);
226 if (event_key)
227 return *event_key;
228 }
229
230 int ch;
231 SigInt = false;
233 timeout(1000); // 1 second
234#ifdef USE_INOTIFY
236#else
237 ch = getch();
238#endif
240
241 if (SigInt)
242 {
244 return event_abort;
245 }
246
247 if (ch == KEY_RESIZE)
248 {
249 timeout(0);
250 while ((ch = getch()) == KEY_RESIZE)
251 {
252 // do nothing
253 }
254 }
255
256 if (ch == ERR)
257 {
258 if (!isatty(STDIN_FILENO)) // terminal was lost
259 mutt_exit(1);
260
261 if (SigWinch)
262 {
263 SigWinch = false;
265 return event_repaint;
266 }
267
269 return event_timeout;
270 }
271
272 if (ch == AbortKey)
273 return event_abort;
274
275 if (ch & 0x80)
276 {
277 const bool c_meta_key = cs_subset_bool(NeoMutt->sub, "meta_key");
278 if (c_meta_key)
279 {
280 /* send ALT-x as ESC-x */
281 ch &= ~0x80;
283 return (struct KeyEvent) { '\033', OP_NULL }; // Escape
284 }
285 }
286
287 return (struct KeyEvent) { ch, OP_NULL };
288}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
void mutt_query_exit(void)
Ask the user if they want to leave NeoMutt.
Definition curs_lib.c:138
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition exit.c:41
int mutt_monitor_getch(void)
Get a character and poll the filesystem monitor.
Definition get.c:177
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition get.c:115
#define GETCH_IGNORE_MACRO
Don't use MacroEvents.
Definition get.h:33
bool OptGui
(pseudo) when the gui (and curses) are started
Definition globals.c:59
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition init.c:38
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
@ NT_TIMEOUT
Timeout has occurred.
Definition notify_type.h:56
@ NT_RESIZE
Window has been resized.
Definition notify_type.h:52
#define OP_TIMEOUT
1 second with no events
Definition opcodes.h:35
#define OP_REPAINT
Repaint is needed.
Definition opcodes.h:34
#define OP_ABORT
$abort_key pressed (Ctrl-G)
Definition opcodes.h:36
volatile sig_atomic_t SigWinch
true after SIGWINCH is received
Definition signal.c:69
volatile sig_atomic_t SigInt
true after SIGINT is received
Definition signal.c:68
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
Definition signal.c:315
Container for Accounts, Notifications.
Definition neomutt.h:43
struct Notify * notify_timeout
Timeout notifications handler.
Definition neomutt.h:46
struct Notify * notify_resize
Window resize notifications handler.
Definition neomutt.h:45
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_push_macro_event()

void mutt_push_macro_event ( int ch,
int op )

Add the character/operation to the macro buffer.

Parameters
chCharacter to add
opOperation to add

Adds the ch/op to the macro buffer. This should be used for macros, push, and exec commands only.

Definition at line 155 of file get.c.

156{
157 array_add(&MacroEvents, ch, op);
158}
void array_add(struct KeyEventArray *a, int ch, int op)
Add an event to the end of the array.
Definition get.c:88
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_unget_ch()

void mutt_unget_ch ( int ch)

Return a keystroke to the input buffer.

Parameters
chKey press

This puts events into the UngetKeyEvents buffer

Definition at line 115 of file get.c.

116{
117 array_add(&UngetKeyEvents, ch, OP_NULL);
118}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_unget_op()

void mutt_unget_op ( int op)

Return an operation to the input buffer.

Parameters
opOperation, e.g. OP_DELETE

This puts events into the UngetKeyEvents buffer

Definition at line 126 of file get.c.

127{
128 array_add(&UngetKeyEvents, 0, op);
129}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_unget_string()

void mutt_unget_string ( const char * s)

Return a string to the input buffer.

Parameters
sString to return

This puts events into the UngetKeyEvents buffer

Definition at line 137 of file get.c.

138{
139 const char *p = s + mutt_str_len(s) - 1;
140
141 while (p >= s)
142 {
143 mutt_unget_ch((unsigned char) *p--);
144 }
145}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MacroEvents

struct KeyEventArray MacroEvents
extern

These are used for macros and exec/push commands.

They can be temporarily ignored by passing GETCH_IGNORE_MACRO

Definition at line 49 of file get.c.

◆ UngetKeyEvents

struct KeyEventArray UngetKeyEvents
extern

These are used in all other "normal" situations, and are not ignored when passing GETCH_IGNORE_MACRO.

Definition at line 53 of file get.c.