NeoMutt  2024-04-25-1-g3de005
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 <stddef.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 71 of file window.c.

72{
73 int n = wcwidth(wc);
74 if (IsWPrint(wc) && (n > 0))
75 return mutt_addwch(win, wc);
76 if (!(wc & ~0x7f))
77 return mutt_window_printf(win, "^%c", ((int) wc + 0x40) & 0x7f);
78 if (!(wc & ~0xffff))
79 return mutt_window_printf(win, "\\u%04x", (int) wc);
80 return mutt_window_printf(win, "\\u%08x", (int) wc);
81}
int mutt_addwch(struct MuttWindow *win, wchar_t wc)
Addwch would be provided by an up-to-date curses library.
Definition: curs_lib.c:318
#define IsWPrint(wc)
Definition: mbyte.h:41
int mutt_window_printf(struct MuttWindow *win, const char *fmt,...)
Write a formatted string to a Window.
Definition: mutt_window.c:431
+ 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 89 of file window.c.

90{
91 if (!wdata)
92 return true;
93
94 wdata->tabs = 0;
95 wchar_t wc = 0;
96
97 /* quietly ignore all other function keys */
98 if (ch & ~0xff)
99 return false;
100
101 /* gather the bytes into a wide character */
102 {
103 char c = ch;
104 size_t k = mbrtowc(&wc, &c, 1, wdata->mbstate);
105 if (k == ICONV_BUF_TOO_SMALL)
106 {
107 return false;
108 }
109 else if ((k != 0) && (k != 1))
110 {
111 memset(wdata->mbstate, 0, sizeof(*wdata->mbstate));
112 return false;
113 }
114 }
115
116 if (wdata->first && (wdata->flags & MUTT_COMP_CLEAR))
117 {
118 wdata->first = false;
119 if (IsWPrint(wc)) /* why? */
120 {
121 wdata->state->curpos = 0;
122 wdata->state->lastchar = 0;
123 }
124 }
125
126 if ((wc == '\r') || (wc == '\n'))
127 {
128 /* Convert from wide characters */
129 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->lastchar);
130 if (!wdata->pass)
131 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
132
133 if (wdata->cdata)
134 {
135 struct FileCompletionData *cdata = wdata->cdata;
136 if (cdata->multiple)
137 {
138 char **tfiles = NULL;
139 *cdata->numfiles = 1;
140 tfiles = mutt_mem_calloc(*cdata->numfiles, sizeof(char *));
141 buf_expand_path_regex(wdata->buffer, false);
142 tfiles[0] = buf_strdup(wdata->buffer);
143 *cdata->files = tfiles;
144 }
145 }
146 return true;
147 }
148 else if (wc && ((wc < ' ') || IsWPrint(wc))) /* why? */
149 {
150 if (wdata->state->lastchar >= wdata->state->wbuflen)
151 {
152 wdata->state->wbuflen = wdata->state->lastchar + 20;
153 mutt_mem_realloc(&wdata->state->wbuf, wdata->state->wbuflen * sizeof(wchar_t));
154 }
155 memmove(wdata->state->wbuf + wdata->state->curpos + 1,
156 wdata->state->wbuf + wdata->state->curpos,
157 (wdata->state->lastchar - wdata->state->curpos) * sizeof(wchar_t));
158 wdata->state->wbuf[wdata->state->curpos++] = wc;
159 wdata->state->lastchar++;
160 }
161 else
162 {
164 mutt_beep(false);
165 }
166
167 return false;
168}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:570
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:68
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: get.c:57
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
Definition: history.c:490
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
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:106
#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:135
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:40
char *** files
List of files selected.
Definition: curs_lib.h:43
bool multiple
Allow multiple selections.
Definition: curs_lib.h:41
int * numfiles
Number of files selected.
Definition: curs_lib.h:44
+ 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 49 of file window.c.