NeoMutt  2025-09-05-55-g97fc89
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
window.c File Reference

GUI ask the user to enter a string. More...

#include "config.h"
#include <stdbool.h>
#include <string.h>
#include <wchar.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "color/lib.h"
#include "complete/lib.h"
#include "history/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "functions.h"
#include "muttlib.h"
#include "state.h"
#include "wdata.h"
+ Include dependency graph for window.c:

Go to the source code of this file.

Functions

static int my_addwch (struct MuttWindow *win, wchar_t wc)
 Display one wide character on screen.
 
bool self_insert (struct EnterWindowData *wdata, int ch)
 Insert a normal character.
 
static int enter_recalc (struct MuttWindow *win)
 Recalculate the Window data - Implements MuttWindow::recalc() -.
 
static int enter_repaint (struct MuttWindow *win)
 Repaint the Window - Implements MuttWindow::repaint() -.
 
static bool enter_recursor (struct MuttWindow *win)
 Recursor the Window - Implements MuttWindow::recursor() -.
 
int mw_get_field (const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
 Ask the user for a string -.
 

Variables

static const struct Mapping EditorHelp []
 Help Bar for the Command Line Editor.
 

Detailed Description

GUI ask the user to enter a string.

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 window.c.

Function Documentation

◆ my_addwch()

static int my_addwch ( struct MuttWindow * win,
wchar_t wc )
static

Display one wide character on screen.

Parameters
winWindow
wcCharacter to display
Return values
OKSuccess
ERRFailure

Definition at line 70 of file window.c.

71{
72 int n = wcwidth(wc);
73 if (IsWPrint(wc) && (n > 0))
74 return mutt_addwch(win, wc);
75 if (!(wc & ~0x7f))
76 return mutt_window_printf(win, "^%c", ((int) wc + 0x40) & 0x7f);
77 if (!(wc & ~0xffff))
78 return mutt_window_printf(win, "\\u%04x", (int) wc);
79 return mutt_window_printf(win, "\\u%08x", (int) wc);
80}
int mutt_addwch(struct MuttWindow *win, wchar_t wc)
Addwch would be provided by an up-to-date curses library.
Definition curs_lib.c:320
#define IsWPrint(wc)
Definition mbyte.h:41
int mutt_window_printf(struct MuttWindow *win, const char *fmt,...)
Write a formatted string to a Window.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 88 of file window.c.

89{
90 if (!wdata)
91 return true;
92
93 wdata->tabs = 0;
94 wchar_t wc = 0;
95
96 /* quietly ignore all other function keys */
97 if (ch & ~0xff)
98 return false;
99
100 /* gather the bytes into a wide character */
101 {
102 char c = ch;
103 size_t k = mbrtowc(&wc, &c, 1, wdata->mbstate);
104 if (k == ICONV_BUF_TOO_SMALL)
105 {
106 return false;
107 }
108 else if ((k != 0) && (k != 1))
109 {
110 memset(wdata->mbstate, 0, sizeof(*wdata->mbstate));
111 return false;
112 }
113 }
114
115 if (wdata->first && (wdata->flags & MUTT_COMP_CLEAR))
116 {
117 wdata->first = false;
118 if (IsWPrint(wc)) /* why? */
119 {
120 wdata->state->curpos = 0;
121 wdata->state->lastchar = 0;
122 }
123 }
124
125 if ((wc == '\r') || (wc == '\n'))
126 {
127 /* Convert from wide characters */
128 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->lastchar);
129 if (!wdata->pass)
130 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
131
132 if (wdata->cdata)
133 {
134 struct FileCompletionData *cdata = wdata->cdata;
135 if (cdata->multiple)
136 {
137 char **tfiles = NULL;
138 *cdata->numfiles = 1;
139 tfiles = MUTT_MEM_CALLOC(*cdata->numfiles, char *);
140 buf_expand_path_regex(wdata->buffer, false);
141 tfiles[0] = buf_strdup(wdata->buffer);
142 *cdata->files = tfiles;
143 }
144 }
145 return true;
146 }
147 else if (wc && ((wc < ' ') || IsWPrint(wc))) /* why? */
148 {
149 if (wdata->state->lastchar >= wdata->state->wbuflen)
150 {
151 wdata->state->wbuflen = wdata->state->lastchar + 20;
152 MUTT_MEM_REALLOC(&wdata->state->wbuf, wdata->state->wbuflen, wchar_t);
153 }
154 memmove(wdata->state->wbuf + wdata->state->curpos + 1,
155 wdata->state->wbuf + wdata->state->curpos,
156 (wdata->state->lastchar - wdata->state->curpos) * sizeof(wchar_t));
157 wdata->state->wbuf[wdata->state->curpos++] = wc;
158 wdata->state->lastchar++;
159 }
160 else
161 {
163 mutt_beep(false);
164 }
165
166 return false;
167}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
void mutt_beep(bool force)
Irritate the user.
Definition curs_lib.c:69
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition get.c:58
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
Definition history.c:482
void buf_mb_wcstombs(struct Buffer *dest, const wchar_t *wstr, size_t wlen)
Convert a string from wide to multibyte characters.
Definition mbyte.c:256
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:47
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:50
#define ICONV_BUF_TOO_SMALL
Error value for iconv() - Buffer too small.
Definition charset.h:98
#define MUTT_COMP_CLEAR
Clear input if printable character is pressed.
Definition mutt.h:57
void buf_expand_path_regex(struct Buffer *buf, bool regex)
Create the canonical path (with regex char escaping)
Definition muttlib.c:121
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:58
int tabs
Number of times the user has hit tab.
Definition wdata.h:63
void * cdata
Auto-Completion private data.
Definition wdata.h:53
CompletionFlags flags
Flags, see CompletionFlags.
Definition wdata.h:49
struct Buffer * buffer
struct Buffer for the result
Definition wdata.h:48
bool first
First time through, no input yet.
Definition wdata.h:59
struct EnterState * state
Current state of text entry.
Definition wdata.h:50
mbstate_t * mbstate
Multi-byte state.
Definition wdata.h:62
enum HistoryClass hclass
History to use, e.g. HC_NEO_COMMAND.
Definition wdata.h:51
Input for the file completion function.
Definition curs_lib.h:39
char *** files
List of files selected.
Definition curs_lib.h:42
bool multiple
Allow multiple selections.
Definition curs_lib.h:40
int * numfiles
Number of files selected.
Definition curs_lib.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ EditorHelp

