NeoMutt  2023-05-17-16-g61469c
Teaching an old dog new tricks
DOXYGEN
functions.h File Reference

Enter functions. More...

#include <stdbool.h>
+ Include dependency graph for functions.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  EnterFunction
 A NeoMutt function. More...
 

Typedefs

typedef int(* enter_function_t) (struct EnterWindowData *wdata, int op)
 

Functions

int enter_function_dispatcher (struct MuttWindow *win, int op)
 Perform an Enter function - Implements function_dispatcher_t -. More...
 
bool self_insert (struct EnterWindowData *wdata, int ch)
 Insert a normal character. More...
 

Detailed Description

Enter functions.

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 functions.h.

Typedef Documentation

◆ enter_function_t

typedef int(* enter_function_t) (struct EnterWindowData *wdata, int op)

Definition at line 40 of file functions.h.

Function Documentation

◆ self_insert()

bool self_insert ( struct EnterWindowData wdata,
int  ch 
)

Insert a normal character.

Parameters
wdataEnter window data
chRaw keypress
Return values
trueIf done (enter pressed)

Definition at line 91 of file window.c.

92{
93 if (!wdata)
94 return true;
95
96 wdata->tabs = 0;
97 wchar_t wc = 0;
98
99 /* quietly ignore all other function keys */
100 if (ch & ~0xff)
101 return false;
102
103 /* gather the bytes into a wide character */
104 {
105 char c = ch;
106 size_t k = mbrtowc(&wc, &c, 1, wdata->mbstate);
107 if (k == ICONV_BUF_TOO_SMALL)
108 {
109 return false;
110 }
111 else if ((k != 0) && (k != 1))
112 {
113 memset(wdata->mbstate, 0, sizeof(*wdata->mbstate));
114 return false;
115 }
116 }
117
118 if (wdata->first && (wdata->flags & MUTT_COMP_CLEAR))
119 {
120 wdata->first = false;
121 if (IsWPrint(wc)) /* why? */
122 {
123 wdata->state->curpos = 0;
124 wdata->state->lastchar = 0;
125 }
126 }
127
128 if ((wc == '\r') || (wc == '\n'))
129 {
130 /* Convert from wide characters */
131 mutt_mb_wcstombs(wdata->buf, wdata->buflen, wdata->state->wbuf, wdata->state->lastchar);
132 if (!wdata->pass)
133 mutt_hist_add(wdata->hclass, wdata->buf, true);
134
135 if (wdata->multiple)
136 {
137 char **tfiles = NULL;
138 *wdata->numfiles = 1;
139 tfiles = mutt_mem_calloc(*wdata->numfiles, sizeof(char *));
140 mutt_expand_path(wdata->buf, wdata->buflen);
141 tfiles[0] = mutt_str_dup(wdata->buf);
142 *wdata->files = tfiles;
143 }
144 return true;
145 }
146 else if (wc && ((wc < ' ') || IsWPrint(wc))) /* why? */
147 {
148 if (wdata->state->lastchar >= wdata->state->wbuflen)
149 {
150 wdata->state->wbuflen = wdata->state->lastchar + 20;
151 mutt_mem_realloc(&wdata->state->wbuf, wdata->state->wbuflen * sizeof(wchar_t));
152 }
153 memmove(wdata->state->wbuf + wdata->state->curpos + 1,
154 wdata->state->wbuf + wdata->state->curpos,
155 (wdata->state->lastchar - wdata->state->curpos) * sizeof(wchar_t));
156 wdata->state->wbuf[wdata->state->curpos++] = wc;
157 wdata->state->lastchar++;
158 }
159 else
160 {
162 mutt_beep(false);
163 }
164
165 return false;
166}
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:593
void mutt_beep(bool force)
Irritate the user.
Definition: curs_lib.c:131
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
Definition: history.c:485
void mutt_mb_wcstombs(char *dest, size_t dlen, const wchar_t *src, size_t slen)
Convert a string from wide to multibyte characters.
Definition: mbyte.c:237
#define IsWPrint(wc)
Definition: mbyte.h:39
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define ICONV_BUF_TOO_SMALL
Error value for iconv() - Buffer too small.
Definition: charset.h:105
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
#define MUTT_COMP_CLEAR
Clear input if printable character is pressed.
Definition: mutt.h:65
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:124
size_t curpos
Position of the cursor.
Definition: state.h:36
size_t wbuflen
Length of buffer.
Definition: state.h:34
wchar_t * wbuf
Buffer for the string being entered.
Definition: state.h:33
size_t lastchar
Position of the last character.
Definition: state.h:35
bool pass
Password mode, conceal characters.
Definition: wdata.h:60
int tabs
Number of times the user has hit tab.
Definition: wdata.h:66
int * numfiles
Number of files selected.
Definition: wdata.h:55
CompletionFlags flags
Flags, see CompletionFlags.
Definition: wdata.h:51
size_t buflen
Length of result buffer.
Definition: wdata.h:49
bool first
First time through, no input yet.
Definition: wdata.h:61
bool multiple
Allow multiple matches.
Definition: wdata.h:52
char *** files
List of files selected.
Definition: wdata.h:54
char * buf
Buffer for the result.
Definition: wdata.h:48
struct EnterState * state
Current state of text entry.
Definition: wdata.h:56
mbstate_t * mbstate
Multi-byte state.
Definition: wdata.h:65
enum HistoryClass hclass
History to use, e.g. HC_COMMAND.
Definition: wdata.h:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function: