mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Simplify readln()
Use getnstr() and be done with it. It will even beep now!
This commit is contained in:
parent
d6e89ef07f
commit
f77b6a3fa6
46
noice.c
46
noice.c
|
@ -327,52 +327,14 @@ nextsel(char **run)
|
|||
char *
|
||||
readln(void)
|
||||
{
|
||||
int c;
|
||||
int i = 0;
|
||||
char *ln = NULL;
|
||||
int y, x, x0;
|
||||
char ln[LINE_MAX];
|
||||
|
||||
echo();
|
||||
curs_set(TRUE);
|
||||
|
||||
/* Starting point */
|
||||
getyx(stdscr, y, x);
|
||||
x0 = x;
|
||||
|
||||
while ((c = getch()) != ERR) {
|
||||
if (c == KEY_ENTER || c == '\r')
|
||||
break;
|
||||
if (c == KEY_BACKSPACE || c == CONTROL('H')) {
|
||||
getyx(stdscr, y, x);
|
||||
if (x >= x0) {
|
||||
i--;
|
||||
if (i > 0) {
|
||||
ln = xrealloc(ln, i * sizeof(*ln));
|
||||
} else {
|
||||
free(ln);
|
||||
ln = NULL;
|
||||
}
|
||||
move(y, x);
|
||||
printw("%c", ' ');
|
||||
move(y, x);
|
||||
} else {
|
||||
move(y, x0);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ln = xrealloc(ln, (i + 1) * sizeof(*ln));
|
||||
ln[i] = c;
|
||||
i++;
|
||||
}
|
||||
if (ln != NULL) {
|
||||
ln = xrealloc(ln, (i + 1) * sizeof(*ln));
|
||||
ln[i] = '\0';
|
||||
}
|
||||
|
||||
curs_set(FALSE);
|
||||
getnstr(ln, sizeof(ln));
|
||||
noecho();
|
||||
|
||||
return ln;
|
||||
curs_set(FALSE);
|
||||
return strdup(ln);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue