mirror of
https://github.com/jarun/nnn.git
synced 2025-03-12 17:54:04 +00:00
Merge pull request #1971 from doremiyeon/xreadline_by_word_movement
xreadline by word movement
This commit is contained in:
commit
da73d9ada9
1 changed files with 45 additions and 9 deletions
54
src/nnn.c
54
src/nnn.c
|
@ -100,6 +100,7 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include <wctype.h>
|
||||
#include <stdalign.h>
|
||||
#ifndef __USE_XOPEN_EXTENDED
|
||||
#define __USE_XOPEN_EXTENDED 1
|
||||
|
@ -179,6 +180,7 @@
|
|||
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
#define ISODD(x) ((x) & 1)
|
||||
#define ISBLANK(x) ((x) == ' ' || (x) == '\t')
|
||||
#define ISSPACE(x) (ISBLANK(x) || (x) == '\n' || (x) == '\r' || (x) == '\f' || (x) == '\v')
|
||||
#define TOUPPER(ch) (((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
|
||||
#define TOLOWER(ch) (((ch) >= 'A' && (ch) <= 'Z') ? ((ch) - 'A' + 'a') : (ch))
|
||||
#define ISUPPER_(ch) ((ch) >= 'A' && (ch) <= 'Z')
|
||||
|
@ -3625,7 +3627,7 @@ static void addcmdtohist(char *cmd)
|
|||
/* Show a prompt with input string and return the changes */
|
||||
static char *xreadline(const char *prefill, const char *prompt)
|
||||
{
|
||||
size_t len, pos;
|
||||
size_t len, pos, lpos;
|
||||
int x, r;
|
||||
const int WCHAR_T_WIDTH = sizeof(wchar_t);
|
||||
wint_t ch[1];
|
||||
|
@ -3704,13 +3706,13 @@ static char *xreadline(const char *prefill, const char *prompt)
|
|||
continue;
|
||||
case CONTROL('W'):
|
||||
printmsg(prompt);
|
||||
do {
|
||||
if (pos == 0)
|
||||
break;
|
||||
memmove(buf + pos - 1, buf + pos,
|
||||
(len - pos) * WCHAR_T_WIDTH);
|
||||
--pos, --len;
|
||||
} while (buf[pos - 1] != ' ' && buf[pos - 1] != '/'); // NOLINT
|
||||
lpos = pos;
|
||||
while (pos > 0 && ISSPACE(buf[pos-1]))
|
||||
--pos;
|
||||
while (pos > 0 && !ISSPACE(buf[pos-1]))
|
||||
--pos;
|
||||
memmove(buf + pos, buf + lpos, (len - lpos) * WCHAR_T_WIDTH);
|
||||
len -= lpos - pos;
|
||||
continue;
|
||||
case CONTROL('K'):
|
||||
printmsg(prompt);
|
||||
|
@ -3733,8 +3735,42 @@ static char *xreadline(const char *prefill, const char *prompt)
|
|||
pos = 0;
|
||||
continue;
|
||||
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;
|
||||
}
|
||||
|
||||
len = 0;
|
||||
goto END;
|
||||
|
|
Loading…
Add table
Reference in a new issue