aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-08-25 13:57:22 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-08-25 13:57:22 +0530
commitefc70f33e58bae95fa2b22231b8694c76c57b7c4 (patch)
tree2dc45d5249c84425c5374180e1396b1a7cba9040
parent76d582d5cd44edfe8db0dc431a9c4729875d0148 (diff)
downloadnnn-efc70f33e58bae95fa2b22231b8694c76c57b7c4.tar.gz
Get rid of getch() ('Führer' works now)
-rw-r--r--nnn.c74
1 files changed, 39 insertions, 35 deletions
diff --git a/nnn.c b/nnn.c
index 0ccf878..4fce5bc 100644
--- a/nnn.c
+++ b/nnn.c
@@ -930,7 +930,7 @@ filterentries(char *path)
curs_set(TRUE);
printprompt(ln);
- while ((r = wget_wch(stdscr, ch)) != ERR)
+ while ((r = get_wch(ch)) != ERR)
if (r == OK)
switch (*ch) {
case '\r': // with nonl(), this is ENTER key value
@@ -974,7 +974,7 @@ filterentries(char *path)
if (len == 1)
cur = 0;
- if (len == maxlen || !isprint(*ch))
+ if (len == maxlen)
break;
wln[len] = (wchar_t)*ch;
@@ -1027,7 +1027,8 @@ xreadline(char *fname)
{
int old_curs = curs_set(1);
size_t len, pos;
- int c, x, y;
+ int x, y, r;
+ wint_t ch[2] = {0};
wchar_t *buf = (wchar_t *)g_buf;
size_t buflen = NAME_MAX - 1;
@@ -1048,41 +1049,44 @@ xreadline(char *fname)
mvaddnwstr(y, x, buf, len + 1);
move(y, x + pos);
- c = getch();
-
- if (c == KEY_ENTER || c == '\n' || c == '\r')
- break;
+ if ((r = get_wch(ch)) != ERR) {
+ if (r == OK) {
+ if (*ch == KEY_ENTER || *ch == '\n' || *ch == '\r')
+ break;
- if (isprint(c) && pos < buflen) {
- memmove(buf + pos + 1, buf + pos, (len - pos) << 2);
- buf[pos] = c;
- ++len, ++pos;
- continue;
- }
+ if (pos < buflen) {
+ memmove(buf + pos + 1, buf + pos, (len - pos) << 2);
+ buf[pos] = *ch;
+ ++len, ++pos;
+ continue;
+ }
- switch (c) {
- case KEY_LEFT:
- if (pos > 0)
- --pos;
- break;
- case KEY_RIGHT:
- if (pos < len)
- ++pos;
- break;
- case KEY_BACKSPACE:
- if (pos > 0) {
- memmove(buf + pos - 1, buf + pos, (len - pos) << 2);
- --len, --pos;
- }
- break;
- case KEY_DC:
- if (pos < len) {
- memmove(buf + pos, buf + pos + 1, (len - pos - 1) << 2);
- --len;
+ } else {
+ switch (*ch) {
+ case KEY_LEFT:
+ if (pos > 0)
+ --pos;
+ break;
+ case KEY_RIGHT:
+ if (pos < len)
+ ++pos;
+ break;
+ case KEY_BACKSPACE:
+ if (pos > 0) {
+ memmove(buf + pos - 1, buf + pos, (len - pos) << 2);
+ --len, --pos;
+ }
+ break;
+ case KEY_DC:
+ if (pos < len) {
+ memmove(buf + pos, buf + pos + 1, (len - pos - 1) << 2);
+ --len;
+ }
+ break;
+ default:
+ break;
+ }
}
- break;
- default:
- break;
}
}