const struct Mapping EditorHelp[]
static
Initial value:
= {
{ N_("Help"), OP_HELP },
{ N_("Complete"), OP_EDITOR_COMPLETE },
{ N_("Hist Up"), OP_EDITOR_HISTORY_UP },
{ N_("Hist Down"), OP_EDITOR_HISTORY_DOWN },
{ N_("Hist Search"), OP_EDITOR_HISTORY_SEARCH },
{ N_("Begin Line"), OP_EDITOR_BOL },
{ N_("End Line"), OP_EDITOR_EOL },
{ N_("Kill Line"), OP_EDITOR_KILL_LINE },
{ N_("Kill Word"), OP_EDITOR_KILL_WORD },
{ NULL, 0 },
}
#define N_(a)
Definition message.h:32

Help Bar for the Command Line Editor.

Definition at line 48 of file window.c.

48 {
49 // clang-format off
50 { N_("Help"), OP_HELP },
51 { N_("Complete"), OP_EDITOR_COMPLETE },
52 { N_("Hist Up"), OP_EDITOR_HISTORY_UP },
53 { N_("Hist Down"), OP_EDITOR_HISTORY_DOWN },
54 { N_("Hist Search"), OP_EDITOR_HISTORY_SEARCH },
55 { N_("Begin Line"), OP_EDITOR_BOL },
56 { N_("End Line"), OP_EDITOR_EOL },
57 { N_("Kill Line"), OP_EDITOR_KILL_LINE },
58 { N_("Kill Word"), OP_EDITOR_KILL_WORD },
59 { NULL, 0 },
60 // clang-format on
61};