mirror of
https://github.com/jarun/nnn.git
synced 2025-01-15 21:36:42 +00:00
extend xreadline() with some by-word movement
added M-b, M-f, M-d, M-bspc according to GNU readline specifications.
This commit is contained in:
parent
5e5a17f954
commit
d6b1b80e40
39
src/nnn.c
39
src/nnn.c
|
@ -100,6 +100,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <wctype.h>
|
||||||
#include <stdalign.h>
|
#include <stdalign.h>
|
||||||
#ifndef __USE_XOPEN_EXTENDED
|
#ifndef __USE_XOPEN_EXTENDED
|
||||||
#define __USE_XOPEN_EXTENDED 1
|
#define __USE_XOPEN_EXTENDED 1
|
||||||
|
@ -3637,7 +3638,7 @@ static void addcmdtohist(char *cmd)
|
||||||
/* Show a prompt with input string and return the changes */
|
/* Show a prompt with input string and return the changes */
|
||||||
static char *xreadline(const char *prefill, const char *prompt)
|
static char *xreadline(const char *prefill, const char *prompt)
|
||||||
{
|
{
|
||||||
size_t len, pos;
|
size_t len, pos, lpos;
|
||||||
int x, r;
|
int x, r;
|
||||||
const int WCHAR_T_WIDTH = sizeof(wchar_t);
|
const int WCHAR_T_WIDTH = sizeof(wchar_t);
|
||||||
wint_t ch[1];
|
wint_t ch[1];
|
||||||
|
@ -3745,8 +3746,42 @@ static char *xreadline(const char *prefill, const char *prompt)
|
||||||
pos = 0;
|
pos = 0;
|
||||||
continue;
|
continue;
|
||||||
case ESC: /* Exit prompt on Esc, but just filter out Alt+key */
|
case ESC: /* Exit prompt on Esc, but just filter out Alt+key */
|
||||||
if (handle_alt_key(ch) != ERR)
|
if (handle_alt_key(ch) != ERR) {
|
||||||
|
switch (*ch) {
|
||||||
|
case 'd':
|
||||||
|
printmsg(prompt);
|
||||||
|
lpos = pos;
|
||||||
|
while (pos < len && !iswalnum(buf[pos + 1]))
|
||||||
|
++pos;
|
||||||
|
while (pos < len && iswalnum(buf[++pos]));
|
||||||
|
memmove(buf + lpos, buf + pos, (len - pos) * WCHAR_T_WIDTH);
|
||||||
|
len -= pos - lpos;
|
||||||
|
pos = lpos;
|
||||||
|
continue;
|
||||||
|
case KEY_BACKSPACE:
|
||||||
|
printmsg(prompt);
|
||||||
|
lpos = pos;
|
||||||
|
while (pos > 0 && !iswalnum(buf[pos - 1]))
|
||||||
|
--pos;
|
||||||
|
while (pos > 0 && iswalnum(buf[pos - 1]))
|
||||||
|
--pos;
|
||||||
|
memmove(buf + pos, buf + lpos, (len - lpos) * WCHAR_T_WIDTH);
|
||||||
|
len -= lpos - pos;
|
||||||
|
continue;
|
||||||
|
case 'f':
|
||||||
|
while (pos < len && !iswalnum(buf[pos + 1]))
|
||||||
|
++pos;
|
||||||
|
while (pos < len && iswalnum(buf[++pos]));
|
||||||
|
continue;
|
||||||
|
case 'b':
|
||||||
|
while (pos > 0 && !iswalnum(buf[pos - 1]))
|
||||||
|
--pos;
|
||||||
|
while (pos > 0 && iswalnum(buf[pos - 1]))
|
||||||
|
--pos;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
goto END;
|
goto END;
|
||||||
|
|
Loading…
Reference in a new issue