Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xreadline by word movement #1971

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -3637,7 +3639,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];
Expand Down Expand Up @@ -3716,13 +3718,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);
Expand All @@ -3745,8 +3747,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);
N-R-K marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down
Loading