Get rid of getch() ('Führer' works now)

This commit is contained in:
Arun Prakash Jana 2017-08-25 13:57:22 +05:30
parent 76d582d5cd
commit efc70f33e5
No known key found for this signature in database
GPG key ID: A75979F35C080412

74
nnn.c
View file

@ -930,7 +930,7 @@ filterentries(char *path)
curs_set(TRUE); curs_set(TRUE);
printprompt(ln); printprompt(ln);
while ((r = wget_wch(stdscr, ch)) != ERR) while ((r = get_wch(ch)) != ERR)
if (r == OK) if (r == OK)
switch (*ch) { switch (*ch) {
case '\r': // with nonl(), this is ENTER key value case '\r': // with nonl(), this is ENTER key value
@ -974,7 +974,7 @@ filterentries(char *path)
if (len == 1) if (len == 1)
cur = 0; cur = 0;
if (len == maxlen || !isprint(*ch)) if (len == maxlen)
break; break;
wln[len] = (wchar_t)*ch; wln[len] = (wchar_t)*ch;
@ -1027,7 +1027,8 @@ xreadline(char *fname)
{ {
int old_curs = curs_set(1); int old_curs = curs_set(1);
size_t len, pos; size_t len, pos;
int c, x, y; int x, y, r;
wint_t ch[2] = {0};
wchar_t *buf = (wchar_t *)g_buf; wchar_t *buf = (wchar_t *)g_buf;
size_t buflen = NAME_MAX - 1; size_t buflen = NAME_MAX - 1;
@ -1048,41 +1049,44 @@ xreadline(char *fname)
mvaddnwstr(y, x, buf, len + 1); mvaddnwstr(y, x, buf, len + 1);
move(y, x + pos); move(y, x + pos);
c = getch(); if ((r = get_wch(ch)) != ERR) {
if (r == OK) {
if (*ch == KEY_ENTER || *ch == '\n' || *ch == '\r')
break;
if (c == KEY_ENTER || c == '\n' || c == '\r') if (pos < buflen) {
break; memmove(buf + pos + 1, buf + pos, (len - pos) << 2);
buf[pos] = *ch;
++len, ++pos;
continue;
}
if (isprint(c) && pos < buflen) { } else {
memmove(buf + pos + 1, buf + pos, (len - pos) << 2); switch (*ch) {
buf[pos] = c; case KEY_LEFT:
++len, ++pos; if (pos > 0)
continue; --pos;
} break;
case KEY_RIGHT:
switch (c) { if (pos < len)
case KEY_LEFT: ++pos;
if (pos > 0) break;
--pos; case KEY_BACKSPACE:
break; if (pos > 0) {
case KEY_RIGHT: memmove(buf + pos - 1, buf + pos, (len - pos) << 2);
if (pos < len) --len, --pos;
++pos; }
break; break;
case KEY_BACKSPACE: case KEY_DC:
if (pos > 0) { if (pos < len) {
memmove(buf + pos - 1, buf + pos, (len - pos) << 2); memmove(buf + pos, buf + pos + 1, (len - pos - 1) << 2);
--len, --pos; --len;
}
break;
default:
break;
}
} }
break;
case KEY_DC:
if (pos < len) {
memmove(buf + pos, buf + pos + 1, (len - pos - 1) << 2);
--len;
}
break;
default:
break;
} }
} }