This commit is contained in:
Arun Prakash Jana 2020-01-19 21:24:33 +05:30
parent 7677cd4417
commit 0f1e648032
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 85 additions and 84 deletions

169
src/nnn.c
View File

@ -2327,94 +2327,95 @@ static char *xreadline(const char *prefill, const char *prompt)
move(xlines - 1, x + wcswidth(buf, pos)); move(xlines - 1, x + wcswidth(buf, pos));
r = get_wch(ch); r = get_wch(ch);
if (r != ERR) { if (r == ERR)
if (r == OK) { continue;
switch (*ch) {
case KEY_ENTER: // fallthrough
case '\n': // fallthrough
case '\r':
goto END;
case 127: // fallthrough
case '\b': /* rhel25 sends '\b' for backspace */
if (pos > 0) {
memmove(buf + pos - 1, buf + pos,
(len - pos) * WCHAR_T_WIDTH);
--len, --pos;
} // fallthrough
case '\t': /* TAB breaks cursor position, ignore it */
continue;
case CONTROL('L'):
printprompt(prompt);
len = pos = 0;
continue;
case CONTROL('A'):
pos = 0;
continue;
case CONTROL('E'):
pos = len;
continue;
case CONTROL('U'):
printprompt(prompt);
memmove(buf, buf + pos, (len - pos) * WCHAR_T_WIDTH);
len -= pos;
pos = 0;
continue;
case 27: /* Exit prompt on Escape */
len = 0;
goto END;
}
/* Filter out all other control chars */ if (r == OK) {
if (*ch < ASCII_MAX && keyname(*ch)[0] == '^') switch (*ch) {
continue; case KEY_ENTER: // fallthrough
case '\n': // fallthrough
if (pos < READLINE_MAX - 1) { case '\r':
memmove(buf + pos + 1, buf + pos, goto END;
case 127: // fallthrough
case '\b': /* rhel25 sends '\b' for backspace */
if (pos > 0) {
memmove(buf + pos - 1, buf + pos,
(len - pos) * WCHAR_T_WIDTH); (len - pos) * WCHAR_T_WIDTH);
buf[pos] = *ch; --len, --pos;
++len, ++pos; } // fallthrough
continue; case '\t': /* TAB breaks cursor position, ignore it */
} continue;
} else { case CONTROL('L'):
switch (*ch) { printprompt(prompt);
#ifdef KEY_RESIZE len = pos = 0;
case KEY_RESIZE: continue;
clearoldprompt(); case CONTROL('A'):
xlines = LINES; pos = 0;
printprompt(prompt); continue;
break; case CONTROL('E'):
pos = len;
continue;
case CONTROL('U'):
printprompt(prompt);
memmove(buf, buf + pos, (len - pos) * WCHAR_T_WIDTH);
len -= pos;
pos = 0;
continue;
case 27: /* Exit prompt on Escape */
len = 0;
goto END;
}
/* Filter out all other control chars */
if (*ch < ASCII_MAX && keyname(*ch)[0] == '^')
continue;
if (pos < READLINE_MAX - 1) {
memmove(buf + pos + 1, buf + pos,
(len - pos) * WCHAR_T_WIDTH);
buf[pos] = *ch;
++len, ++pos;
continue;
}
} else {
switch (*ch) {
#ifdef KE
case KEY_RESIZE:
clearoldprompt();
xlines = LINES;
printprompt(prompt);
break;
#endif #endif
case KEY_LEFT: case KEY_LEFT:
if (pos > 0) if (pos > 0)
--pos; --pos;
break; break;
case KEY_RIGHT: case KEY_RIGHT:
if (pos < len) if (pos < len)
++pos; ++pos;
break; break;
case KEY_BACKSPACE: case KEY_BACKSPACE:
if (pos > 0) { if (pos > 0) {
memmove(buf + pos - 1, buf + pos, memmove(buf + pos - 1, buf + pos,
(len - pos) * WCHAR_T_WIDTH); (len - pos) * WCHAR_T_WIDTH);
--len, --pos; --len, --pos;
}
break;
case KEY_DC:
if (pos < len) {
memmove(buf + pos, buf + pos + 1,
(len - pos - 1) * WCHAR_T_WIDTH);
--len;
}
break;
case KEY_END:
pos = len;
break;
case KEY_HOME:
pos = 0;
break;
default:
break;
} }
break;
case KEY_DC:
if (pos < len) {
memmove(buf + pos, buf + pos + 1,
(len - pos - 1) * WCHAR_T_WIDTH);
--len;
}
break;
case KEY_END:
pos = len;
break;
case KEY_HOME:
pos = 0;
break;
default:
break;
} }
} }
} }