diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2017-08-25 13:57:22 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2017-08-25 13:57:22 +0530 |
commit | efc70f33e58bae95fa2b22231b8694c76c57b7c4 (patch) | |
tree | 2dc45d5249c84425c5374180e1396b1a7cba9040 | |
parent | 76d582d5cd44edfe8db0dc431a9c4729875d0148 (diff) | |
download | nnn-efc70f33e58bae95fa2b22231b8694c76c57b7c4.tar.gz |
Get rid of getch() ('Führer' works now)
-rw-r--r-- | nnn.c | 74 |
1 files changed, 39 insertions, 35 deletions
@@ -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; } } |