Tidy up xreadline()

This commit is contained in:
Arun Prakash Jana 2018-04-25 22:37:59 +05:30
parent 18deea6383
commit 4fbb36b66b
No known key found for this signature in database
GPG key ID: A75979F35C080412

22
nnn.c
View file

@ -1213,7 +1213,7 @@ end:
/* Show a prompt with input string and return the changes */ /* Show a prompt with input string and return the changes */
static char * static char *
xreadline(char *fname) xreadline(char *fname, char *prompt)
{ {
int old_curs = curs_set(1); int old_curs = curs_set(1);
size_t len, pos; size_t len, pos;
@ -1221,6 +1221,8 @@ xreadline(char *fname)
wint_t ch[2] = {0}; wint_t ch[2] = {0};
static wchar_t * const buf = (wchar_t *)g_buf; static wchar_t * const buf = (wchar_t *)g_buf;
printprompt(prompt);
if (fname) { if (fname) {
DPRINTF_S(fname); DPRINTF_S(fname);
len = pos = mbstowcs(buf, fname, NAME_MAX); len = pos = mbstowcs(buf, fname, NAME_MAX);
@ -1247,6 +1249,7 @@ xreadline(char *fname)
if (*ch == CONTROL('L')) { if (*ch == CONTROL('L')) {
clearprompt(); clearprompt();
printprompt(prompt);
len = pos = 0; len = pos = 0;
continue; continue;
} }
@ -1263,6 +1266,7 @@ xreadline(char *fname)
if (*ch == CONTROL('U')) { if (*ch == CONTROL('U')) {
clearprompt(); clearprompt();
printprompt(prompt);
memmove(buf, buf + pos, (len - pos) << 2); memmove(buf, buf + pos, (len - pos) << 2);
len -= pos; len -= pos;
pos = 0; pos = 0;
@ -1319,6 +1323,7 @@ xreadline(char *fname)
settimeout(); settimeout();
DPRINTF_S(buf); DPRINTF_S(buf);
wcstombs(g_buf, buf, NAME_MAX); wcstombs(g_buf, buf, NAME_MAX);
clearprompt();
return g_buf; return g_buf;
} }
@ -3091,15 +3096,14 @@ nochange:
else else
printmsg("quotes off"); printmsg("quotes off");
goto nochange; goto nochange;
case SEL_OPEN: case SEL_OPEN: // fallthrough
printprompt("open with: "); // fallthrough
case SEL_ARCHIVE: // fallthrough case SEL_ARCHIVE: // fallthrough
case SEL_NEW: case SEL_NEW:
if (sel != SEL_OPEN) if (sel == SEL_OPEN)
printprompt("name: "); tmp = xreadline(NULL, "open with: ");
else
tmp = xreadline(NULL, "name: ");
tmp = xreadline(NULL);
clearprompt();
if (tmp == NULL || tmp[0] == '\0') if (tmp == NULL || tmp[0] == '\0')
break; break;
@ -3183,9 +3187,7 @@ nochange:
if (ndents <= 0) if (ndents <= 0)
break; break;
printprompt(""); tmp = xreadline(dents[cur].name, "");
tmp = xreadline(dents[cur].name);
clearprompt();
if (tmp == NULL || tmp[0] == '\0') if (tmp == NULL || tmp[0] == '\0')
break; break;